Tests: move cron session-scoping delivery to dispatch seam

This commit is contained in:
Peter Steinberger
2026-04-07 09:26:56 +08:00
parent d8dbacb900
commit 1b243ad562
2 changed files with 22 additions and 34 deletions

View File

@@ -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: "" });

View File

@@ -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);