fix(cron): avoid false legacy payload kind migrations

This commit is contained in:
shuicici
2026-03-12 20:06:29 +08:00
committed by Ayaan Zaidi
parent 21fa50f564
commit 3e2c776aaf
2 changed files with 35 additions and 7 deletions

View File

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

View File

@@ -28,17 +28,24 @@ 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();
if (lowered === "agentturn") {
if (original !== "agentTurn") {
payload.kind = "agentTurn"; payload.kind = "agentTurn";
return true; return true;
} }
if (raw === "systemevent") { return false;
}
if (lowered === "systemevent") {
if (original !== "systemEvent") {
payload.kind = "systemEvent"; payload.kind = "systemEvent";
return true; return true;
} }
return false; return false;
} }
return false;
}
function inferPayloadIfMissing(raw: Record<string, unknown>) { function inferPayloadIfMissing(raw: Record<string, unknown>) {
const message = typeof raw.message === "string" ? raw.message.trim() : ""; const message = typeof raw.message === "string" ? raw.message.trim() : "";