Test-only fix for the flaky Libraries scan-polling family in web/src/App.test.tsx (flaked on main runs 569 and 573 today, plus once locally).
Root cause: the tests mock window.setInterval to capture the poll handler and tick it manually, but useLibrariesScreenQuery registers that interval in a passive effect gated on hasActiveScans, which flips only after an async fetch resolves outside act. findBy* resolves on the DOM mutation and can beat the passive-effect flush under CI load — so the captured-handlers array was still empty and the tick silently no-opped. That explains both CI signatures exactly (scan-status count stuck at 1; 75% label never removed).
Fix: a runPollTick() helper that (a) flushes pending effects with an empty act, (b) asserts at least one handler was captured (future regressions fail loudly instead of silently no-opping), and (c) runs the handlers inside act so all state commits land before assertions. Applied to all five tests with the manual-tick pattern; post-tick waitFors became plain synchronous expects — nothing depends on wall-clock scheduling anymore. Also tightened one test's interval mock to the ≥10s poll cadence so it doesn't capture waitFor's internal 50ms interval.
Verification: 20 full App.test.tsx runs under 6-way CPU contention — 0 failures; full suite 202/202; typecheck + eslint clean. No product code touched.
Test-only fix for the flaky Libraries scan-polling family in `web/src/App.test.tsx` (flaked on main runs 569 and 573 today, plus once locally).
**Root cause**: the tests mock `window.setInterval` to capture the poll handler and tick it manually, but `useLibrariesScreenQuery` registers that interval in a passive effect gated on `hasActiveScans`, which flips only after an async fetch resolves outside `act`. `findBy*` resolves on the DOM mutation and can beat the passive-effect flush under CI load — so the captured-handlers array was still empty and the tick silently no-opped. That explains both CI signatures exactly (scan-status count stuck at 1; `75%` label never removed).
**Fix**: a `runPollTick()` helper that (a) flushes pending effects with an empty `act`, (b) asserts at least one handler was captured (future regressions fail loudly instead of silently no-opping), and (c) runs the handlers inside `act` so all state commits land before assertions. Applied to all five tests with the manual-tick pattern; post-tick `waitFor`s became plain synchronous expects — nothing depends on wall-clock scheduling anymore. Also tightened one test's interval mock to the ≥10s poll cadence so it doesn't capture `waitFor`'s internal 50ms interval.
**Verification**: 20 full `App.test.tsx` runs under 6-way CPU contention — 0 failures; full suite 202/202; typecheck + eslint clean. No product code touched.
Fixes #157.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
The five Libraries polling tests mock window.setInterval to capture the
poll handler, but that handler is registered in a passive useEffect that
only runs after an out-of-act state commit (the async fetch that flips
hasActiveScans). findBy*/waitFor resolve on the DOM mutation via
MutationObserver, which can win the race against React's passive-effect
flush under CI load - leaving intervalHandlers empty when the test
invokes it. The forEach was then a silent no-op: no poll fetch, so
'route delta' timed out at scan-status count > 1, and 'stops polling'
never cleared the 75% label.
Fix: new runPollTick helper flushes pending effects with an empty
act(), asserts the poll handler is actually registered (turning any
future regression into a clear failure instead of a timeout), and
invokes the handlers inside act() so fetch microtasks and state updates
are fully applied before assertions run. All post-tick waitFor blocks
become plain synchronous expects - nothing depends on wall-clock
scheduling anymore. Also aligned the 'stops polling' setInterval mock
with its siblings' >=10000ms cadence filter so it captures exactly the
poll handler, not waitFor's internal 50ms interval callback.
Verified: 20x full App.test.tsx loop under CPU contention, 0 failures;
full vitest suite 202 passed; tsc + eslint clean.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
timothy
merged commit 117afa310e into main2026-07-07 16:02:32 +02:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Test-only fix for the flaky Libraries scan-polling family in
web/src/App.test.tsx(flaked on main runs 569 and 573 today, plus once locally).Root cause: the tests mock
window.setIntervalto capture the poll handler and tick it manually, butuseLibrariesScreenQueryregisters that interval in a passive effect gated onhasActiveScans, which flips only after an async fetch resolves outsideact.findBy*resolves on the DOM mutation and can beat the passive-effect flush under CI load — so the captured-handlers array was still empty and the tick silently no-opped. That explains both CI signatures exactly (scan-status count stuck at 1;75%label never removed).Fix: a
runPollTick()helper that (a) flushes pending effects with an emptyact, (b) asserts at least one handler was captured (future regressions fail loudly instead of silently no-opping), and (c) runs the handlers insideactso all state commits land before assertions. Applied to all five tests with the manual-tick pattern; post-tickwaitFors became plain synchronous expects — nothing depends on wall-clock scheduling anymore. Also tightened one test's interval mock to the ≥10s poll cadence so it doesn't capturewaitFor's internal 50ms interval.Verification: 20 full
App.test.tsxruns under 6-way CPU contention — 0 failures; full suite 202/202; typecheck + eslint clean. No product code touched.Fixes #157.
🤖 Generated with Claude Code