diff --git a/CHANGELOG.md b/CHANGELOG.md index 311eb67cf..64f219996 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ Docs: https://docs.openclaw.ai ### Fixes +- Tests/Telegram: add regression coverage for command-menu sync that asserts all `setMyCommands` entries are Telegram-safe and hyphen-normalized across native/custom/plugin command sources. (#19703) Thanks @obviyus. - Agents/Image: collapse resize diagnostics to one line per image and include visible pixel/byte size details in the log message for faster triage. - Agents/Subagents: preemptively guard accumulated tool-result context before model calls by truncating oversized outputs and compacting oldest tool-result messages to avoid context-window overflow crashes. Thanks @tyler6204. - Agents/Subagents: add explicit subagent guidance to recover from `[compacted: tool output removed to free context]` / `[truncated: output exceeded context limit]` markers by re-reading with smaller chunks instead of full-file `cat`. Thanks @tyler6204. diff --git a/src/telegram/bot-native-command-menu.test.ts b/src/telegram/bot-native-command-menu.test.ts index a1b77e943..cabea3132 100644 --- a/src/telegram/bot-native-command-menu.test.ts +++ b/src/telegram/bot-native-command-menu.test.ts @@ -50,6 +50,16 @@ describe("bot-native-command-menu", () => { expect(result.issues).toContain('Plugin command "/empty" is missing a description.'); }); + it("normalizes hyphenated plugin command names", () => { + const result = buildPluginTelegramMenuCommands({ + specs: [{ name: "agent-run", description: "Run agent" }], + existingCommands: new Set(), + }); + + expect(result.commands).toEqual([{ command: "agent_run", description: "Run agent" }]); + expect(result.issues).toEqual([]); + }); + it("deletes stale commands before setting new menu", async () => { const callOrder: string[] = []; const deleteMyCommands = vi.fn(async () => { diff --git a/src/telegram/bot-native-commands.test.ts b/src/telegram/bot-native-commands.test.ts index 0c89a63ff..08bc90925 100644 --- a/src/telegram/bot-native-commands.test.ts +++ b/src/telegram/bot-native-commands.test.ts @@ -2,6 +2,7 @@ import path from "node:path"; import { beforeEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import { STATE_DIR } from "../config/paths.js"; +import { TELEGRAM_COMMAND_NAME_PATTERN } from "../config/telegram-custom-commands.js"; import type { TelegramAccountConfig } from "../config/types.js"; import type { RuntimeEnv } from "../runtime.js"; import { registerTelegramNativeCommands } from "./bot-native-commands.js"; @@ -180,6 +181,53 @@ describe("registerTelegramNativeCommands", () => { expect(registeredHandlers).not.toContain("export-session"); }); + it("registers only Telegram-safe command names across native, custom, and plugin sources", async () => { + const setMyCommands = vi.fn().mockResolvedValue(undefined); + + pluginCommandMocks.getPluginCommandSpecs.mockReturnValue([ + { name: "plugin-status", description: "Plugin status" }, + { name: "plugin@bad", description: "Bad plugin command" }, + ] as never); + + registerTelegramNativeCommands({ + ...buildParams({}), + bot: { + api: { + setMyCommands, + sendMessage: vi.fn().mockResolvedValue(undefined), + }, + command: vi.fn(), + } as unknown as Parameters[0]["bot"], + telegramCfg: { + customCommands: [ + { command: "custom-backup", description: "Custom backup" }, + { command: "custom!bad", description: "Bad custom command" }, + ], + } as TelegramAccountConfig, + }); + + await vi.waitFor(() => { + expect(setMyCommands).toHaveBeenCalled(); + }); + + const registeredCommands = setMyCommands.mock.calls[0]?.[0] as Array<{ + command: string; + description: string; + }>; + + expect(registeredCommands.length).toBeGreaterThan(0); + for (const entry of registeredCommands) { + expect(entry.command.includes("-")).toBe(false); + expect(TELEGRAM_COMMAND_NAME_PATTERN.test(entry.command)).toBe(true); + } + + expect(registeredCommands.some((entry) => entry.command === "export_session")).toBe(true); + expect(registeredCommands.some((entry) => entry.command === "custom_backup")).toBe(true); + expect(registeredCommands.some((entry) => entry.command === "plugin_status")).toBe(true); + expect(registeredCommands.some((entry) => entry.command === "plugin-status")).toBe(false); + expect(registeredCommands.some((entry) => entry.command === "custom-bad")).toBe(false); + }); + it("passes agent-scoped media roots for plugin command replies with media", async () => { const commandHandlers = new Map Promise>(); const sendMessage = vi.fn().mockResolvedValue(undefined);