mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 08:48:37 +00:00
test: harden Telegram command menu sanitization coverage (#19703)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 6a41b11590
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:
@@ -55,6 +55,7 @@ Docs: https://docs.openclaw.ai
|
|||||||
|
|
||||||
### Fixes
|
### 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/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: 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.
|
- 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.
|
||||||
|
|||||||
@@ -50,6 +50,16 @@ describe("bot-native-command-menu", () => {
|
|||||||
expect(result.issues).toContain('Plugin command "/empty" is missing a description.');
|
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 () => {
|
it("deletes stale commands before setting new menu", async () => {
|
||||||
const callOrder: string[] = [];
|
const callOrder: string[] = [];
|
||||||
const deleteMyCommands = vi.fn(async () => {
|
const deleteMyCommands = vi.fn(async () => {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import path from "node:path";
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import { STATE_DIR } from "../config/paths.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 { TelegramAccountConfig } from "../config/types.js";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
|
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
|
||||||
@@ -180,6 +181,53 @@ describe("registerTelegramNativeCommands", () => {
|
|||||||
expect(registeredHandlers).not.toContain("export-session");
|
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 () => {
|
it("passes agent-scoped media roots for plugin command replies with media", async () => {
|
||||||
const commandHandlers = new Map<string, (ctx: unknown) => Promise<void>>();
|
const commandHandlers = new Map<string, (ctx: unknown) => Promise<void>>();
|
||||||
const sendMessage = vi.fn().mockResolvedValue(undefined);
|
const sendMessage = vi.fn().mockResolvedValue(undefined);
|
||||||
|
|||||||
Reference in New Issue
Block a user