Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(test): make cron catch-up tests timezone-independent

[._.]/ Adam Eivyf33fbe3a28dc
diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.js
index 20928ca01a..c28628a802 100644
--- a/server/services/taskSchedule.test.js
+++ b/server/services/taskSchedule.test.js
@@ -486,12 +486,24 @@ describe('taskSchedule', () => {
})
describe('cron catch-up', () => {
+ // Resolve "the most recent 9 AM in the past, local time." Bare
+ // `setHours(9, 0, 0, 0)` flakes in CI when the runner's wall-clock is
+ // before 9 AM local (UTC CI fires at ~04:00 UTC daily) — today's 9 AM
+ // would be in the future and shouldRunTask's `prevRunMs <= now` guard
+ // correctly rejects a slot that hasn't happened yet, breaking these
+ // tests' premise. Subtract a day when needed.
+ const recentNineAm = () => {
+ const d = new Date()
+ d.setHours(9, 0, 0, 0)
+ if (d.getTime() > Date.now()) d.setDate(d.getDate() - 1)
+ return d
+ }
+
it('catches up a never-run cron when the most-recent slot is within one period', async () => {
- // Cron: 0 9 * * * (daily 9 AM). It's now 10:30 AM — today's 9 AM slot already elapsed.
- // First call (from=now): most-recent past 9 AM is today.
- // Second call (from=prev-60s): one occurrence earlier = yesterday's 9 AM (the lookback bound).
- const todayNineAm = new Date()
- todayNineAm.setHours(9, 0, 0, 0)
+ // Cron: 0 9 * * * (daily 9 AM). The most recent past 9 AM already elapsed.
+ // First call (from=now): most-recent past 9 AM.
+ // Second call (from=prev-60s): one occurrence earlier (the lookback bound).
+ const todayNineAm = recentNineAm()
const yesterdayNineAm = new Date(todayNineAm.getTime() - 24 * 60 * 60 * 1000)
parseCronToPrevRun
@@ -512,10 +524,9 @@ describe('taskSchedule', () => {
})
it('catches up after the recorded lastRun even if the daemon missed the slot', async () => {
- // Cron fired yesterday, then daemon was down across today's 9 AM. Now it's 11 AM.
+ // Cron fired yesterday, then daemon was down across today's 9 AM.
// Catch-up bound is the recorded lastRun (yesterday), so today's 9 AM counts as missed.
- const todayNineAm = new Date()
- todayNineAm.setHours(9, 0, 0, 0)
+ const todayNineAm = recentNineAm()
const yesterdayNineAm = new Date(todayNineAm.getTime() - 24 * 60 * 60 * 1000)
parseCronToPrevRun.mockReturnValueOnce(todayNineAm)
@@ -536,10 +547,9 @@ describe('taskSchedule', () => {
})
it('does NOT catch up when lastRun already covers the most-recent slot', async () => {
- // Cron fired this morning at 9 AM; it's now 10 AM. lastRun is at the same 9 AM.
+ // Cron fired this morning at 9 AM; lastRun is at the same 9 AM.
// prevRun == lastRun → not strictly greater → no catch-up.
- const todayNineAm = new Date()
- todayNineAm.setHours(9, 0, 0, 0)
+ const todayNineAm = recentNineAm()
const tomorrowNineAm = new Date(todayNineAm.getTime() + 24 * 60 * 60 * 1000)
parseCronToPrevRun.mockReturnValueOnce(todayNineAm)