test: share telegram command menu fixture

This commit is contained in:
Peter Steinberger
2026-04-20 17:48:52 +01:00
parent 47d42606ac
commit e7befec3ff

View File

@@ -67,6 +67,30 @@ function registerPlugCommand(params: PlugCommandHarnessParams = {}) {
};
}
function registerCustomTelegramCommandMenu(
customCommands: NonNullable<TelegramAccountConfig["customCommands"]>,
) {
const setMyCommands = vi.fn().mockResolvedValue(undefined);
const runtimeLog = vi.fn();
registerTelegramNativeCommands({
...createNativeCommandTestParams({ commands: { native: false } }),
bot: {
api: {
setMyCommands,
sendMessage: vi.fn().mockResolvedValue(undefined),
},
command: vi.fn(),
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
runtime: { log: runtimeLog } as unknown as RuntimeEnv,
telegramCfg: { customCommands } as TelegramAccountConfig,
nativeEnabled: false,
nativeSkillsEnabled: false,
});
return { runtimeLog, setMyCommands };
}
describe("registerTelegramNativeCommands", () => {
beforeAll(async () => {
({
@@ -118,30 +142,11 @@ describe("registerTelegramNativeCommands", () => {
});
it("truncates Telegram command registration to 100 commands", async () => {
const cfg: OpenClawConfig = {
commands: { native: false },
};
const customCommands = Array.from({ length: 120 }, (_, index) => ({
command: `cmd_${index}`,
description: `Command ${index}`,
}));
const setMyCommands = vi.fn().mockResolvedValue(undefined);
const runtimeLog = vi.fn();
registerTelegramNativeCommands({
...createNativeCommandTestParams(cfg),
bot: {
api: {
setMyCommands,
sendMessage: vi.fn().mockResolvedValue(undefined),
},
command: vi.fn(),
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
runtime: { log: runtimeLog } as unknown as RuntimeEnv,
telegramCfg: { customCommands } as TelegramAccountConfig,
nativeEnabled: false,
nativeSkillsEnabled: false,
});
const { runtimeLog, setMyCommands } = registerCustomTelegramCommandMenu(customCommands);
const registeredCommands = await waitForRegisteredCommands(setMyCommands);
expect(registeredCommands).toHaveLength(100);
@@ -152,30 +157,11 @@ describe("registerTelegramNativeCommands", () => {
});
it("keeps sub-100 commands by shortening long descriptions to fit Telegram payload budget", async () => {
const cfg: OpenClawConfig = {
commands: { native: false },
};
const customCommands = Array.from({ length: 92 }, (_, index) => ({
command: `cmd_${index}`,
description: `Command ${index} ` + "x".repeat(120),
}));
const setMyCommands = vi.fn().mockResolvedValue(undefined);
const runtimeLog = vi.fn();
registerTelegramNativeCommands({
...createNativeCommandTestParams(cfg),
bot: {
api: {
setMyCommands,
sendMessage: vi.fn().mockResolvedValue(undefined),
},
command: vi.fn(),
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
runtime: { log: runtimeLog } as unknown as RuntimeEnv,
telegramCfg: { customCommands } as TelegramAccountConfig,
nativeEnabled: false,
nativeSkillsEnabled: false,
});
const { runtimeLog, setMyCommands } = registerCustomTelegramCommandMenu(customCommands);
const registeredCommands = await waitForRegisteredCommands(setMyCommands);
expect(registeredCommands).toHaveLength(92);