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

test: freeze the clock in the perpetual-PARKED scheduling case (#3693)

[._.]/ Adam Eivybed5b375ea24
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 34fb3be616..458b7aee53 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -86,3 +86,5 @@
- One malformed file in the CoS missions directory no longer takes out the whole Missions overview. `getStats()` dereferenced `mission.subTasks.length` on every record `loadMissions()` handed back, and that loader passed through anything that parsed as JSON — so a hand-edited file, a half-written record, or one written in an older shape threw a `TypeError` and blanked the page instead of costing one row. Records are now normalized at the single door they come through: `subTasks`, `goals` and `metrics` coerce to their expected shapes, `progress` to a finite number (no more `NaN%` average), and an absent status buckets under `unknown` rather than an `undefined` key. Anything that isn't a usable mission object is dropped with one `⚠️` line naming the file, so a corrupt record is visible rather than silently missing.
- Internal: the shared test helper that redirects `PATHS.data` at a temp dir now re-roots *every* `PATHS` member that lives under `data/`, not just `data` itself. 45 of the 49 members are built as `join(INSTALL_ROOT, 'data/…')` independently of `PATHS.data`, so "redirect `data` and the suite is isolated" was false for almost every disk-touching test — each one had to independently rediscover that and restate the on-disk layout by hand, and the failure mode when it didn't was #3683/#3687: green CI, writes landing in the developer's live install. The whole `data/` subtree now moves with the temp root, preserving each member's relative layout, while explicit per-suite overrides still merge last as the escape hatch for a member that genuinely wants a different target (a scratch root, `~/Downloads`, a pre-seeded fixture dir). Twenty call sites that merely restated the shipped layout are gone. Test-only change; no production code touched.
+
+- Internal: the task-schedule suite's "perpetual task parked on every app" case no longer passes or fails depending on what time of day it runs. It parked one app at the *next* 9am and another 30 minutes out, then asserted the 30-minute park was the soonest — true at 10am, false at 08:45, when 9am is only 15 minutes away. The case now freezes the clock at a fixed instant and uses two absolute park timestamps, so the comparison it makes is the one it means to make; a suite-wide `afterEach` restores real time so a failed assertion inside a frozen block can't leak fake time into later cases. Verified the case still fails when the soonest-park selection is inverted. Test-only change; no production code touched.
diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.js
index 113ec3867a..8943ed3b33 100644
--- a/server/services/taskSchedule.test.js
+++ b/server/services/taskSchedule.test.js
@@ -1,4 +1,4 @@
-import { describe, it, expect, beforeEach, vi } from 'vitest'
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
vi.mock('./cosEvents.js', () => ({
cosEvents: { emit: vi.fn() },
@@ -187,6 +187,12 @@ describe('taskSchedule', () => {
readJSONFile.mockResolvedValue(null)
})
+ // Cases that freeze the clock restore it here, so a failed assertion inside a
+ // faked-timer block can't leak fake time into every case that follows.
+ afterEach(() => {
+ vi.useRealTimers()
+ })
+
describe('INTERVAL_TYPES', () => {
it('should define all expected interval types', () => {
expect(INTERVAL_TYPES.ROTATION).toBe('rotation')
@@ -1480,8 +1486,13 @@ describe('taskSchedule', () => {
// only on the ≤1h fallback poll.
describe('getUpcomingTasks — perpetual recheck boundary', () => {
it('reports a perpetual task PARKED on every app as scheduled at the soonest recheck', async () => {
- const nineAm = recentNineAm()
- nineAm.setDate(nineAm.getDate() + 1) // next 9am (future)
+ // Clock frozen (#3693): this case compares two ABSOLUTE park timestamps,
+ // so on a real clock its verdict depended on when the suite ran — the
+ // next 9am is >30m out at 10am but only 15m out at 08:45, which flips
+ // which park is soonest and fails the assertion below.
+ vi.useFakeTimers()
+ vi.setSystemTime(new Date('2026-01-01T12:00:00Z'))
+ const nineAm = new Date('2026-01-02T09:00:00Z') // next 9am (future, well past `soon`)
const soon = new Date(Date.now() + 30 * 60 * 1000).toISOString() // 30m out
mockSchedule({
tasks: { 'claim-issue': { type: 'perpetual', enabled: true, recheckCron: '0 9 * * *' } },