mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 11:37:38 +00:00
refactor(test): deduplicate isolated agent cron test helpers
This commit is contained in:
29
src/cron/isolated-agent.delivery.test-helpers.ts
Normal file
29
src/cron/isolated-agent.delivery.test-helpers.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { vi } from "vitest";
|
||||||
|
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
|
||||||
|
import type { CliDeps } from "../cli/deps.js";
|
||||||
|
|
||||||
|
export function createCliDeps(overrides: Partial<CliDeps> = {}): CliDeps {
|
||||||
|
return {
|
||||||
|
sendMessageSlack: vi.fn(),
|
||||||
|
sendMessageWhatsApp: vi.fn(),
|
||||||
|
sendMessageTelegram: vi.fn(),
|
||||||
|
sendMessageDiscord: vi.fn(),
|
||||||
|
sendMessageSignal: vi.fn(),
|
||||||
|
sendMessageIMessage: vi.fn(),
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mockAgentPayloads(
|
||||||
|
payloads: Array<Record<string, unknown>>,
|
||||||
|
extra: Partial<Awaited<ReturnType<typeof runEmbeddedPiAgent>>> = {},
|
||||||
|
): void {
|
||||||
|
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
||||||
|
payloads,
|
||||||
|
meta: {
|
||||||
|
durationMs: 5,
|
||||||
|
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
||||||
|
},
|
||||||
|
...extra,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
import "./isolated-agent.mocks.js";
|
import "./isolated-agent.mocks.js";
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
|
|
||||||
import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js";
|
import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js";
|
||||||
import type { CliDeps } from "../cli/deps.js";
|
import { createCliDeps, mockAgentPayloads } from "./isolated-agent.delivery.test-helpers.js";
|
||||||
import { runCronIsolatedAgentTurn } from "./isolated-agent.js";
|
import { runCronIsolatedAgentTurn } from "./isolated-agent.js";
|
||||||
import {
|
import {
|
||||||
makeCfg,
|
makeCfg,
|
||||||
@@ -12,28 +11,6 @@ import {
|
|||||||
} from "./isolated-agent.test-harness.js";
|
} from "./isolated-agent.test-harness.js";
|
||||||
import { setupIsolatedAgentTurnMocks } from "./isolated-agent.test-setup.js";
|
import { setupIsolatedAgentTurnMocks } from "./isolated-agent.test-setup.js";
|
||||||
|
|
||||||
function createCliDeps(overrides: Partial<CliDeps> = {}): CliDeps {
|
|
||||||
return {
|
|
||||||
sendMessageSlack: vi.fn(),
|
|
||||||
sendMessageWhatsApp: vi.fn(),
|
|
||||||
sendMessageTelegram: vi.fn(),
|
|
||||||
sendMessageDiscord: vi.fn(),
|
|
||||||
sendMessageSignal: vi.fn(),
|
|
||||||
sendMessageIMessage: vi.fn(),
|
|
||||||
...overrides,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function mockAgentPayloads(payloads: Array<Record<string, unknown>>) {
|
|
||||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
|
||||||
payloads,
|
|
||||||
meta: {
|
|
||||||
durationMs: 5,
|
|
||||||
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("runCronIsolatedAgentTurn forum topic delivery", () => {
|
describe("runCronIsolatedAgentTurn forum topic delivery", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
setupIsolatedAgentTurnMocks();
|
setupIsolatedAgentTurnMocks();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import "./isolated-agent.mocks.js";
|
import "./isolated-agent.mocks.js";
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
|
|
||||||
import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js";
|
import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js";
|
||||||
import type { CliDeps } from "../cli/deps.js";
|
import type { CliDeps } from "../cli/deps.js";
|
||||||
|
import { createCliDeps, mockAgentPayloads } from "./isolated-agent.delivery.test-helpers.js";
|
||||||
import { runCronIsolatedAgentTurn } from "./isolated-agent.js";
|
import { runCronIsolatedAgentTurn } from "./isolated-agent.js";
|
||||||
import {
|
import {
|
||||||
makeCfg,
|
makeCfg,
|
||||||
@@ -13,32 +13,6 @@ import {
|
|||||||
} from "./isolated-agent.test-harness.js";
|
} from "./isolated-agent.test-harness.js";
|
||||||
import { setupIsolatedAgentTurnMocks } from "./isolated-agent.test-setup.js";
|
import { setupIsolatedAgentTurnMocks } from "./isolated-agent.test-setup.js";
|
||||||
|
|
||||||
function createCliDeps(overrides: Partial<CliDeps> = {}): CliDeps {
|
|
||||||
return {
|
|
||||||
sendMessageSlack: vi.fn(),
|
|
||||||
sendMessageWhatsApp: vi.fn(),
|
|
||||||
sendMessageTelegram: vi.fn(),
|
|
||||||
sendMessageDiscord: vi.fn(),
|
|
||||||
sendMessageSignal: vi.fn(),
|
|
||||||
sendMessageIMessage: vi.fn(),
|
|
||||||
...overrides,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function mockAgentPayloads(
|
|
||||||
payloads: Array<Record<string, unknown>>,
|
|
||||||
extra: Partial<Awaited<ReturnType<typeof runEmbeddedPiAgent>>> = {},
|
|
||||||
): void {
|
|
||||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
|
||||||
payloads,
|
|
||||||
meta: {
|
|
||||||
durationMs: 5,
|
|
||||||
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
|
||||||
},
|
|
||||||
...extra,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runTelegramAnnounceTurn(params: {
|
async function runTelegramAnnounceTurn(params: {
|
||||||
home: string;
|
home: string;
|
||||||
storePath: string;
|
storePath: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user