Skip to content

Commit 7ac35b4

Browse files
committed
perf: merge cron direct delivery tests
1 parent 350d322 commit 7ac35b4

2 files changed

Lines changed: 106 additions & 112 deletions

File tree

src/cron/isolated-agent.direct-delivery-core-channels.test.ts

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import type { CliDeps } from "../cli/deps.js";
66
import { resolveOutboundSendDep } from "../infra/outbound/send-deps.js";
77
import { setActivePluginRegistry } from "../plugins/runtime.js";
88
import { createOutboundTestPlugin, createTestRegistry } from "../test-utils/channel-plugins.js";
9-
import { createCliDeps, mockAgentPayloads } from "./isolated-agent.delivery.test-helpers.js";
9+
import {
10+
createCliDeps,
11+
expectDirectTelegramDelivery,
12+
mockAgentPayloads,
13+
runTelegramAnnounceTurn,
14+
} from "./isolated-agent.delivery.test-helpers.js";
1015
import { runCronIsolatedAgentTurn } from "./isolated-agent.js";
1116
import {
1217
makeCfg,
@@ -175,6 +180,48 @@ const identityResolveTarget: ChannelOutboundAdapter["resolveTarget"] = ({ to })
175180
: { ok: false, error: new Error("target is required") };
176181
};
177182

183+
function makeRunMeta(finalAssistantVisibleText: string) {
184+
return {
185+
durationMs: 5,
186+
agentMeta: { sessionId: "s", provider: "p", model: "m" },
187+
finalAssistantVisibleText,
188+
};
189+
}
190+
191+
async function expectTelegramAnnounceDelivery({
192+
expected,
193+
meta,
194+
payloads,
195+
to,
196+
}: {
197+
expected: Parameters<typeof expectDirectTelegramDelivery>[1];
198+
meta?: Parameters<typeof mockAgentPayloads>[1];
199+
payloads: Parameters<typeof mockAgentPayloads>[0];
200+
to: string;
201+
}): Promise<void> {
202+
await withTempCronHome(async (home) => {
203+
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
204+
const deps = createCliDeps();
205+
if (meta) {
206+
mockAgentPayloads(payloads, meta);
207+
} else {
208+
mockAgentPayloads(payloads);
209+
}
210+
211+
const res = await runTelegramAnnounceTurn({
212+
home,
213+
storePath,
214+
deps,
215+
delivery: { mode: "announce", channel: "telegram", to },
216+
});
217+
218+
expect(res.status).toBe("ok");
219+
expect(res.delivered).toBe(true);
220+
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
221+
expectDirectTelegramDelivery(deps, expected);
222+
});
223+
}
224+
178225
describe("runCronIsolatedAgentTurn core-channel direct delivery", () => {
179226
beforeEach(() => {
180227
setupIsolatedAgentTurnMocks({ fast: true });
@@ -266,3 +313,61 @@ describe("runCronIsolatedAgentTurn core-channel direct delivery", () => {
266313
});
267314
}
268315
});
316+
317+
describe("runCronIsolatedAgentTurn telegram forum-topic direct delivery", () => {
318+
beforeEach(() => {
319+
setupIsolatedAgentTurnMocks();
320+
});
321+
322+
it("routes forum-topic telegram targets through the correct delivery path", async () => {
323+
await expectTelegramAnnounceDelivery({
324+
to: "123:topic:42",
325+
payloads: [{ text: "forum message" }],
326+
expected: {
327+
chatId: "123",
328+
text: "forum message",
329+
messageThreadId: 42,
330+
},
331+
});
332+
});
333+
334+
it("delivers only the final assistant-visible text to forum-topic telegram targets", async () => {
335+
await expectTelegramAnnounceDelivery({
336+
to: "123:topic:42",
337+
payloads: [
338+
{ text: "section 1" },
339+
{ text: "temporary error", isError: true },
340+
{ text: "section 2" },
341+
],
342+
meta: { meta: makeRunMeta("section 1\nsection 2") },
343+
expected: {
344+
chatId: "123",
345+
text: "section 1\nsection 2",
346+
messageThreadId: 42,
347+
},
348+
});
349+
});
350+
351+
it("routes plain telegram targets through the correct delivery path", async () => {
352+
await expectTelegramAnnounceDelivery({
353+
to: "123",
354+
payloads: [{ text: "plain message" }],
355+
expected: {
356+
chatId: "123",
357+
text: "plain message",
358+
},
359+
});
360+
});
361+
362+
it("delivers only the final assistant-visible text to plain telegram targets", async () => {
363+
await expectTelegramAnnounceDelivery({
364+
to: "123",
365+
payloads: [{ text: "Working on it..." }, { text: "Final weather summary" }],
366+
meta: { meta: makeRunMeta("Final weather summary") },
367+
expected: {
368+
chatId: "123",
369+
text: "Final weather summary",
370+
},
371+
});
372+
});
373+
});

src/cron/isolated-agent.direct-delivery-forum-topics.test.ts

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)