

























@@ -6,7 +6,12 @@ import type { CliDeps } from "../cli/deps.js";
66import { resolveOutboundSendDep } from "../infra/outbound/send-deps.js";
77import { setActivePluginRegistry } from "../plugins/runtime.js";
88import { 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";
1015import { runCronIsolatedAgentTurn } from "./isolated-agent.js";
1116import {
1217makeCfg,
@@ -175,6 +180,48 @@ const identityResolveTarget: ChannelOutboundAdapter["resolveTarget"] = ({ to })
175180 : { ok: false, error: new Error("target is required") };
176181};
177182183+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+178225describe("runCronIsolatedAgentTurn core-channel direct delivery", () => {
179226beforeEach(() => {
180227setupIsolatedAgentTurnMocks({ 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+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。