fix(ci): repair telegram test harness config

This commit is contained in:
Peter Steinberger 2026-04-03 20:21:23 +01:00
parent 0805add3a4
commit 63443acc2b
No known key found for this signature in database
4 changed files with 71 additions and 26 deletions

View File

@ -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();
});

View File

@ -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();

View File

@ -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 () => {

View File

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