diff --git a/src/cli/cron-cli/shared.test.ts b/src/cli/cron-cli/shared.test.ts index 7d75b1055806..f9fa764cfd3a 100644 --- a/src/cli/cron-cli/shared.test.ts +++ b/src/cli/cron-cli/shared.test.ts @@ -474,27 +474,59 @@ describe("printCronList", () => { ); it.each([ - { label: "disabled", enabled: false, runStatus: "ok" as const, expectedStatus: "disabled" }, - { label: "running", enabled: true, runStatus: "ok" as const, expectedStatus: "running" }, - { label: "failed", enabled: true, runStatus: "error" as const, expectedStatus: "error" }, + { + label: "disabled", + enabled: false, + running: false, + runStatus: "ok" as const, + expectedStatus: "disabled", + }, + { + label: "running", + enabled: true, + running: true, + runStatus: "ok" as const, + expectedStatus: "running", + }, + { + label: "paused but force-running", + enabled: false, + running: true, + runStatus: "ok" as const, + expectedStatus: "running", + }, + { + label: "failed", + enabled: true, + running: false, + runStatus: "error" as const, + expectedStatus: "error", + }, ])( "does not let prior non-delivery override a $label automation", - ({ enabled, runStatus, expectedStatus }) => { + ({ enabled, running, runStatus, expectedStatus }) => { const job = createBaseJob({ enabled, state: { lastRunStatus: runStatus, lastDeliveryStatus: "not-delivered", - ...(expectedStatus === "running" ? { runningAtMs: Date.now() } : {}), + ...(running ? { runningAtMs: Date.now() } : {}), }, }); + const list = createRuntimeLogCapture(); + printCronList([job], list.runtime); + expectLogsToInclude(list.logs, expectedStatus); + const show = createRuntimeLogCapture(); printCronShow(job, show.runtime); expectLogsToInclude(show.logs, `status: ${expectedStatus}`); expect(show.logs.join("\n")).not.toContain("ok (not delivered)"); expect(enrichCronJsonWithStatus(job)).toMatchObject({ status: expectedStatus }); + expect(enrichCronJsonWithStatus({ jobs: [job] })).toMatchObject({ + jobs: [{ status: expectedStatus }], + }); }, ); diff --git a/src/cli/cron-cli/shared.ts b/src/cli/cron-cli/shared.ts index 9a3dda817659..d392388d66fe 100644 --- a/src/cli/cron-cli/shared.ts +++ b/src/cli/cron-cli/shared.ts @@ -170,13 +170,13 @@ export function enrichCronJsonWithStatus(value: unknown): unknown { } function computeStatus(job: { enabled?: unknown; state?: unknown }): string { - if (!job.enabled) { - return "disabled"; - } const state = asOptionalRecord(job.state) ?? {}; if (state.runningAtMs) { return "running"; } + if (!job.enabled) { + return "disabled"; + } return typeof state.lastRunStatus === "string" ? state.lastRunStatus : typeof state.lastStatus === "string"