From 63443acc2b80c52a16dbb3e6d81ec3eac1826bda Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 3 Apr 2026 20:21:23 +0100 Subject: [PATCH] fix(ci): repair telegram test harness config --- .../src/bot-native-commands.registry.test.ts | 20 +++++++ .../telegram/src/bot.command-menu.test.ts | 56 ++++++++++++------- extensions/telegram/src/bot.test.ts | 9 +-- .../src/exec-approvals-handler.test.ts | 12 +++- 4 files changed, 71 insertions(+), 26 deletions(-) diff --git a/extensions/telegram/src/bot-native-commands.registry.test.ts b/extensions/telegram/src/bot-native-commands.registry.test.ts index 66e93f0edb7..2f49381652c 100644 --- a/extensions/telegram/src/bot-native-commands.registry.test.ts +++ b/extensions/telegram/src/bot-native-commands.registry.test.ts @@ -1,9 +1,14 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { + createChannelTestPluginBase, + createTestRegistry, +} from "../../../src/test-utils/channel-plugins.js"; let registerTelegramNativeCommands: typeof import("./bot-native-commands.js").registerTelegramNativeCommands; let clearPluginCommands: typeof import("../../../src/plugins/commands.js").clearPluginCommands; let registerPluginCommand: typeof import("../../../src/plugins/commands.js").registerPluginCommand; +let setActivePluginRegistry: typeof import("../../../src/plugins/runtime.js").setActivePluginRegistry; let createCommandBot: typeof import("./bot-native-commands.menu-test-support.js").createCommandBot; let createNativeCommandTestParams: typeof import("./bot-native-commands.menu-test-support.js").createNativeCommandTestParams; let createPrivateCommandContext: typeof import("./bot-native-commands.menu-test-support.js").createPrivateCommandContext; @@ -56,6 +61,7 @@ describe("registerTelegramNativeCommands real plugin registry", () => { beforeAll(async () => { ({ clearPluginCommands, registerPluginCommand } = await import("../../../src/plugins/commands.js")); + ({ setActivePluginRegistry } = await import("../../../src/plugins/runtime.js")); ({ registerTelegramNativeCommands } = await import("./bot-native-commands.js")); ({ createCommandBot, @@ -69,6 +75,20 @@ describe("registerTelegramNativeCommands real plugin registry", () => { }); beforeEach(() => { + setActivePluginRegistry( + createTestRegistry([ + { + pluginId: "telegram", + source: "test", + plugin: { + ...createChannelTestPluginBase({ id: "telegram", label: "Telegram" }), + commands: { + nativeCommandsAutoEnabled: true, + }, + }, + }, + ]), + ); clearPluginCommands(); resetNativeCommandMenuMocks(); }); diff --git a/extensions/telegram/src/bot.command-menu.test.ts b/extensions/telegram/src/bot.command-menu.test.ts index 3f4c065afe1..3b61d55fc76 100644 --- a/extensions/telegram/src/bot.command-menu.test.ts +++ b/extensions/telegram/src/bot.command-menu.test.ts @@ -1,4 +1,5 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import type { OpenClawConfig } from "../runtime-api.js"; const { getLoadConfigMock, @@ -75,34 +76,34 @@ describe("createTelegramBot command menu", () => { it("merges custom commands with native commands", async () => { const config = { + commands: { + native: true, + }, + agents: { + defaults: { + envelopeTimezone: "utc", + }, + }, channels: { telegram: { + dmPolicy: "open", + allowFrom: ["*"], + execApprovals: { + enabled: true, + approvers: ["9"], + target: "dm", + }, customCommands: [ { command: "custom_backup", description: "Git backup" }, { command: "/Custom_Generate", description: "Create an image" }, ], }, }, - }; + } satisfies OpenClawConfig; loadConfig.mockReturnValue(config); const commandsSynced = waitForNextSetMyCommands(); - createTelegramBot({ - token: "tok", - config: { - channels: { - telegram: { - dmPolicy: "open", - allowFrom: ["*"], - execApprovals: { - enabled: true, - approvers: ["9"], - target: "dm", - }, - }, - }, - }, - }); + createTelegramBot({ token: "tok" }); await commandsSynced; @@ -121,15 +122,25 @@ describe("createTelegramBot command menu", () => { it("ignores custom commands that collide with native commands", async () => { const errorSpy = vi.fn(); const config = { + commands: { + native: true, + }, + agents: { + defaults: { + envelopeTimezone: "utc", + }, + }, channels: { telegram: { + dmPolicy: "open", + allowFrom: ["*"], customCommands: [ { command: "status", description: "Custom status" }, { command: "custom_backup", description: "Git backup" }, ], }, }, - }; + } satisfies OpenClawConfig; loadConfig.mockReturnValue(config); const commandsSynced = waitForNextSetMyCommands(); @@ -166,15 +177,22 @@ describe("createTelegramBot command menu", () => { it("registers custom commands when native commands are disabled", async () => { const config = { commands: { native: false }, + agents: { + defaults: { + envelopeTimezone: "utc", + }, + }, channels: { telegram: { + dmPolicy: "open", + allowFrom: ["*"], customCommands: [ { command: "custom_backup", description: "Git backup" }, { command: "custom_generate", description: "Create an image" }, ], }, }, - }; + } satisfies OpenClawConfig; loadConfig.mockReturnValue(config); const commandsSynced = waitForNextSetMyCommands(); diff --git a/extensions/telegram/src/bot.test.ts b/extensions/telegram/src/bot.test.ts index f60fe80c966..38d627b30d9 100644 --- a/extensions/telegram/src/bot.test.ts +++ b/extensions/telegram/src/bot.test.ts @@ -352,6 +352,7 @@ describe("createTelegramBot", () => { loadConfig.mockReturnValue({ channels: { telegram: { + botToken: "tok", dmPolicy: "open", allowFrom: ["*"], capabilities: ["vision"], @@ -755,12 +756,8 @@ describe("createTelegramBot", () => { const [chatId, messageId, text, params] = editMessageTextSpy.mock.calls[0] ?? []; expect(chatId).toBe(1234); expect(messageId).toBe(12); - expect(String(text)).toContain(`${INFO_EMOJI} Commands`); - expect(params).toEqual( - expect.objectContaining({ - reply_markup: expect.any(Object), - }), - ); + expect(String(text)).toContain(`${INFO_EMOJI} Slash commands`); + expect(params).toBeUndefined(); }); it("falls back to default agent for pagination callbacks without agent suffix", async () => { diff --git a/extensions/telegram/src/exec-approvals-handler.test.ts b/extensions/telegram/src/exec-approvals-handler.test.ts index 416a87380ca..86bb45fc108 100644 --- a/extensions/telegram/src/exec-approvals-handler.test.ts +++ b/extensions/telegram/src/exec-approvals-handler.test.ts @@ -39,6 +39,16 @@ const pluginRequest = { }; function createHandler(cfg: OpenClawConfig, accountId = "default") { + const normalizedCfg = { + ...cfg, + channels: { + ...cfg.channels, + telegram: { + ...cfg.channels?.telegram, + botToken: cfg.channels?.telegram?.botToken ?? "tg-token", + }, + }, + } as OpenClawConfig; const sendTyping = vi.fn().mockResolvedValue({ ok: true }); const sendMessage = vi .fn() @@ -49,7 +59,7 @@ function createHandler(cfg: OpenClawConfig, accountId = "default") { { token: "tg-token", accountId, - cfg, + cfg: normalizedCfg, }, { nowMs: () => 1000,