From 163080b60998b12ec9d1924c5aa36dcade2ed624 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 13 Dec 2025 03:43:55 +0000 Subject: [PATCH] test(cron): cover disabled scheduler --- src/cron/service.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/cron/service.test.ts b/src/cron/service.test.ts index 368b4dc25..6b5a8d9e5 100644 --- a/src/cron/service.test.ts +++ b/src/cron/service.test.ts @@ -117,4 +117,43 @@ describe("CronService", () => { cron.stop(); await store.cleanup(); }); + + it("does not schedule timers when cron is disabled", async () => { + const store = await makeStorePath(); + const enqueueSystemEvent = vi.fn(); + const requestReplyHeartbeatNow = vi.fn(); + + const cron = new CronService({ + storePath: store.storePath, + cronEnabled: false, + log: noopLogger, + enqueueSystemEvent, + requestReplyHeartbeatNow, + runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" })), + }); + + await cron.start(); + const atMs = Date.parse("2025-12-13T00:00:01.000Z"); + await cron.add({ + enabled: true, + schedule: { kind: "at", atMs }, + sessionTarget: "main", + wakeMode: "now", + payload: { kind: "systemEvent", text: "hello" }, + }); + + const status = await cron.status(); + expect(status.enabled).toBe(false); + expect(status.nextWakeAtMs).toBeNull(); + + vi.setSystemTime(new Date("2025-12-13T00:00:01.000Z")); + await vi.runOnlyPendingTimersAsync(); + + expect(enqueueSystemEvent).not.toHaveBeenCalled(); + expect(requestReplyHeartbeatNow).not.toHaveBeenCalled(); + expect(noopLogger.warn).toHaveBeenCalled(); + + cron.stop(); + await store.cleanup(); + }); });