test: drive coverage-flaky timing tests by timer order and events

Merged
AI
3d ago
+115-45

Summary

Three tests raced real time under the Coverage job's parallelism. Each now waits on timer order or an event. No timeout was widened and nothing retries. Test-only, 5 files.

  • Snapshot-source lifecycle. Fake timers advance whenever the loop idles, and the fixture's filesystem calls are in memory.
  • Remote materialization timeout. Only the download timeout is faked. The test waits for staging (or settlement, or Vitest's t.signal abort), then advances 80 ms.
  • Artifact tracking. Ten 1 s vi.waitFor polls now await close, abort, a held-read count, or the expected rmSync. Timers are selected by delay within the scheduling call, not by global index.

Fixes #4321.

Validation

Tested bc5da7c53 (on 093341a60). pnpm check:affected --run --head bc5da7c53: 8 passed, 8 skipped. The first gate run had one worker SIGABRT in the unrelated src/platform-runtime-gateway.test.ts with no failed assertion; that file passed 5/5 alone and the rerun passed.

Local stress with coverage at bc5da7c53, 64 runs each (not CI's configuration):

TestBaseHead
lifecycle (32-way)4 failed0
materialization timeout test (32-way)37 failed0
materialization, whole file (8-way)—0
artifact-tracking (32-way)00

At 32-way the file's untouched first test times out on base too, hence 8-way for the whole file. Artifact-tracking never failed locally, so that change removes the wall-clock bounds rather than a reproduced flake.

šŸ¤– Generated with Claude Code