test(telegram): dedupe native-command test setup

This commit is contained in:
Peter Steinberger
2026-02-22 07:48:35 +00:00
parent cd7faea93b
commit 94e5a46187
3 changed files with 98 additions and 109 deletions

View File

@@ -6,6 +6,7 @@ import { TELEGRAM_COMMAND_NAME_PATTERN } from "../config/telegram-custom-command
import type { TelegramAccountConfig } from "../config/types.js";
import type { RuntimeEnv } from "../runtime.js";
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
import { createNativeCommandTestParams } from "./bot-native-commands.test-helpers.js";
const { listSkillCommandsForAgents } = vi.hoisted(() => ({
listSkillCommandsForAgents: vi.fn(() => []),
@@ -63,34 +64,20 @@ describe("registerTelegramNativeCommands", () => {
deliveryMocks.deliverReplies.mockResolvedValue({ delivered: true });
});
const buildParams = (cfg: OpenClawConfig, accountId = "default") => ({
bot: {
api: {
setMyCommands: vi.fn().mockResolvedValue(undefined),
sendMessage: vi.fn().mockResolvedValue(undefined),
},
command: vi.fn(),
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
cfg,
runtime: {} as unknown as RuntimeEnv,
accountId,
telegramCfg: {} as TelegramAccountConfig,
allowFrom: [],
groupAllowFrom: [],
replyToMode: "off" as const,
textLimit: 4096,
useAccessGroups: false,
nativeEnabled: true,
nativeSkillsEnabled: true,
nativeDisabledExplicit: false,
resolveGroupPolicy: () => ({ allowlistEnabled: false, allowed: true }),
resolveTelegramGroupConfig: () => ({
groupConfig: undefined,
topicConfig: undefined,
}),
shouldSkipUpdate: () => false,
opts: { token: "token" },
});
const buildParams = (cfg: OpenClawConfig, accountId = "default") =>
createNativeCommandTestParams({
bot: {
api: {
setMyCommands: vi.fn().mockResolvedValue(undefined),
sendMessage: vi.fn().mockResolvedValue(undefined),
},
command: vi.fn(),
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
cfg,
runtime: {} as RuntimeEnv,
accountId,
telegramCfg: {} as TelegramAccountConfig,
});
it("scopes skill commands when account binding exists", () => {
const cfg: OpenClawConfig = {