diff --git a/src/cron/isolated-agent/delivery-target.test.ts b/src/cron/isolated-agent/delivery-target.test.ts index 8d94cca7955..099f479db0e 100644 --- a/src/cron/isolated-agent/delivery-target.test.ts +++ b/src/cron/isolated-agent/delivery-target.test.ts @@ -216,6 +216,29 @@ describe("resolveDeliveryTarget", () => { expect(result.to).toBe("room-allowed"); }); + it("applies allowFrom rerouting to dry-run delivery previews", async () => { + setLastSessionEntry({ + sessionId: "sess-preview", + lastChannel: "alpha", + lastTo: "room-denied", + }); + setStoredAlphaAllowFrom(["room-allowed"]); + + const cfg = makeCfg({ bindings: [], channels: { alpha: { allowFrom: [] } } }); + const result = await resolveDeliveryTarget( + cfg, + AGENT_ID, + { + channel: "last", + to: undefined, + }, + { dryRun: true }, + ); + + expect(result.channel).toBe("alpha"); + expect(result.to).toBe("room-allowed"); + }); + it("keeps explicit delivery target unchanged", async () => { setLastSessionEntry({ sessionId: "sess-w2", diff --git a/src/cron/isolated-agent/delivery-target.ts b/src/cron/isolated-agent/delivery-target.ts index f4fafe0ce5c..7ac683a5d4d 100644 --- a/src/cron/isolated-agent/delivery-target.ts +++ b/src/cron/isolated-agent/delivery-target.ts @@ -178,34 +178,6 @@ export async function resolveDeliveryTarget( }; } - if (options?.dryRun) { - const { getLoadedChannelPluginForRead } = await loadDeliveryTargetRuntime(); - const defaultTo = getLoadedChannelPluginForRead(channel)?.config.resolveDefaultTo?.({ - cfg, - accountId, - }); - const previewTo = toCandidate ?? defaultTo; - if (!previewTo) { - return { - ok: false, - channel, - to: undefined, - accountId, - threadId, - mode, - error: new Error("Target is required for delivery preview."), - }; - } - return { - ok: true, - channel, - to: previewTo, - accountId, - threadId, - mode, - }; - } - let effectiveAllowFrom: string[] | undefined; if (mode === "implicit") { const { @@ -264,6 +236,16 @@ export async function resolveDeliveryTarget( error: docked.error, }; } + if (options?.dryRun) { + return { + ok: true, + channel, + to: docked.to, + accountId, + threadId, + mode, + }; + } const idLikeTarget = await maybeResolveIdLikeTarget({ cfg, channel,