test: harden Telegram command menu sanitization coverage (#19703)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 6a41b115902cafb5f5d79666850d4f3cd6b603ec
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
Ayaan Zaidi
2026-02-18 09:16:31 +05:30
committed by GitHub
parent cc29be8c9b
commit 6a5f887b3d
3 changed files with 59 additions and 0 deletions

View File

@@ -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.

View File

@@ -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<string>(),
});
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 () => {

View File

@@ -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<typeof registerTelegramNativeCommands>[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<string, (ctx: unknown) => Promise<void>>();
const sendMessage = vi.fn().mockResolvedValue(undefined);