fix(cron): align dry-run delivery previews with target policy

This commit is contained in:
Ayaan Zaidi
2026-04-21 11:45:07 +05:30
parent ab3938df1e
commit 5579fef673
2 changed files with 33 additions and 28 deletions

View File

@@ -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",

View File

@@ -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,