mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:10:44 +00:00
fix(cron): align dry-run delivery previews with target policy
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user