mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-19 05:50:47 +00:00
refactor(telegram): reuse menu helpers in skill allowlist test
This commit is contained in:
@@ -4,26 +4,24 @@ import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { writeSkill } from "../../../src/agents/skills.e2e-test-helpers.js";
|
||||
import type { OpenClawConfig } from "../../../src/config/config.js";
|
||||
import type { TelegramAccountConfig } from "../../../src/config/types.js";
|
||||
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
|
||||
import {
|
||||
createNativeCommandTestParams,
|
||||
resetNativeCommandMenuMocks,
|
||||
waitForRegisteredCommands,
|
||||
} from "./bot-native-commands.menu-test-support.js";
|
||||
|
||||
const pluginCommandMocks = vi.hoisted(() => ({
|
||||
getPluginCommandSpecs: vi.fn(() => []),
|
||||
matchPluginCommand: vi.fn(() => null),
|
||||
executePluginCommand: vi.fn(async () => ({ text: "ok" })),
|
||||
}));
|
||||
const deliveryMocks = vi.hoisted(() => ({
|
||||
deliverReplies: vi.fn(async () => ({ delivered: true })),
|
||||
}));
|
||||
|
||||
vi.mock("../../../src/plugins/commands.js", () => ({
|
||||
getPluginCommandSpecs: pluginCommandMocks.getPluginCommandSpecs,
|
||||
matchPluginCommand: pluginCommandMocks.matchPluginCommand,
|
||||
executePluginCommand: pluginCommandMocks.executePluginCommand,
|
||||
}));
|
||||
vi.mock("./bot/delivery.js", () => ({
|
||||
deliverReplies: deliveryMocks.deliverReplies,
|
||||
}));
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
@@ -35,10 +33,10 @@ async function makeWorkspace(prefix: string) {
|
||||
|
||||
describe("registerTelegramNativeCommands skill allowlist integration", () => {
|
||||
afterEach(async () => {
|
||||
resetNativeCommandMenuMocks();
|
||||
pluginCommandMocks.getPluginCommandSpecs.mockClear().mockReturnValue([]);
|
||||
pluginCommandMocks.matchPluginCommand.mockClear().mockReturnValue(null);
|
||||
pluginCommandMocks.executePluginCommand.mockClear().mockResolvedValue({ text: "ok" });
|
||||
deliveryMocks.deliverReplies.mockClear().mockResolvedValue({ delivered: true });
|
||||
await Promise.all(
|
||||
tempDirs
|
||||
.splice(0, tempDirs.length)
|
||||
@@ -76,49 +74,22 @@ describe("registerTelegramNativeCommands skill allowlist integration", () => {
|
||||
};
|
||||
|
||||
registerTelegramNativeCommands({
|
||||
bot: {
|
||||
api: {
|
||||
setMyCommands,
|
||||
sendMessage: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
command: vi.fn(),
|
||||
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
|
||||
cfg,
|
||||
runtime: { log: vi.fn() } as unknown as Parameters<
|
||||
typeof registerTelegramNativeCommands
|
||||
>[0]["runtime"],
|
||||
accountId: "bot-a",
|
||||
telegramCfg: {} as TelegramAccountConfig,
|
||||
allowFrom: [],
|
||||
groupAllowFrom: [],
|
||||
replyToMode: "off",
|
||||
textLimit: 4000,
|
||||
useAccessGroups: false,
|
||||
nativeEnabled: true,
|
||||
nativeSkillsEnabled: true,
|
||||
nativeDisabledExplicit: false,
|
||||
resolveGroupPolicy: () =>
|
||||
({
|
||||
allowlistEnabled: false,
|
||||
allowed: true,
|
||||
}) as ReturnType<
|
||||
Parameters<typeof registerTelegramNativeCommands>[0]["resolveGroupPolicy"]
|
||||
>,
|
||||
resolveTelegramGroupConfig: () => ({
|
||||
groupConfig: undefined,
|
||||
topicConfig: undefined,
|
||||
...createNativeCommandTestParams(cfg, {
|
||||
bot: {
|
||||
api: {
|
||||
setMyCommands,
|
||||
sendMessage: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
command: vi.fn(),
|
||||
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
|
||||
runtime: { log: vi.fn() } as unknown as Parameters<
|
||||
typeof registerTelegramNativeCommands
|
||||
>[0]["runtime"],
|
||||
accountId: "bot-a",
|
||||
}),
|
||||
shouldSkipUpdate: () => false,
|
||||
opts: { token: "token" },
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(setMyCommands).toHaveBeenCalled();
|
||||
});
|
||||
const registeredCommands = setMyCommands.mock.calls[0]?.[0] as Array<{
|
||||
command: string;
|
||||
description: string;
|
||||
}>;
|
||||
const registeredCommands = await waitForRegisteredCommands(setMyCommands);
|
||||
|
||||
expect(registeredCommands.some((entry) => entry.command === "alpha_skill")).toBe(true);
|
||||
expect(registeredCommands.some((entry) => entry.command === "beta_skill")).toBe(false);
|
||||
|
||||
Reference in New Issue
Block a user