Repository navigation
test(scaffald): bound the two loop-guard tests instead of racing a clock - #915
Merged
Merged
Conversation
…ock (#753) `profile-view-tracking` and `results-view-xp` each keep a "the old shape really did loop" case beside the fix, so the guard above it cannot pass vacuously. Both did it by rendering the broken component, waiting a fixed 120 ms, and asserting the effect had re-entered more than 20 times. That made the result a function of how fast the machine was, and the loop is not slow. Measured locally it re-enters the effect **6,143 times in 60 ms**. Letting that run for a fixed window is enough to take the vitest worker down with it — `Error: Worker exited unexpectedly`, surfaced as `STACK_TRACE_ERROR` against whichever test happened to be in flight. That is the #753 flake. Both suites failed exactly that way tonight on unrelated PRs and passed on a plain re-run: #908 profile view tracking > the old shape really did loop #870 results view XP > the old shape really did loop They surface on dependency PRs specifically because CI runs `Test (affected)`, and a lockfile change makes every project affected — so `apps/scaffald`'s suite runs when an ordinary feature PR would not. Each one first read as a regression from the bump. ## The assertion never needed a clock Knowing the effect re-enters itself without a terminating condition is what the test is for, and 25 iterations establish that as well as six thousand. `unbounded-loop-probe.ts` counts calls, stops the loop the instant it reaches `LOOP_CAP`, and resolves. Fast machine or slow, the work is the same and nothing runs away. The two cases now finish in ~11 ms rather than 120 ms+. `shouldStop` is the *test's* bound, not a fix to the shape under test: the effect still has no terminating condition of its own, and the probe only trips it once the loop has already proved itself. ## The guard still guards A stall is now the interesting failure — it means the old shape stopped looping, so react-query changed its identity semantics and the reasoning behind the fix needs revisiting. `settled()` races the loop against a 2 s deadline so that case is a readable assertion rather than a suite timeout. Verified by mutation: replacing `Looping`'s unstable mutation object with the stable `mutate` makes it fail with AssertionError: expected 'stalled' to be 'looped' rather than passing. The 2 s is only paid when the test is about to fail. Ran the pair six times: 6/6 green each time. `scaffald-app` full suite 98 passed / 0 failed; typecheck and lint clean. Co-Authored-By: Claude Opus 5 <[email protected]>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the part of #753 I could pin down.
profile-view-trackingandresults-view-xpeach keep a "the old shape really did loop" case beside the fix, so the guard above it cannot pass vacuously. That instinct is right — a guard test that cannot fail is worth nothing. The mechanism was the problem: render the broken component, wait a fixed 120 ms, assert the effect re-entered more than 20 times.The loop is not slow
I measured it before changing anything:
6,143 iterations in 60 ms.
> 20was never the risk — the runaway was. Letting that run for a fixed wall-clock window is enough to take the vitest worker down with it, which is reported asSTACK_TRACE_ERRORagainst whichever test happened to be in flight.That is the #753 flake, and both suites hit it tonight on unrelated PRs, each passing on a plain re-run with no code change:
profile view tracking > the old shape really did loopresults view XP > the old shape really did loopTwo sightings of the same construction in one evening is not ambient flakiness.
Why dependency PRs specifically: CI runs
Test (affected), and a lockfile change makes every project affected — soapps/scaffald's suite runs when an ordinary feature PR would not. Both sightings were on dep PRs, and each initially read as a regression from the bump. That cost real time on #908 before I re-ran it.The assertion never needed a clock
Knowing the effect re-enters itself with no terminating condition is what the test is for, and 25 iterations establish that as well as six thousand.
unbounded-loop-probe.tscounts calls, stops the loop the instant it reachesLOOP_CAP, and resolves. Fast machine or slow, the work is identical and nothing runs away. The two cases went from 120 ms+ to ~11 ms.shouldStopis the test's bound, not a fix to the shape under test — the effect still has no terminating condition of its own, and the probe only trips it once the loop has already proved itself. I'd rather that be explicit than have the looping component quietly stop being a faithful reproduction.The guard still guards
This is the half worth reviewing. A stall is now the interesting failure: it means the old shape stopped looping, so react-query changed its identity semantics and the reasoning behind the fix needs revisiting.
settled()races the loop against a 2 s deadline so that case is a readable assertion rather than a suite-level timeout.Verified by mutation rather than by argument — swapped
Looping's unstable mutation object for the stablemutate, so it no longer loops:It fails, clearly, in 2010 ms. The 2 s is only paid when the test is already about to fail.
Verification
scaffald-appfull suite: 98 passed / 0 failed.scaffald-apptypecheck and lint clean;pnpm prepushgreen.Scope
#753 was filed as "two different projects failed and passed on re-run within a day, with no local reproduction." This is a concrete, reproducible cause for the
apps/scaffaldhalf, so I'd keep #753 open until another clean stretch goes by — I can't claim these two tests were the only thing behind it.🤖 Generated with Claude Code