test(frontend): guard unit tests against real network calls - #411
Merged
Conversation
Nothing in tests/setup.ts blocked fetch or XMLHttpRequest, so a request that slipped past a mock could reach the real network instead of failing the test that made it, and whatever landed late surfaced as noise in a random other test (issue #267). Replace both with a stub that throws immediately, naming the current test and the request URL. A test that intentionally needs a real network call opts in via allowNetworkInThisTest(), re-armed every afterEach. Ran the full 235-file suite three times with the guard in place; all pass, so the guard finds no existing leaks.
haksungjang
force-pushed
the
fix-267-frontend-test-network-guard
branch
from
September 6, 2026 15:57
5ca445f to
2f2ab2d
Compare
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.
Summary
Issue #267 reported the frontend unit suite flaking under CI load with a
different test failing each time, and neither failure reproduced locally.
tests/setup.tsnever blockedfetchorXMLHttpRequest, so a request thatslipped past a mock could reach the real network (or hang on a host that
doesn't exist in CI) instead of failing the test that made the call — the
resulting error then surfaced later, in whatever test happened to be running
at the time.
This adds a network guard to
tests/setup.ts:fetchandXMLHttpRequestare both replaced with a stub that throws immediately, naming the current
test (via
expect.getState().currentTestName) and the request URL. A testthat intentionally needs the real implementation opts in with
allowNetworkInThisTest(), which the guard re-arms on everyafterEachsothe opt-out can't leak into the next test.
Ran the full 235-file / 2624-test suite three times with the guard active;
all green every time. That means the guard did its job at making leaks
attributable, but found none currently in the suite — every test file is
already mocking its network calls correctly. That explains and closes the
fetch/AggregateErrorsymptom from the original report (it's now astructurally impossible failure mode). The
data-testid="policy-exception-row"symptom from the same report is a different root cause (looks like Radix
portal/focus-trap timing or worker-level resource contention, not a network
leak) and is left out of scope for this PR; noted on the issue.
Verification
node node_modules/vitest/vitest.mjs run(Node 20, full suite): 235/235files, 2624/2624 tests green, run three times back to back.
fetch(...)andopening
new XMLHttpRequest().open(...)inside a scratch test: the thrownerror contained both the offending URL and the full current test name, e.g.
Unmocked fetch call to "http://example.com/probe-2" during test "network guard temp probe > captures the test name and url in the thrown error".The scratch test file was removed before this commit.
tsc -b --noEmit: clean.eslint tests/setup.ts: clean.node scripts/i18n-check.cjs: OK (pre-existing dynamic-key warnings only,unrelated to this change).
node tools/em-dash/lint.mjs: OK.Closes #267