mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-21 23:11:01 +00:00
test(telegram): fix native command runtime mocks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../../src/config/config.js";
|
||||
import type { ResolvedAgentRoute } from "../../../src/routing/resolve-route.js";
|
||||
import type { TelegramBotDeps } from "./bot-deps.js";
|
||||
import {
|
||||
createDeferred,
|
||||
createNativeCommandTestParams,
|
||||
@@ -189,6 +190,16 @@ function registerAndResolveCommandHandlerBase(params: {
|
||||
} = params;
|
||||
const commandHandlers = new Map<string, TelegramCommandHandler>();
|
||||
const sendMessage = vi.fn().mockResolvedValue(undefined);
|
||||
const telegramDeps: TelegramBotDeps = {
|
||||
loadConfig: vi.fn(() => cfg),
|
||||
resolveStorePath: sessionMocks.resolveStorePath as TelegramBotDeps["resolveStorePath"],
|
||||
readChannelAllowFromStore: vi.fn(async () => []),
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
dispatchReplyWithBufferedBlockDispatcher:
|
||||
replyMocks.dispatchReplyWithBufferedBlockDispatcher as TelegramBotDeps["dispatchReplyWithBufferedBlockDispatcher"],
|
||||
listSkillCommandsForAgents: vi.fn(() => []),
|
||||
wasSentByBot: vi.fn(() => false),
|
||||
};
|
||||
registerTelegramNativeCommands({
|
||||
...createNativeCommandTestParams({
|
||||
bot: {
|
||||
@@ -206,6 +217,7 @@ function registerAndResolveCommandHandlerBase(params: {
|
||||
useAccessGroups,
|
||||
telegramCfg,
|
||||
resolveTelegramGroupConfig,
|
||||
telegramDeps,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
|
||||
import {
|
||||
createNativeCommandTestParams,
|
||||
listSkillCommandsForAgents,
|
||||
resetNativeCommandMenuMocks,
|
||||
waitForRegisteredCommands,
|
||||
} from "./bot-native-commands.menu-test-support.js";
|
||||
@@ -62,6 +63,10 @@ describe("registerTelegramNativeCommands skill allowlist integration", () => {
|
||||
},
|
||||
],
|
||||
};
|
||||
const actualSkillCommands = await import("../../../src/auto-reply/skill-commands.js");
|
||||
listSkillCommandsForAgents.mockImplementation(({ cfg, agentIds }) =>
|
||||
actualSkillCommands.listSkillCommandsForAgents({ cfg, agentIds }),
|
||||
);
|
||||
|
||||
registerTelegramNativeCommands({
|
||||
...createNativeCommandTestParams(cfg, {
|
||||
|
||||
@@ -65,28 +65,36 @@ const replyPipelineMocks = vi.hoisted(() => {
|
||||
export const dispatchReplyWithBufferedBlockDispatcher =
|
||||
replyPipelineMocks.dispatchReplyWithBufferedBlockDispatcher;
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/reply-runtime", () => ({
|
||||
finalizeInboundContext: replyPipelineMocks.finalizeInboundContext,
|
||||
}));
|
||||
vi.mock("openclaw/plugin-sdk/reply-runtime", () => ({
|
||||
dispatchReplyWithBufferedBlockDispatcher:
|
||||
replyPipelineMocks.dispatchReplyWithBufferedBlockDispatcher,
|
||||
}));
|
||||
vi.mock("openclaw/plugin-sdk/channel-runtime", () => ({
|
||||
createReplyPrefixOptions: replyPipelineMocks.createReplyPrefixOptions,
|
||||
}));
|
||||
vi.mock("openclaw/plugin-sdk/channel-runtime", () => ({
|
||||
recordInboundSessionMetaSafe: replyPipelineMocks.recordInboundSessionMetaSafe,
|
||||
}));
|
||||
vi.mock("openclaw/plugin-sdk/reply-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/reply-runtime")>();
|
||||
return {
|
||||
...actual,
|
||||
finalizeInboundContext: replyPipelineMocks.finalizeInboundContext,
|
||||
dispatchReplyWithBufferedBlockDispatcher:
|
||||
replyPipelineMocks.dispatchReplyWithBufferedBlockDispatcher,
|
||||
};
|
||||
});
|
||||
vi.mock("openclaw/plugin-sdk/channel-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/channel-runtime")>();
|
||||
return {
|
||||
...actual,
|
||||
createReplyPrefixOptions: replyPipelineMocks.createReplyPrefixOptions,
|
||||
recordInboundSessionMetaSafe: replyPipelineMocks.recordInboundSessionMetaSafe,
|
||||
};
|
||||
});
|
||||
|
||||
const deliveryMocks = vi.hoisted(() => ({
|
||||
deliverReplies: vi.fn(async () => {}),
|
||||
}));
|
||||
export const deliverReplies = deliveryMocks.deliverReplies;
|
||||
vi.mock("./bot/delivery.js", () => ({ deliverReplies: deliveryMocks.deliverReplies }));
|
||||
vi.mock("openclaw/plugin-sdk/conversation-runtime", () => ({
|
||||
readChannelAllowFromStore: vi.fn(async () => []),
|
||||
}));
|
||||
vi.mock("openclaw/plugin-sdk/conversation-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/conversation-runtime")>();
|
||||
return {
|
||||
...actual,
|
||||
readChannelAllowFromStore: vi.fn(async () => []),
|
||||
};
|
||||
});
|
||||
export { createNativeCommandTestParams };
|
||||
|
||||
export function createNativeCommandsHarness(params?: {
|
||||
@@ -104,6 +112,16 @@ export function createNativeCommandsHarness(params?: {
|
||||
const sendMessage: AnyAsyncMock = vi.fn(async () => undefined);
|
||||
const setMyCommands: AnyAsyncMock = vi.fn(async () => undefined);
|
||||
const log: AnyMock = vi.fn();
|
||||
const telegramDeps = {
|
||||
loadConfig: vi.fn(() => params?.cfg ?? ({} as OpenClawConfig)),
|
||||
resolveStorePath: vi.fn((storePath?: string) => storePath ?? "/tmp/sessions.json"),
|
||||
readChannelAllowFromStore: vi.fn(async () => []),
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
dispatchReplyWithBufferedBlockDispatcher:
|
||||
replyPipelineMocks.dispatchReplyWithBufferedBlockDispatcher,
|
||||
listSkillCommandsForAgents: vi.fn(() => []),
|
||||
wasSentByBot: vi.fn(() => false),
|
||||
};
|
||||
const bot = {
|
||||
api: {
|
||||
setMyCommands,
|
||||
@@ -128,6 +146,7 @@ export function createNativeCommandsHarness(params?: {
|
||||
nativeEnabled: params?.nativeEnabled ?? true,
|
||||
nativeSkillsEnabled: false,
|
||||
nativeDisabledExplicit: false,
|
||||
telegramDeps,
|
||||
resolveGroupPolicy:
|
||||
params?.resolveGroupPolicy ??
|
||||
(() =>
|
||||
|
||||
Reference in New Issue
Block a user