diff --git a/src/cron/isolated-agent.direct-delivery-core-channels.test.ts b/src/cron/isolated-agent.direct-delivery-core-channels.test.ts index 623e358c851..9fb54c41575 100644 --- a/src/cron/isolated-agent.direct-delivery-core-channels.test.ts +++ b/src/cron/isolated-agent.direct-delivery-core-channels.test.ts @@ -6,7 +6,12 @@ import type { CliDeps } from "../cli/deps.js"; import { resolveOutboundSendDep } from "../infra/outbound/send-deps.js"; import { setActivePluginRegistry } from "../plugins/runtime.js"; import { createOutboundTestPlugin, createTestRegistry } from "../test-utils/channel-plugins.js"; -import { createCliDeps, mockAgentPayloads } from "./isolated-agent.delivery.test-helpers.js"; +import { + createCliDeps, + expectDirectTelegramDelivery, + mockAgentPayloads, + runTelegramAnnounceTurn, +} from "./isolated-agent.delivery.test-helpers.js"; import { runCronIsolatedAgentTurn } from "./isolated-agent.js"; import { makeCfg, @@ -175,6 +180,48 @@ const identityResolveTarget: ChannelOutboundAdapter["resolveTarget"] = ({ to }) : { ok: false, error: new Error("target is required") }; }; +function makeRunMeta(finalAssistantVisibleText: string) { + return { + durationMs: 5, + agentMeta: { sessionId: "s", provider: "p", model: "m" }, + finalAssistantVisibleText, + }; +} + +async function expectTelegramAnnounceDelivery({ + expected, + meta, + payloads, + to, +}: { + expected: Parameters[1]; + meta?: Parameters[1]; + payloads: Parameters[0]; + to: string; +}): Promise { + 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 core-channel direct delivery", () => { beforeEach(() => { setupIsolatedAgentTurnMocks({ fast: true }); @@ -266,3 +313,61 @@ describe("runCronIsolatedAgentTurn core-channel direct delivery", () => { }); } }); + +describe("runCronIsolatedAgentTurn telegram forum-topic direct delivery", () => { + beforeEach(() => { + setupIsolatedAgentTurnMocks(); + }); + + it("routes forum-topic telegram targets through the correct delivery path", async () => { + 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 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 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 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", + }, + }); + }); +}); diff --git a/src/cron/isolated-agent.direct-delivery-forum-topics.test.ts b/src/cron/isolated-agent.direct-delivery-forum-topics.test.ts deleted file mode 100644 index 7d8457d658b..00000000000 --- a/src/cron/isolated-agent.direct-delivery-forum-topics.test.ts +++ /dev/null @@ -1,111 +0,0 @@ -import "./isolated-agent.mocks.js"; -import { beforeEach, describe, expect, it } from "vitest"; -import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js"; -import { - createCliDeps, - expectDirectTelegramDelivery, - mockAgentPayloads, - runTelegramAnnounceTurn, -} from "./isolated-agent.delivery.test-helpers.js"; -import { withTempCronHome, writeSessionStore } from "./isolated-agent.test-harness.js"; -import { setupIsolatedAgentTurnMocks } from "./isolated-agent.test-setup.js"; - -function makeRunMeta(finalAssistantVisibleText: string) { - return { - durationMs: 5, - agentMeta: { sessionId: "s", provider: "p", model: "m" }, - finalAssistantVisibleText, - }; -} - -async function expectTelegramAnnounceDelivery({ - expected, - meta, - payloads, - to, -}: { - expected: Parameters[1]; - meta?: Parameters[1]; - payloads: Parameters[0]; - to: string; -}): Promise { - 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 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 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 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 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", - }, - }); - }); -});