mirror of https://github.com/openclaw/openclaw.git
test: share cron run fallback helpers
This commit is contained in:
parent
0574ac23d0
commit
e64cc907ff
|
|
@ -7,6 +7,7 @@ import {
|
|||
countActiveDescendantRunsMock,
|
||||
listDescendantRunsForRequesterMock,
|
||||
loadRunCronIsolatedAgentTurn,
|
||||
mockRunCronFallbackPassthrough,
|
||||
pickLastNonEmptyTextFromPayloadsMock,
|
||||
runEmbeddedPiAgentMock,
|
||||
runWithModelFallbackMock,
|
||||
|
|
@ -17,13 +18,6 @@ const runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn();
|
|||
describe("runCronIsolatedAgentTurn — interim ack retry", () => {
|
||||
setupRunCronIsolatedAgentTurnSuite();
|
||||
|
||||
const mockFallbackPassthrough = () => {
|
||||
runWithModelFallbackMock.mockImplementation(async ({ provider, model, run }) => {
|
||||
const result = await run(provider, model);
|
||||
return { result, provider, model, attempts: [] };
|
||||
});
|
||||
};
|
||||
|
||||
const runTurnAndExpectOk = async (expectedFallbackCalls: number, expectedAgentCalls: number) => {
|
||||
const result = await runCronIsolatedAgentTurn(makeIsolatedAgentTurnParams());
|
||||
expect(result.status).toBe("ok");
|
||||
|
|
@ -62,7 +56,7 @@ describe("runCronIsolatedAgentTurn — interim ack retry", () => {
|
|||
meta: { agentMeta: { usage: { input: 10, output: 20 } } },
|
||||
});
|
||||
|
||||
mockFallbackPassthrough();
|
||||
mockRunCronFallbackPassthrough();
|
||||
await runTurnAndExpectOk(2, 2);
|
||||
expect(runEmbeddedPiAgentMock.mock.calls[1]?.[0]?.prompt).toContain(
|
||||
"previous response was only an acknowledgement",
|
||||
|
|
@ -76,7 +70,7 @@ describe("runCronIsolatedAgentTurn — interim ack retry", () => {
|
|||
meta: { agentMeta: { usage: { input: 10, output: 20 } } },
|
||||
});
|
||||
|
||||
mockFallbackPassthrough();
|
||||
mockRunCronFallbackPassthrough();
|
||||
await runTurnAndExpectOk(1, 1);
|
||||
});
|
||||
|
||||
|
|
@ -93,7 +87,7 @@ describe("runCronIsolatedAgentTurn — interim ack retry", () => {
|
|||
]);
|
||||
countActiveDescendantRunsMock.mockReturnValue(0);
|
||||
|
||||
mockFallbackPassthrough();
|
||||
mockRunCronFallbackPassthrough();
|
||||
await runTurnAndExpectOk(1, 1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|||
import {
|
||||
clearFastTestEnv,
|
||||
loadRunCronIsolatedAgentTurn,
|
||||
mockRunCronFallbackPassthrough,
|
||||
resetRunCronIsolatedAgentTurnHarness,
|
||||
resolveCronDeliveryPlanMock,
|
||||
resolveDeliveryTargetMock,
|
||||
restoreFastTestEnv,
|
||||
runEmbeddedPiAgentMock,
|
||||
runWithModelFallbackMock,
|
||||
} from "./run.test-harness.js";
|
||||
|
||||
const runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn();
|
||||
|
|
@ -32,12 +32,18 @@ function makeParams() {
|
|||
describe("runCronIsolatedAgentTurn message tool policy", () => {
|
||||
let previousFastTestEnv: string | undefined;
|
||||
|
||||
const mockFallbackPassthrough = () => {
|
||||
runWithModelFallbackMock.mockImplementation(async ({ provider, model, run }) => {
|
||||
const result = await run(provider, model);
|
||||
return { result, provider, model, attempts: [] };
|
||||
});
|
||||
};
|
||||
async function expectMessageToolDisabledForPlan(plan: {
|
||||
requested: boolean;
|
||||
mode: "none" | "announce";
|
||||
channel?: string;
|
||||
to?: string;
|
||||
}) {
|
||||
mockRunCronFallbackPassthrough();
|
||||
resolveCronDeliveryPlanMock.mockReturnValue(plan);
|
||||
await runCronIsolatedAgentTurn(makeParams());
|
||||
expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
|
||||
expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.disableMessageTool).toBe(true);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
previousFastTestEnv = clearFastTestEnv();
|
||||
|
|
@ -56,35 +62,23 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
|
|||
});
|
||||
|
||||
it('disables the message tool when delivery.mode is "none"', async () => {
|
||||
mockFallbackPassthrough();
|
||||
resolveCronDeliveryPlanMock.mockReturnValue({
|
||||
await expectMessageToolDisabledForPlan({
|
||||
requested: false,
|
||||
mode: "none",
|
||||
});
|
||||
|
||||
await runCronIsolatedAgentTurn(makeParams());
|
||||
|
||||
expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
|
||||
expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.disableMessageTool).toBe(true);
|
||||
});
|
||||
|
||||
it("disables the message tool when cron delivery is active", async () => {
|
||||
mockFallbackPassthrough();
|
||||
resolveCronDeliveryPlanMock.mockReturnValue({
|
||||
await expectMessageToolDisabledForPlan({
|
||||
requested: true,
|
||||
mode: "announce",
|
||||
channel: "telegram",
|
||||
to: "123",
|
||||
});
|
||||
|
||||
await runCronIsolatedAgentTurn(makeParams());
|
||||
|
||||
expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
|
||||
expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.disableMessageTool).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the message tool enabled for shared callers when delivery is not requested", async () => {
|
||||
mockFallbackPassthrough();
|
||||
mockRunCronFallbackPassthrough();
|
||||
resolveCronDeliveryPlanMock.mockReturnValue({
|
||||
requested: false,
|
||||
mode: "none",
|
||||
|
|
|
|||
|
|
@ -341,6 +341,13 @@ function makeDefaultEmbeddedResult() {
|
|||
};
|
||||
}
|
||||
|
||||
export function mockRunCronFallbackPassthrough(): void {
|
||||
runWithModelFallbackMock.mockImplementation(async ({ provider, model, run }) => {
|
||||
const result = await run(provider, model);
|
||||
return { result, provider, model, attempts: [] };
|
||||
});
|
||||
}
|
||||
|
||||
export function resetRunCronIsolatedAgentTurnHarness(): void {
|
||||
vi.clearAllMocks();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue