Tests: move cron threaded delivery to dispatch seam

This commit is contained in:
Peter Steinberger
2026-04-07 09:32:37 +08:00
parent 1b243ad562
commit 3da203556c
2 changed files with 25 additions and 41 deletions

View File

@@ -1,5 +1,4 @@
import "./isolated-agent.mocks.js";
import fs from "node:fs/promises";
import { beforeEach, describe, expect, it, vi } from "vitest";
import * as modelSelection from "../agents/model-selection.js";
import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js";
@@ -249,46 +248,6 @@ describe("runCronIsolatedAgentTurn", () => {
setupIsolatedAgentTurnMocks({ fast: true });
});
it("routes threaded announce targets through direct delivery", async () => {
await withTempHome(async (home) => {
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
await fs.writeFile(
storePath,
JSON.stringify(
{
"agent:main:main": {
sessionId: "main-session",
updatedAt: Date.now(),
lastChannel: "telegram",
lastTo: "123",
lastThreadId: 42,
},
},
null,
2,
),
"utf-8",
);
const deps = createCliDeps();
mockAgentPayloads([{ text: "Final weather summary" }]);
const res = await runTelegramAnnounceTurn({
home,
storePath,
deps,
delivery: { mode: "announce", channel: "last" },
});
expect(res.status).toBe("ok");
expect(res.delivered).toBe(true);
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
expectDirectTelegramDelivery(deps, {
chatId: "123",
text: "Final weather summary",
messageThreadId: 42,
});
});
});
it("skips announce when messaging tool already sent to target", async () => {
await withTelegramAnnounceFixture(async ({ home, storePath, deps }) => {
mockAgentPayloads([{ text: "sent" }], {

View File

@@ -712,6 +712,31 @@ describe("dispatchCronDelivery — double-announce guard", () => {
});
});
it("passes threaded telegram delivery through to the outbound adapter", async () => {
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);
const params = makeBaseParams({ synthesizedText: "Final weather summary" });
params.resolvedDelivery = {
...makeResolvedDelivery(),
mode: "implicit",
threadId: 42,
};
const state = await dispatchCronDelivery(params);
expect(state.result).toBeUndefined();
expect(state.delivered).toBe(true);
expect(deliverOutboundPayloads).toHaveBeenCalledWith(
expect.objectContaining({
channel: "telegram",
to: "123456",
threadId: 42,
payloads: [{ text: "Final weather summary" }],
}),
);
});
it("suppresses NO_REPLY payload with surrounding whitespace", async () => {
vi.mocked(countActiveDescendantRuns).mockReturnValue(0);
vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);