fix: migrate cron payload channel alias

This commit is contained in:
Peter Steinberger
2026-01-09 22:40:51 +01:00
parent bdee50da6b
commit 22b3bd4415
4 changed files with 110 additions and 0 deletions

View File

@@ -118,6 +118,57 @@ describe("CronService", () => {
await store.cleanup();
});
it("migrates legacy payload.channel to payload.provider on load", async () => {
const store = await makeStorePath();
const enqueueSystemEvent = vi.fn();
const requestHeartbeatNow = vi.fn();
const rawJob = {
id: "legacy-1",
name: "legacy",
enabled: true,
createdAtMs: Date.now(),
updatedAtMs: Date.now(),
schedule: { kind: "cron", expr: "* * * * *" },
sessionTarget: "isolated",
wakeMode: "now",
payload: {
kind: "agentTurn",
message: "hi",
deliver: true,
channel: "telegram",
to: "7200373102",
},
state: {},
};
await fs.mkdir(path.dirname(store.storePath), { recursive: true });
await fs.writeFile(
store.storePath,
JSON.stringify({ version: 1, jobs: [rawJob] }, null, 2),
"utf-8",
);
const cron = new CronService({
storePath: store.storePath,
cronEnabled: true,
log: noopLogger,
enqueueSystemEvent,
requestHeartbeatNow,
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })),
});
await cron.start();
const jobs = await cron.list({ includeDisabled: true });
const job = jobs.find((j) => j.id === rawJob.id);
const payload = job?.payload as unknown as Record<string, unknown>;
expect(payload.provider).toBe("telegram");
expect("channel" in payload).toBe(false);
cron.stop();
await store.cleanup();
});
it("posts last output to main even when isolated job errors", async () => {
const store = await makeStorePath();
const enqueueSystemEvent = vi.fn();