47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { vi } from "vitest";
|
|
import { parseTelegramTarget } from "../../extensions/telegram/src/targets.js";
|
|
import { signalOutbound, telegramOutbound } from "../../test/channel-outbounds.js";
|
|
import { loadModelCatalog } from "../agents/model-catalog.js";
|
|
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
|
|
import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js";
|
|
import { callGateway } from "../gateway/call.js";
|
|
import { setActivePluginRegistry } from "../plugins/runtime.js";
|
|
import { createOutboundTestPlugin, createTestRegistry } from "../test-utils/channel-plugins.js";
|
|
|
|
export function setupIsolatedAgentTurnMocks(params?: { fast?: boolean }): void {
|
|
if (params?.fast) {
|
|
vi.stubEnv("OPENCLAW_TEST_FAST", "1");
|
|
}
|
|
vi.mocked(runEmbeddedPiAgent).mockReset();
|
|
vi.mocked(loadModelCatalog).mockResolvedValue([]);
|
|
vi.mocked(runSubagentAnnounceFlow).mockReset().mockResolvedValue(true);
|
|
vi.mocked(callGateway).mockReset().mockResolvedValue({ ok: true, deleted: true });
|
|
setActivePluginRegistry(
|
|
createTestRegistry([
|
|
{
|
|
pluginId: "telegram",
|
|
plugin: createOutboundTestPlugin({
|
|
id: "telegram",
|
|
outbound: telegramOutbound,
|
|
messaging: {
|
|
parseExplicitTarget: ({ raw }) => {
|
|
const target = parseTelegramTarget(raw);
|
|
return {
|
|
to: target.chatId,
|
|
threadId: target.messageThreadId,
|
|
chatType: target.chatType === "unknown" ? undefined : target.chatType,
|
|
};
|
|
},
|
|
},
|
|
}),
|
|
source: "test",
|
|
},
|
|
{
|
|
pluginId: "signal",
|
|
plugin: createOutboundTestPlugin({ id: "signal", outbound: signalOutbound }),
|
|
source: "test",
|
|
},
|
|
]),
|
|
);
|
|
}
|