Skip to content

Commit 550b946

Browse files
committed
test: share telegram forum delivery harness
1 parent 13e707f commit 550b946

1 file changed

Lines changed: 60 additions & 73 deletions

File tree

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

Lines changed: 60 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,107 +18,94 @@ function makeRunMeta(finalAssistantVisibleText: string) {
1818
};
1919
}
2020

21+
async function expectTelegramAnnounceDelivery({
22+
expected,
23+
meta,
24+
payloads,
25+
to,
26+
}: {
27+
expected: Parameters<typeof expectDirectTelegramDelivery>[1];
28+
meta?: Parameters<typeof mockAgentPayloads>[1];
29+
payloads: Parameters<typeof mockAgentPayloads>[0];
30+
to: string;
31+
}): Promise<void> {
32+
await withTempCronHome(async (home) => {
33+
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
34+
const deps = createCliDeps();
35+
if (meta) {
36+
mockAgentPayloads(payloads, meta);
37+
} else {
38+
mockAgentPayloads(payloads);
39+
}
40+
41+
const res = await runTelegramAnnounceTurn({
42+
home,
43+
storePath,
44+
deps,
45+
delivery: { mode: "announce", channel: "telegram", to },
46+
});
47+
48+
expect(res.status).toBe("ok");
49+
expect(res.delivered).toBe(true);
50+
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
51+
expectDirectTelegramDelivery(deps, expected);
52+
});
53+
}
54+
2155
describe("runCronIsolatedAgentTurn forum topic delivery", () => {
2256
beforeEach(() => {
2357
setupIsolatedAgentTurnMocks();
2458
});
2559

2660
it("routes forum-topic telegram targets through the correct delivery path", async () => {
27-
await withTempCronHome(async (home) => {
28-
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
29-
const deps = createCliDeps();
30-
mockAgentPayloads([{ text: "forum message" }]);
31-
32-
const res = await runTelegramAnnounceTurn({
33-
home,
34-
storePath,
35-
deps,
36-
delivery: { mode: "announce", channel: "telegram", to: "123:topic:42" },
37-
});
38-
39-
expect(res.status).toBe("ok");
40-
expect(res.delivered).toBe(true);
41-
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
42-
expectDirectTelegramDelivery(deps, {
61+
await expectTelegramAnnounceDelivery({
62+
to: "123:topic:42",
63+
payloads: [{ text: "forum message" }],
64+
expected: {
4365
chatId: "123",
4466
text: "forum message",
4567
messageThreadId: 42,
46-
});
68+
},
4769
});
4870
});
4971

5072
it("delivers only the final assistant-visible text to forum-topic telegram targets", async () => {
51-
await withTempCronHome(async (home) => {
52-
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
53-
const deps = createCliDeps();
54-
mockAgentPayloads(
55-
[{ text: "section 1" }, { text: "temporary error", isError: true }, { text: "section 2" }],
56-
{ meta: makeRunMeta("section 1\nsection 2") },
57-
);
58-
59-
const res = await runTelegramAnnounceTurn({
60-
home,
61-
storePath,
62-
deps,
63-
delivery: { mode: "announce", channel: "telegram", to: "123:topic:42" },
64-
});
65-
66-
expect(res.status).toBe("ok");
67-
expect(res.delivered).toBe(true);
68-
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
69-
expectDirectTelegramDelivery(deps, {
73+
await expectTelegramAnnounceDelivery({
74+
to: "123:topic:42",
75+
payloads: [
76+
{ text: "section 1" },
77+
{ text: "temporary error", isError: true },
78+
{ text: "section 2" },
79+
],
80+
meta: { meta: makeRunMeta("section 1\nsection 2") },
81+
expected: {
7082
chatId: "123",
7183
text: "section 1\nsection 2",
7284
messageThreadId: 42,
73-
});
85+
},
7486
});
7587
});
7688

7789
it("routes plain telegram targets through the correct delivery path", async () => {
78-
await withTempCronHome(async (home) => {
79-
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
80-
const deps = createCliDeps();
81-
mockAgentPayloads([{ text: "plain message" }]);
82-
83-
const plainRes = await runTelegramAnnounceTurn({
84-
home,
85-
storePath,
86-
deps,
87-
delivery: { mode: "announce", channel: "telegram", to: "123" },
88-
});
89-
90-
expect(plainRes.status).toBe("ok");
91-
expect(plainRes.delivered).toBe(true);
92-
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
93-
expectDirectTelegramDelivery(deps, {
90+
await expectTelegramAnnounceDelivery({
91+
to: "123",
92+
payloads: [{ text: "plain message" }],
93+
expected: {
9494
chatId: "123",
9595
text: "plain message",
96-
});
96+
},
9797
});
9898
});
9999

100100
it("delivers only the final assistant-visible text to plain telegram targets", async () => {
101-
await withTempCronHome(async (home) => {
102-
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
103-
const deps = createCliDeps();
104-
mockAgentPayloads([{ text: "Working on it..." }, { text: "Final weather summary" }], {
105-
meta: makeRunMeta("Final weather summary"),
106-
});
107-
108-
const plainRes = await runTelegramAnnounceTurn({
109-
home,
110-
storePath,
111-
deps,
112-
delivery: { mode: "announce", channel: "telegram", to: "123" },
113-
});
114-
115-
expect(plainRes.status).toBe("ok");
116-
expect(plainRes.delivered).toBe(true);
117-
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
118-
expectDirectTelegramDelivery(deps, {
101+
await expectTelegramAnnounceDelivery({
102+
to: "123",
103+
payloads: [{ text: "Working on it..." }, { text: "Final weather summary" }],
104+
meta: { meta: makeRunMeta("Final weather summary") },
105+
expected: {
119106
chatId: "123",
120107
text: "Final weather summary",
121-
});
108+
},
122109
});
123110
});
124111
});

0 commit comments

Comments
 (0)