fix(cron): avoid false legacy payload kind migrations
This commit is contained in:
@@ -75,4 +75,25 @@ describe("normalizeStoredCronJobs", () => {
|
|||||||
channel: "slack",
|
channel: "slack",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not report legacyPayloadKind for already-normalized payload kinds", () => {
|
||||||
|
const jobs = [
|
||||||
|
{
|
||||||
|
id: "normalized-agent-turn",
|
||||||
|
name: "normalized",
|
||||||
|
enabled: true,
|
||||||
|
wakeMode: "now",
|
||||||
|
schedule: { kind: "every", everyMs: 60_000, anchorMs: 1 },
|
||||||
|
payload: { kind: "agentTurn", message: "ping" },
|
||||||
|
sessionTarget: "isolated",
|
||||||
|
delivery: { mode: "announce" },
|
||||||
|
state: {},
|
||||||
|
},
|
||||||
|
] as Array<Record<string, unknown>>;
|
||||||
|
|
||||||
|
const result = normalizeStoredCronJobs(jobs);
|
||||||
|
|
||||||
|
expect(result.mutated).toBe(false);
|
||||||
|
expect(result.issues.legacyPayloadKind).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,14 +28,21 @@ function incrementIssue(issues: CronStoreIssues, key: CronStoreIssueKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function normalizePayloadKind(payload: Record<string, unknown>) {
|
function normalizePayloadKind(payload: Record<string, unknown>) {
|
||||||
const raw = typeof payload.kind === "string" ? payload.kind.trim().toLowerCase() : "";
|
const original = typeof payload.kind === "string" ? payload.kind.trim() : "";
|
||||||
if (raw === "agentturn") {
|
const lowered = original.toLowerCase();
|
||||||
payload.kind = "agentTurn";
|
if (lowered === "agentturn") {
|
||||||
return true;
|
if (original !== "agentTurn") {
|
||||||
|
payload.kind = "agentTurn";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (raw === "systemevent") {
|
if (lowered === "systemevent") {
|
||||||
payload.kind = "systemEvent";
|
if (original !== "systemEvent") {
|
||||||
return true;
|
payload.kind = "systemEvent";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user