fix(cicd): freeze Date constructor in qa-stuck-check smoke tests - #37169
Conversation
The QA Stuck Check PR-validate job was failing on #37150 with assert.ok(!byTeam['Team : Maintenance']) This is a pre-existing time bomb on main, not a regression from this PR. This PR only surfaced it: the validate workflow triggers on changes to .claude/triage-config.json, which the dead-code removal touches, and that workflow rarely runs otherwise. Root cause: the test pinned the clock with Date.now = () => FIXED_NOW; // Monday 2026-05-25 but find-stuck-issues.js:73 reads the clock as `new Date()`, which does not consult Date.now(). So the fixtures were frozen at 2026-05-25 while the script compared them against the real clock. Once the real date drifted past FIXED_NOW, every fixture aged past STUCK_DAYS: the "Too fresh" item (1 day old, Team : Maintenance) was measured at 66 business days, so it was reported as stuck and the negative assertion failed. The suite passed only while real time stayed within ~3 business days of FIXED_NOW, so it has been broken since roughly late May 2026. Fix: freeze the whole Date constructor, not just Date.now(), so the pin the test already intended actually applies to the script under test. No production code changes — find-stuck-issues.js is untouched. Also derives the temp-config filename from the real clock plus pid, since a frozen Date.now() would otherwise make that name a constant. All 12 scenarios pass, and the result no longer depends on the date the suite is run. Refs: #36950 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
❌ Issue Linking RequiredThis PR could not be linked to an issue. All PRs must be linked to an issue for tracking purposes. How to fix this:Option 1: Add keyword to PR body (Recommended - auto-removes this comment)
Option 2: Link via GitHub UI (Note: won't clear the failed check)
Why is this required?Issue linking ensures proper tracking, documentation, and helps maintain project history. It connects your code changes to the problem they solve. |
|
Claude finished @nicobytes's task in 1m 4s —— View job Review: freeze Date constructor in qa-stuck-check smoke tests
I traced the
New IssuesNo issues found. Minor nits (non-blocking, no change required):
I was unable to execute Test-only change (+17/−2), no production code touched. Looks good to merge. |
There was a problem hiding this comment.
Pull request overview
This PR stabilizes the .github/scripts/qa-stuck-check smoke tests by properly freezing time so the tests remain deterministic regardless of the real execution date, addressing a latent failure in the “QA Stuck Check — PR validate” job.
Changes:
- Replaces a
Date.now-only stub with aglobal.Dateconstructor override sonew Date()infind-stuck-issues.jsis actually pinned to the intended fixed timestamp. - Updates the temporary triage-config filename generation to use the real clock (
RealDate.now()) plusprocess.pidto avoid collisions under a frozen clock.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Problem
The QA Stuck Check — PR validate job fails on
mainwith:This is a pre-existing time bomb, not a regression from any particular PR. It reproduces on a clean checkout of
main:git checkout main node .github/scripts/qa-stuck-check/test-find-stuck-issues.js # fails todayIt went unnoticed because the validate workflow only runs on PRs touching
.github/scripts/qa-stuck-check/**, its two workflow files, or.claude/triage-config.json— which is rare. It surfaced on #37150, which edits.claude/triage-config.json.Root cause
The test pins the clock:
But
find-stuck-issues.js:73reads the clock as:new Date()does not consultDate.now()— it reads the system clock directly. So the stub never reached the code under test: fixtures were frozen at 2026-05-25 while the script compared them against the real clock.Once the real date drifted past
FIXED_NOW, every fixture aged pastSTUCK_DAYS=3. The fixture deliberately labelled "Too fresh" — 1 day old,Team : Maintenance, which must not be reported — was measured at 66 business days stuck:so it was grouped as stuck and the negative assertion blew up. The suite passed only while real time stayed within ~3 business days of
FIXED_NOW, i.e. it has been failing since roughly late May 2026.Fix
Freeze the whole
Dateconstructor, not justDate.now(), so the pin the test already intended actually applies to the script under test:new Date(someString)andnew Date(someNumber)still pass through to the real constructor, sonew Date(item.updatedAt)(line 99) andnew Date(d)(line 175) keep working; only the zero-arg form is pinned.Also derives the temp-config filename from the real clock plus
process.pid, since a frozenDate.now()would otherwise make that name a constant:No production code changes —
find-stuck-issues.jsis untouched. Test file only, +17/−2.Verification
All 12 scenarios pass, and the result no longer depends on the date the suite is run:
Note on the scheduled run
Only the smoke tests were affected. The Mon/Thu scheduled job (
cicd_scheduled_qa-stuck-check.yml) runs against real project data with a real clock, so its behaviour was always correct — this bug was confined to the test harness.Unblocks #37150.
🤖 Generated with Claude Code