fix(plugin-sdk): keep telegram command config available

This commit is contained in:
Vincent Koc 2026-04-04 21:48:32 +09:00
parent b3faf20d91
commit 2a03326925
1 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,52 @@
import { beforeAll, describe, expect, it, vi } from "vitest";
vi.mock("../channels/plugins/contract-surfaces.js", () => ({
getBundledChannelContractSurfaceModule: vi.fn(() => null),
}));
let telegramCommandConfig: typeof import("./telegram-command-config.js");
beforeAll(async () => {
vi.resetModules();
telegramCommandConfig = await import("./telegram-command-config.js");
});
describe("telegram command config fallback", () => {
it("keeps command validation available when the bundled contract surface is unavailable", () => {
expect(telegramCommandConfig.TELEGRAM_COMMAND_NAME_PATTERN.test("hello_world")).toBe(true);
expect(telegramCommandConfig.normalizeTelegramCommandName("/Hello-World")).toBe(
"hello_world",
);
expect(telegramCommandConfig.normalizeTelegramCommandDescription(" hi ")).toBe("hi");
expect(
telegramCommandConfig.resolveTelegramCustomCommands({
commands: [
{ command: "/Hello-World", description: " Says hi " },
{ command: "/Hello-World", description: "duplicate" },
{ command: "", description: "missing command" },
{ command: "/ok", description: "" },
],
}),
).toEqual({
commands: [{ command: "hello_world", description: "Says hi" }],
issues: [
{
index: 1,
field: "command",
message: 'Telegram custom command "/hello_world" is duplicated.',
},
{
index: 2,
field: "command",
message: "Telegram custom command is missing a command name.",
},
{
index: 3,
field: "description",
message: 'Telegram custom command "/ok" is missing a description.',
},
],
});
});
});