From 1b243ad5624af48c6faae36f0ba9daed05cbb1fb Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 7 Apr 2026 09:26:56 +0800 Subject: [PATCH] Tests: move cron session-scoping delivery to dispatch seam --- ...p-recipient-besteffortdeliver-true.test.ts | 34 ------------------- .../delivery-dispatch.double-announce.test.ts | 22 ++++++++++++ 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/cron/isolated-agent.skips-delivery-without-whatsapp-recipient-besteffortdeliver-true.test.ts b/src/cron/isolated-agent.skips-delivery-without-whatsapp-recipient-besteffortdeliver-true.test.ts index ccd86d02dcc..74d767986c5 100644 --- a/src/cron/isolated-agent.skips-delivery-without-whatsapp-recipient-besteffortdeliver-true.test.ts +++ b/src/cron/isolated-agent.skips-delivery-without-whatsapp-recipient-besteffortdeliver-true.test.ts @@ -249,40 +249,6 @@ describe("runCronIsolatedAgentTurn", () => { setupIsolatedAgentTurnMocks({ fast: true }); }); - it("delivers explicit targets directly with per-channel-peer session scoping", async () => { - await withTelegramAnnounceFixture(async ({ home, storePath, deps }) => { - mockAgentPayloads([{ text: "hello from cron" }]); - - const res = await runCronIsolatedAgentTurn({ - cfg: makeCfg(home, storePath, { - session: { - store: storePath, - mainKey: "main", - dmScope: "per-channel-peer", - }, - channels: { - telegram: { botToken: "t-1" }, - }, - }), - deps, - job: { - ...makeJob({ kind: "agentTurn", message: "do it" }), - delivery: { mode: "announce", channel: "telegram", to: "123" }, - }, - message: "do it", - sessionKey: "cron:job-1", - lane: "cron", - }); - - expectDeliveredOk(res); - expect(runSubagentAnnounceFlow).not.toHaveBeenCalled(); - expectDirectTelegramDelivery(deps, { - chatId: "123", - text: "hello from cron", - }); - }); - }); - it("routes threaded announce targets through direct delivery", async () => { await withTempHome(async (home) => { const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" }); diff --git a/src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts b/src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts index 03f27b7594c..5f5573d9742 100644 --- a/src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts +++ b/src/cron/isolated-agent/delivery-dispatch.double-announce.test.ts @@ -67,6 +67,7 @@ vi.mock("./subagent-followup.runtime.js", () => ({ import { countActiveDescendantRuns } from "../../agents/subagent-registry-read.js"; import { callGateway } from "../../gateway/call.runtime.js"; import { deliverOutboundPayloads } from "../../infra/outbound/deliver.js"; +import { buildOutboundSessionContext } from "../../infra/outbound/session-context.js"; import { enqueueSystemEvent } from "../../infra/system-events.js"; import { shouldEnqueueCronMainSummary } from "../heartbeat-policy.js"; import { @@ -690,6 +691,27 @@ describe("dispatchCronDelivery — double-announce guard", () => { ); }); + it("builds outbound session context from the run session key under per-channel-peer scoping", async () => { + vi.mocked(countActiveDescendantRuns).mockReturnValue(0); + vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false); + + const params = makeBaseParams({ synthesizedText: "hello from cron" }); + params.cfgWithAgentDefaults = { + session: { dmScope: "per-channel-peer" }, + } as never; + params.agentSessionKey = "agent:main:telegram:123456"; + + const state = await dispatchCronDelivery(params); + + expect(state.result).toBeUndefined(); + expect(state.delivered).toBe(true); + expect(buildOutboundSessionContext).toHaveBeenCalledWith({ + cfg: params.cfgWithAgentDefaults, + agentId: "main", + sessionKey: "agent:main:telegram:123456", + }); + }); + it("suppresses NO_REPLY payload with surrounding whitespace", async () => { vi.mocked(countActiveDescendantRuns).mockReturnValue(0); vi.mocked(isLikelyInterimCronMessage).mockReturnValue(false);