Repository navigation
Stop the auth-redirect suite failing on machine load - #1739
Merged
Merged
Conversation
Every test in this suite re-imports ./client after resetModules, and the first import in the file is the one that transforms client.ts and its whole dependency graph. That cost landed inside whichever test ran first: 13.4s against a 5s timeout on a contended machine, while the other five finished in under half a second each. The result was a suite that failed on machine load rather than on behaviour, naming a file the offending PR had not touched. A beforeAll import pays it once. resetModules drops module instances but keeps the transform cache, so each test still gets the fresh redirect gate it needs while the re-import stays cheap. Measured on the same loaded machine: first test 13433ms -> 292ms, slowest test now 347ms under deliberate CPU contention that previously failed the suite outright. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0125QDX24TNuod7FKLwTDhvW
PR Summary by QodoPrewarm client module transforms outside auth-redirect tests
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding |
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.
Closes #1735.
src/api/client.authRedirect.test.tsfailed intermittently withTest timed out in 5000ms, on a file that unrelated PRs had not touched — so whoever hit it lost time deciding whether they had broken something.The cause
It is not a race, and it is not evenly spread. Every test re-imports
./clientaftervi.resetModules(), and the first import in the file is the one that transformsclient.tsand everything it pulls in. That one-time cost was charged to whichever test happened to run first.Measured on a loaded machine with the timeout lifted, so the real durations show:
One test needed 13.4s against a 5s budget; the other five were never close to it.
resetModules()clears module instances but Vite's transform cache survives, which is why only the first import is expensive.The fix
A
beforeAllthat imports./clientonce, so the transform is paid outside any test's budget. Each test still gets the fresh redirect gate it needs —resetModules()keeps working exactly as before, and the per-test re-import is cheap because the transform cache is warm.The load in that last row is the same contention that previously failed the suite deterministically; it now passes with roughly 14× headroom against the unchanged 5s timeout.
Deliberately not done: raising
testTimeout. That would have hidden the asymmetry and weakened every test's ability to fail fast on a genuine hang, when only the module warm-up was ever slow.Verification
npm test— 1147 passed (99 files), a fully green full-suite run.eslintclean.This file uses single quotes and no semicolons, unlike the repo default; it is already that way on
mainand prettier is not gated in CI, so the change matches the file's local style rather than reformatting 194 unrelated lines.🤖 Generated with Claude Code
https://claude.ai/code/session_0125QDX24TNuod7FKLwTDhvW
Note
Low Risk
Test-only change; no production code or runtime behavior is modified.
Overview
Fixes intermittent 5s timeouts in
client.authRedirect.test.tsby warming the Vite transform cache before any test runs.Adds a
beforeAll(120s budget) thatimport('./client')once, so the expensive first transform ofclient.tsand its dependency graph is not charged to whichever test runs first aftervi.resetModules(). Per-test behavior is unchanged:resetModules()still clears module instances for a fresh redirect gate, and each test’s re-import stays cheap because the transform cache remains warm.Also extends the Vitest import list with
beforeAll.Reviewed by Cursor Bugbot for commit d3edfcc. Bugbot is set up for automated code reviews on this repo. Configure here.