From 58b1d7643ed483bd122ae07717e2e5eddef104e7 Mon Sep 17 00:00:00 2001 From: Vignesh Natarajan Date: Sat, 14 Feb 2026 19:46:11 -0800 Subject: [PATCH] test (heartbeat/cron): cover interval wake handling for tagged cron events --- .../heartbeat-runner.ghost-reminder.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/infra/heartbeat-runner.ghost-reminder.test.ts b/src/infra/heartbeat-runner.ghost-reminder.test.ts index 76bcaf22fe4..85467ae5889 100644 --- a/src/infra/heartbeat-runner.ghost-reminder.test.ts +++ b/src/infra/heartbeat-runner.ghost-reminder.test.ts @@ -181,4 +181,43 @@ describe("Ghost reminder bug (issue #13317)", () => { await fs.rm(tmpDir, { recursive: true, force: true }); } }); + + it("uses CRON_EVENT_PROMPT for tagged cron events on interval wake", async () => { + const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-cron-interval-")); + const sendTelegram = vi.fn().mockResolvedValue({ + messageId: "m1", + chatId: "155462274", + }); + const getReplySpy = vi + .spyOn(replyModule, "getReplyFromConfig") + .mockResolvedValue({ text: "Relay this cron update now" }); + + try { + const { cfg, sessionKey } = await createConfig(tmpDir); + enqueueSystemEvent("Cron: QMD maintenance completed", { + sessionKey, + contextKey: "cron:qmd-maintenance", + }); + + const result = await runHeartbeatOnce({ + cfg, + agentId: "main", + reason: "interval", + deps: { + sendTelegram, + }, + }); + + expect(result.status).toBe("ran"); + expect(getReplySpy).toHaveBeenCalledTimes(1); + const calledCtx = getReplySpy.mock.calls[0]?.[0]; + expect(calledCtx?.Provider).toBe("cron-event"); + expect(calledCtx?.Body).toContain("scheduled reminder has been triggered"); + expect(calledCtx?.Body).toContain("Cron: QMD maintenance completed"); + expect(calledCtx?.Body).not.toContain("Read HEARTBEAT.md"); + expect(sendTelegram).toHaveBeenCalled(); + } finally { + await fs.rm(tmpDir, { recursive: true, force: true }); + } + }); });