diff --git a/src/cron/service.runs-one-shot-main-job-disables-it.test.ts b/src/cron/service.runs-one-shot-main-job-disables-it.test.ts index 90f6dde5e..f9aa49c89 100644 --- a/src/cron/service.runs-one-shot-main-job-disables-it.test.ts +++ b/src/cron/service.runs-one-shot-main-job-disables-it.test.ts @@ -57,6 +57,34 @@ function createCronEventHarness() { } describe("CronService", () => { + async function loadLegacyJobFromStore(rawJob: Record) { + const store = await makeStorePath(); + const enqueueSystemEvent = vi.fn(); + const requestHeartbeatNow = vi.fn(); + + 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); + + return { cron, store, enqueueSystemEvent, requestHeartbeatNow, job }; + } + it("runs a one-shot main job and disables it after success when requested", async () => { const store = await makeStorePath(); const enqueueSystemEvent = vi.fn(); @@ -409,10 +437,6 @@ describe("CronService", () => { }); it("migrates legacy payload.provider to payload.channel on load", async () => { - const store = await makeStorePath(); - const enqueueSystemEvent = vi.fn(); - const requestHeartbeatNow = vi.fn(); - const rawJob = { id: "legacy-1", name: "legacy", @@ -432,25 +456,7 @@ describe("CronService", () => { 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 { cron, store, job } = await loadLegacyJobFromStore(rawJob); // Legacy delivery fields are migrated to the top-level delivery object const delivery = job?.delivery as unknown as Record; expect(delivery?.channel).toBe("telegram"); @@ -463,10 +469,6 @@ describe("CronService", () => { }); it("canonicalizes payload.channel casing on load", async () => { - const store = await makeStorePath(); - const enqueueSystemEvent = vi.fn(); - const requestHeartbeatNow = vi.fn(); - const rawJob = { id: "legacy-2", name: "legacy", @@ -486,25 +488,7 @@ describe("CronService", () => { 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 { cron, store, job } = await loadLegacyJobFromStore(rawJob); // Legacy delivery fields are migrated to the top-level delivery object const delivery = job?.delivery as unknown as Record; expect(delivery?.channel).toBe("telegram");