test: share telegram forum delivery harness

This commit is contained in:
Peter Steinberger
2026-04-19 01:21:35 +01:00
parent 13e707fb7f
commit 550b946696

View File

@@ -18,107 +18,94 @@ function makeRunMeta(finalAssistantVisibleText: string) {
};
}
async function expectTelegramAnnounceDelivery({
expected,
meta,
payloads,
to,
}: {
expected: Parameters<typeof expectDirectTelegramDelivery>[1];
meta?: Parameters<typeof mockAgentPayloads>[1];
payloads: Parameters<typeof mockAgentPayloads>[0];
to: string;
}): 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 runTelegramAnnounceTurn({
home,
storePath,
deps,
delivery: { mode: "announce", channel: "telegram", to },
});
expect(res.status).toBe("ok");
expect(res.delivered).toBe(true);
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
expectDirectTelegramDelivery(deps, expected);
});
}
describe("runCronIsolatedAgentTurn forum topic delivery", () => {
beforeEach(() => {
setupIsolatedAgentTurnMocks();
});
it("routes forum-topic telegram targets through the correct delivery path", async () => {
await withTempCronHome(async (home) => {
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
const deps = createCliDeps();
mockAgentPayloads([{ text: "forum message" }]);
const res = await runTelegramAnnounceTurn({
home,
storePath,
deps,
delivery: { mode: "announce", channel: "telegram", to: "123:topic:42" },
});
expect(res.status).toBe("ok");
expect(res.delivered).toBe(true);
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
expectDirectTelegramDelivery(deps, {
await expectTelegramAnnounceDelivery({
to: "123:topic:42",
payloads: [{ text: "forum message" }],
expected: {
chatId: "123",
text: "forum message",
messageThreadId: 42,
});
},
});
});
it("delivers only the final assistant-visible text to forum-topic telegram targets", async () => {
await withTempCronHome(async (home) => {
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
const deps = createCliDeps();
mockAgentPayloads(
[{ text: "section 1" }, { text: "temporary error", isError: true }, { text: "section 2" }],
{ meta: makeRunMeta("section 1\nsection 2") },
);
const res = await runTelegramAnnounceTurn({
home,
storePath,
deps,
delivery: { mode: "announce", channel: "telegram", to: "123:topic:42" },
});
expect(res.status).toBe("ok");
expect(res.delivered).toBe(true);
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
expectDirectTelegramDelivery(deps, {
await expectTelegramAnnounceDelivery({
to: "123:topic:42",
payloads: [
{ text: "section 1" },
{ text: "temporary error", isError: true },
{ text: "section 2" },
],
meta: { meta: makeRunMeta("section 1\nsection 2") },
expected: {
chatId: "123",
text: "section 1\nsection 2",
messageThreadId: 42,
});
},
});
});
it("routes plain telegram targets through the correct delivery path", async () => {
await withTempCronHome(async (home) => {
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
const deps = createCliDeps();
mockAgentPayloads([{ text: "plain message" }]);
const plainRes = await runTelegramAnnounceTurn({
home,
storePath,
deps,
delivery: { mode: "announce", channel: "telegram", to: "123" },
});
expect(plainRes.status).toBe("ok");
expect(plainRes.delivered).toBe(true);
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
expectDirectTelegramDelivery(deps, {
await expectTelegramAnnounceDelivery({
to: "123",
payloads: [{ text: "plain message" }],
expected: {
chatId: "123",
text: "plain message",
});
},
});
});
it("delivers only the final assistant-visible text to plain telegram targets", 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" }], {
meta: makeRunMeta("Final weather summary"),
});
const plainRes = await runTelegramAnnounceTurn({
home,
storePath,
deps,
delivery: { mode: "announce", channel: "telegram", to: "123" },
});
expect(plainRes.status).toBe("ok");
expect(plainRes.delivered).toBe(true);
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
expectDirectTelegramDelivery(deps, {
await expectTelegramAnnounceDelivery({
to: "123",
payloads: [{ text: "Working on it..." }, { text: "Final weather summary" }],
meta: { meta: makeRunMeta("Final weather summary") },
expected: {
chatId: "123",
text: "Final weather summary",
});
},
});
});
});