Skip to content

test(workspace): pin the clock in sessions-panel date-bucket test - #498

Draft
albertoperdomo2 wants to merge 3 commits into
mainfrom
fix/sessions-panel-date-bucket-flake
Draft

albertoperdomo2 wants to merge 3 commits into
mainfrom
fix/sessions-panel-date-bucket-flake

Conversation

@albertoperdomo2

Copy link
Copy Markdown
Contributor

Summary

Unblocks #497: the Verify Web Coverage Badges check currently fails on main (and therefore on any PR branch) because sessions-panel.test.tsx > groups sessions by date buckets is calendar-dependent — no code change involved.

Root cause: the test's "Older" fixture is Date.now() - 30 days, but groupByDateBucket (src/lib/date-buckets.ts) has a "This month" tier. Whenever now − 30d is still inside the current calendar month, the fixture groups as "This month" and the Older header never renders. That happens on the 31st of every month — which is why the suite passed on Aug 30 and failed on Aug 31 (today) in CI with an identical tree.

Fix: pin the clock in that one test (vi.useFakeTimers() + vi.setSystemTime(2026-06-17T12:00:00Z), real timers restored in finally) so Today / Yesterday / Older are deterministic on any date and in any timezone. Chose a mid-month instant so the 30-day fixture always lands in the previous month.

OpenSpec

deterministic-session-date-buckets change doc included with skip_specs: true — test-only, no behavior changes (openspec/changes/deterministic-session-date-buckets/).

Test plan

  • Fails on today's date before the fix, passes after
  • Passes under TZ=UTC, TZ=Pacific/Kiritimati (UTC+14), TZ=America/New_York
  • Full sessions-panel + lib test files green (488 passed, 0 failed)

Merge order

Merge this first, then rebase/merge #497 — its coverage-badge check is red only because of this shared-main test.

The 'groups sessions by date buckets' test used Date.now() - 30 days as
its 'Older' fixture, but groupByDateBucket has a 'This month' tier: on
month-boundary days (every 31st), now - 30d is still inside the current
calendar month and buckets as 'This month', so the 'Older' header never
renders and the test fails. It broke CI on 2026-08-31 with no code
change.

Pin the clock to a fixed mid-month instant with fake timers so the
buckets are deterministic on any date and in any timezone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant