mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:50:49 +00:00
test: share core channel delivery harness
This commit is contained in:
@@ -83,6 +83,44 @@ async function runExplicitAnnounceTurn(params: {
|
||||
});
|
||||
}
|
||||
|
||||
type CoreChannelSendFn = CliDeps[ChannelCase["sendKey"]];
|
||||
|
||||
async function expectCoreChannelAnnounceDelivery({
|
||||
assertSend,
|
||||
meta,
|
||||
payloads,
|
||||
testCase,
|
||||
}: {
|
||||
assertSend: (sendFn: CoreChannelSendFn) => void;
|
||||
meta?: Parameters<typeof mockAgentPayloads>[1];
|
||||
payloads: Parameters<typeof mockAgentPayloads>[0];
|
||||
testCase: ChannelCase;
|
||||
}): Promise<void> {
|
||||
await withTempCronHome(async (home) => {
|
||||
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
|
||||
const deps = createCliDeps();
|
||||
if (meta) {
|
||||
mockAgentPayloads(payloads, meta);
|
||||
} else {
|
||||
mockAgentPayloads(payloads);
|
||||
}
|
||||
|
||||
const res = await runExplicitAnnounceTurn({
|
||||
home,
|
||||
storePath,
|
||||
deps,
|
||||
channel: testCase.channel,
|
||||
to: testCase.to,
|
||||
});
|
||||
|
||||
expect(res.status).toBe("ok");
|
||||
expect(res.delivered).toBe(true);
|
||||
expect(res.deliveryAttempted).toBe(true);
|
||||
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
|
||||
assertSend(deps[testCase.sendKey]);
|
||||
});
|
||||
}
|
||||
|
||||
type CoreChannel = ChannelCase["channel"];
|
||||
type TestSendFn = (
|
||||
to: string,
|
||||
@@ -180,73 +218,46 @@ describe("runCronIsolatedAgentTurn core-channel direct delivery", () => {
|
||||
|
||||
for (const testCase of CASES) {
|
||||
it(`routes ${testCase.name} text-only announce delivery through the outbound adapter`, async () => {
|
||||
await withTempCronHome(async (home) => {
|
||||
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
|
||||
const deps = createCliDeps();
|
||||
mockAgentPayloads([{ text: "hello from cron" }]);
|
||||
|
||||
const res = await runExplicitAnnounceTurn({
|
||||
home,
|
||||
storePath,
|
||||
deps,
|
||||
channel: testCase.channel,
|
||||
to: testCase.to,
|
||||
});
|
||||
|
||||
expect(res.status).toBe("ok");
|
||||
expect(res.delivered).toBe(true);
|
||||
expect(res.deliveryAttempted).toBe(true);
|
||||
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
|
||||
|
||||
const sendFn = deps[testCase.sendKey];
|
||||
expect(sendFn).toHaveBeenCalledTimes(1);
|
||||
expect(sendFn).toHaveBeenCalledWith(
|
||||
testCase.expectedTo,
|
||||
"hello from cron",
|
||||
expect.any(Object),
|
||||
);
|
||||
await expectCoreChannelAnnounceDelivery({
|
||||
testCase,
|
||||
payloads: [{ text: "hello from cron" }],
|
||||
assertSend: (sendFn) => {
|
||||
expect(sendFn).toHaveBeenCalledTimes(1);
|
||||
expect(sendFn).toHaveBeenCalledWith(
|
||||
testCase.expectedTo,
|
||||
"hello from cron",
|
||||
expect.any(Object),
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it(`preserves multi-payload text-only announce delivery for ${testCase.name} even when final assistant text exists`, async () => {
|
||||
await withTempCronHome(async (home) => {
|
||||
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
|
||||
const deps = createCliDeps();
|
||||
mockAgentPayloads([{ text: "Working on it..." }, { text: "Final weather summary" }], {
|
||||
await expectCoreChannelAnnounceDelivery({
|
||||
testCase,
|
||||
payloads: [{ text: "Working on it..." }, { text: "Final weather summary" }],
|
||||
meta: {
|
||||
meta: {
|
||||
durationMs: 5,
|
||||
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
||||
finalAssistantVisibleText: "Final weather summary",
|
||||
},
|
||||
});
|
||||
|
||||
const res = await runExplicitAnnounceTurn({
|
||||
home,
|
||||
storePath,
|
||||
deps,
|
||||
channel: testCase.channel,
|
||||
to: testCase.to,
|
||||
});
|
||||
|
||||
expect(res.status).toBe("ok");
|
||||
expect(res.delivered).toBe(true);
|
||||
expect(res.deliveryAttempted).toBe(true);
|
||||
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
|
||||
|
||||
const sendFn = deps[testCase.sendKey];
|
||||
expect(sendFn).toHaveBeenCalledTimes(2);
|
||||
expect(sendFn).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
testCase.expectedTo,
|
||||
"Working on it...",
|
||||
expect.any(Object),
|
||||
);
|
||||
expect(sendFn).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
testCase.expectedTo,
|
||||
"Final weather summary",
|
||||
expect.any(Object),
|
||||
);
|
||||
},
|
||||
assertSend: (sendFn) => {
|
||||
expect(sendFn).toHaveBeenCalledTimes(2);
|
||||
expect(sendFn).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
testCase.expectedTo,
|
||||
"Working on it...",
|
||||
expect.any(Object),
|
||||
);
|
||||
expect(sendFn).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
testCase.expectedTo,
|
||||
"Final weather summary",
|
||||
expect.any(Object),
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user