Flaky SPA test: LibrariesScreen "stops scan polling and refreshes sources once when scans complete" #447

Closed
opened 2026-07-18 15:56:10 +02:00 by timothy · 2 comments
Owner

Symptom

The vitest test web/src/screens/LibrariesScreen.test.tsx > LibrariesScreen > stops scan polling and refreshes sources once when scans complete (line ~258) flakes in the Build & test (.NET) CI job's Test SPA step.

::error ... LibrariesScreen.test.tsx:258:43::Error: expect(element).not.toBeInTheDocument()
expected document not to contain element, found <span class="ctv-progress-label">75 %</span> instead

Evidence it's a flake (not a real regression)

  • Failed on CI run for PR #443 head 8a85f9dd (run 1081) — a diff that touches only scripts/*.sh, docs/*.md, .gitea/workflows/*.yml (zero web/ files), so it cannot have caused a web-test change.
  • Passed on the very next run (PR #443 head 4345180a, an unrelated change) — the same web/ code, green.
  • main was green across this window.

So the test is non-deterministic: it intermittently still sees the ctv-progress-label ("75 %") in the DOM when it expects the scan-progress UI to have cleared after scans complete — a fake-timer / polling race in the test (the scan-status poll → progress-label teardown timing), the same class as the mount-debounce/timer flakes noted in prior sessions.

Fix direction (not yet investigated)

Make the assertion wait for the teardown deterministically — e.g. await waitFor(() => expect(...).not.toBeInTheDocument()), advance/flush fake timers explicitly before asserting, or await the poll-stop effect — rather than asserting synchronously right after triggering scan-complete. Reproduce locally by running the single test in a tight loop (vitest run -t "stops scan polling" ×N) to catch the intermittent failure before fixing.

Impact

Advisory-ish but real: this red blocks the Build & test (.NET) gate (a required check) intermittently, so it can block unrelated PRs' merges until a re-run. Low priority but worth de-flaking.

Done-when

  • Root-caused (which timer/effect leaves the progress label mounted)
  • Test made deterministic (loops green locally ×N)
  • Adversarial review passed
## Symptom The vitest test `web/src/screens/LibrariesScreen.test.tsx > LibrariesScreen > stops scan polling and refreshes sources once when scans complete` (line ~258) **flakes** in the `Build & test (.NET)` CI job's *Test SPA* step. ``` ::error ... LibrariesScreen.test.tsx:258:43::Error: expect(element).not.toBeInTheDocument() expected document not to contain element, found <span class="ctv-progress-label">75 %</span> instead ``` ## Evidence it's a flake (not a real regression) - **Failed** on CI run for PR #443 head `8a85f9dd` (run 1081) — a diff that touches **only** `scripts/*.sh`, `docs/*.md`, `.gitea/workflows/*.yml` (zero `web/` files), so it cannot have caused a web-test change. - **Passed** on the very next run (PR #443 head `4345180a`, an unrelated change) — the same `web/` code, green. - `main` was green across this window. So the test is non-deterministic: it intermittently still sees the `ctv-progress-label` ("75 %") in the DOM when it expects the scan-progress UI to have cleared after scans complete — a **fake-timer / polling race** in the test (the scan-status poll → progress-label teardown timing), the same class as the mount-debounce/timer flakes noted in prior sessions. ## Fix direction (not yet investigated) Make the assertion wait for the teardown deterministically — e.g. `await waitFor(() => expect(...).not.toBeInTheDocument())`, advance/flush fake timers explicitly before asserting, or await the poll-stop effect — rather than asserting synchronously right after triggering scan-complete. Reproduce locally by running the single test in a tight loop (`vitest run -t "stops scan polling"` ×N) to catch the intermittent failure before fixing. ## Impact Advisory-ish but real: this red blocks the `Build & test (.NET)` gate (a **required** check) intermittently, so it can block unrelated PRs' merges until a re-run. Low priority but worth de-flaking. ## Done-when - [ ] Root-caused (which timer/effect leaves the progress label mounted) - [ ] Test made deterministic (loops green locally ×N) - [ ] Adversarial review passed
timothy added the bugci-cdpriority: lowfrontend labels 2026-07-18 15:56:10 +02:00
timothy added the in-progress label 2026-07-18 16:30:47 +02:00
Author
Owner

🤖 Claiming as part of a batched small-issue sweep this session (parallel worktrees, one PR per item). Will post a close comment per the Task Completion Protocol when its PR merges.

🤖 Claiming as part of a batched small-issue sweep this session (parallel worktrees, one PR per item). Will post a close comment per the Task Completion Protocol when its PR merges.
Author
Owner

✅ Merged via PR #451 (squash, bundled with #409). Root cause: the test asserted synchronously right after a fire-and-forget interval handler (loadScanStatuses returns void while its promise chain settles later), racing the state update + refetch. Done: wrapped the post-tick assertions in waitFor (no weakening of what they assert). Files: web/src/screens/LibrariesScreen.test.tsx. 20/20 green in a repeat loop. Pure-SPA/test leaf.

✅ Merged via PR #451 (squash, bundled with #409). **Root cause:** the test asserted synchronously right after a fire-and-forget interval handler (`loadScanStatuses` returns void while its promise chain settles later), racing the state update + refetch. **Done:** wrapped the post-tick assertions in `waitFor` (no weakening of what they assert). **Files:** `web/src/screens/LibrariesScreen.test.tsx`. 20/20 green in a repeat loop. Pure-SPA/test leaf.
timothy removed the in-progress label 2026-07-18 18:22:19 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#447