Skip to content

Stop the auth-redirect suite failing on machine load - #1739

Merged
nadaverell merged 1 commit into
mainfrom
fix/authredirect-test-timeout
Sep 13, 2026
Merged

nadaverell merged 1 commit into
mainfrom
fix/authredirect-test-timeout

Conversation

@nadaverell

@nadaverell nadaverell commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1735.

src/api/client.authRedirect.test.ts failed intermittently with Test 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 ./client after vi.resetModules(), and the first import in the file is the one that transforms client.ts and 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:

test before
1 — burst of concurrent 401s 13,433 ms
2–6 396 / 491 / 396 / 489 / 534 ms

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 beforeAll that imports ./client once, 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.

first test slowest test
before 13,433 ms 13,433 ms
after 292 ms 292 ms
after, under 8 busy-loop processes 347 ms 347 ms

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.
  • Reproduced the original failure under CPU load before the change, and confirmed it passes under the same load after.
  • eslint clean.

This file uses single quotes and no semicolons, unlike the repo default; it is already that way on main and 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.ts by warming the Vite transform cache before any test runs.

Adds a beforeAll (120s budget) that import('./client') once, so the expensive first transform of client.ts and its dependency graph is not charged to whichever test runs first after vi.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.

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
@nadaverell
nadaverell requested a review from hisco as a code owner September 13, 2026 12:21
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Prewarm client module transforms outside auth-redirect tests

🐞 Bug fix 🧪 Tests 🕐 Less than 5 minutes

Grey Divider

AI Description

• Prewarms the API client transform cache before auth-redirect tests execute.
• Preserves per-test module isolation while preventing load-dependent timeout failures.
Diagram

sequenceDiagram
    participant Suite as Test Suite
    participant Vite as Vite Cache
    participant Client as API Client
    Suite->>Vite: beforeAll import
    Vite->>Client: transform graph
    Client-->>Vite: cache transform
    loop Each test
        Suite->>Suite: reset modules
        Suite->>Vite: re-import client
        Vite-->>Suite: cached transform
    end
Loading
High-Level Assessment

The chosen prewarm is appropriate because it removes one-time transform work from individual test budgets without weakening the global timeout or sacrificing fresh module state. Raising the timeout was correctly dismissed because it would mask hangs and apply broadly rather than addressing the asymmetric setup cost.

Files changed (1) +12 / -1

Bug fix (1) +12 / -1
client.authRedirect.test.tsPrewarm API client transforms before timed tests +12/-1

Prewarm API client transforms before timed tests

• Imports the client once in a suite-level 'beforeAll' with a dedicated warm-up timeout. Per-test 'resetModules()' and re-imports remain unchanged, preserving fresh redirect state while reusing Vite's transform cache.

web/src/api/client.authRedirect.test.ts

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@nadaverell
nadaverell merged commit 63b6313 into main Sep 13, 2026
9 checks passed
@nadaverell
nadaverell deleted the fix/authredirect-test-timeout branch September 13, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

client.authRedirect.test.ts runs at a 20% margin under the default 5s timeout

1 participant