This repository was archived by the owner on Nov 4, 2026. It is now read-only.
Repository navigation
docs(tests): make the network-escape guard's Fix: text say where the teardown goes - #7803
Merged
Merged
Conversation
…teardown goes
The guard's failure message prescribed `vi.stubGlobal('fetch', router) +
vi.unstubAllGlobals()` with no word about WHERE the unstub goes. That pair is
safe only when nothing the component started is still in flight at teardown,
and objectui#7439 is the measured counter-example: a file with exactly the
prescribed shape still escaped intermittently, because a decision carrying
`refreshAfter: true` makes the record page re-read approval state after the
test body returns and the prescribed teardown put the real `fetch` back while
that read was pending.
Vitest runs `afterEach` in reverse registration order, so a teardown written in
the test file runs before the root setup's RTL `cleanup()` and before the
guard's own assertion. The message now says so, and gives the two remedies in
order: unmount before unstubbing (which the referenced DatasetReportRenderer
`afterEach` already does, with its own measured note), and — when the component
can issue a read after the test body returns — install one double at module
scope and never tear it down, following the worked example PR #7764 landed.
The shrink-only ledger pin printed a second copy of the same prescription. It
now points at the guard's text instead of restating it: one ruling written
twice, with one copy rotting, is the defect this card is about.
No change to what the guard catches: `KNOWN_ESCAPES` and the verdict logic are
untouched, and only the thrown message's template literal moved.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KbJQ1y1J12nZxYzFWhP8Q3
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #7765
The network-escape guard's failure message is this repo's canonical instruction
for the class, and objectui#7307 is a 21-file burn-down following it. It
prescribed
vi.stubGlobal('fetch', router) + vi.unstubAllGlobals()and saidnothing about where the unstub goes — and that omission is what made
objectui#7439 flake. This changes what the guard says, not what it catches.
The new wording, and the passage it follows
Card objectui#7765 required the new clause to follow the worked example landed in
PR objectui#7764 rather than invent a second explanation, "because the defect
class this card belongs to is one ruling written twice, and one copy rotting."
The passage followed is the module-scope comment in
packages/app-shell/src/views/RecordDetailView.approvalDeclaredActions.test.tsx(lines 286-312). Its load-bearing sentences, and where each landed:
afterEachhooks in reverse registration order, so a teardown in THIS file runs FIRST — before the root setup's RTLcleanup()and before the network-escape guard's assertion"fetchback in place"refreshAfter...notifyDataChanged... Both are fire-and-forget by design: nothing in the console awaits them, and no test barrier here waits for them either"One clause is not from objectui#7764. The referenced example the message has
always pointed at,
packages/plugin-report/src/__tests__/DatasetReportRenderer.test.tsx, alreadyhardened its own teardown: its
afterEach(lines 137-148) callscleanup()before
vi.unstubAllGlobals(), with a comment stating the same reverse-orderfact and its own measurement — "Measured — one run in six leaked a single
attempt that way." That ordering is the cheaper of the two remedies and was
being dropped on the floor by the message's one-line summary of that file, so it
is now the first bullet. It is quoted from the file the message already cites,
not invented here.
The second copy — named individually
The claim's file surface admitted sibling guards printing the same prescription,
"but name each one." There is exactly one:
scripts/__tests__/network-escape-ledger.test.ts(lines 76-78) restated theshape in its own ledger-GREW assertion message. Restating the new clause there
would have recreated the very defect this card is about, so that message now
points at the guard's text instead of carrying a second copy of it.
Nothing asserts on the guard's message text: the only importer of the guard is
that pin, and it imports
KNOWN_ESCAPES(the set), not the string.Void condition — not tripped
Clause-② is
no, so any change to the guard's verdict voids the card.KNOWN_ESCAPESuntouched, and the four prohibitions all held.KNOWN_ESCAPESset,guardedFetch, and theafterEachfilter and verdict —diffbyte-identical againstorigin/main. The single changed hunk is@@ -239,2 +239,18 @@, inside thethrow new Error(...)template literal.packages/*/srcchanged. Diff is 2 files, anchored on therecorded base
dfcbedee5(origin/mainadvanced to7c67a773mid-run, so atwo-dot diff would have credited this branch with a sibling's merge).
check-governed-queue-guard.mjs --test:NOT GOVERNED — 2 path(s) checked against 5 governed surface(s); none matched.Kept as draft regardless.Lit control — the new text really is on the failure path
Not a static argument: a real escape was provoked and the printed message read
back. A temporary case was appended to
scripts/__tests__/report-namespace-agreement-6416.test.tscallingfetch('http://127.0.0.1:3000/api/v1/lit-control-7765'), run with a name filter.Mutation confirmed on disk before the run, by hash:
The guard went red and printed the whole new clause, thrown from
vitest.setup.network-escape-guard.ts:227:Restoration was under
trap ... EXIT INT TERMwith an absolute path, but theproof is state, not that the trap fired:
Green readings — the guard is a ROOT setup, so scale matters
It loads through
vitest.setup.base.tsfor every project, so a single filewould not show it undamaged.
vitest run --project unitvitest run --project dom --shard=1/8vitest run scripts/__tests__/network-escape-ledger.test.ts(the pin for a file changed here, named)Gates, each read from its own printed verdict rather than a bare
$?:pnpm type-check:vitest-setup— exit 0, no diagnostics. This is the gatefor a repo-root setup file; turbo's
type-checkstructurally cannot reach one.It resolves
@object-ui/components,/fields,/plugin-dashboard,/plugin-gridthrough their built declarations, so it was run afterbuilding those four closures. Run before that build it emits four
TS2882—an unmet prerequisite, not a result, and not reported as one.
pnpm type-check:scripts— exit 0 (covers the ledger pin file).pnpm lint:root— exit 0; 33 warnings, 0 errors, all pre-existingno-explicit-anyat lines 172/181/187, none in the changed hunk.node scripts/check-vi-mock-specifiers.mjs—OK (4313 tracked source file(s)...);node scripts/check-doc-example-shared-reader.mjs—OK 77 documented symbol(s).... These are the only two gate scripts that read eitherchanged path.
All heavy runs went through the shared verify lock; the wall-clock figures it
printed are shared-box seconds, not idle-box ones.
Changeset
Gate verdict, copied verbatim:
Acted on that verdict: no changeset added.
What was NOT measured — stated plainly
registered to re-observe
fetch is still the double? false. What this PR addsis corroboration from a third, independent site: the
DatasetReportRenderer.test.tsxafterEachcomment states the samereverse-order fact and reports its own measurement ("one run in six"), written
by a different author than objectui#7764. Three sites now agree; none of the
three was re-run as an experiment here.
fetchsits inside thetest body, so the guard naming that test is the ordinary case, not the
teardown-window misattribution the card describes. Nothing here says anything
about fact 2 either way.
🤖 Generated with Claude Code
https://claude.ai/code/session_01KbJQ1y1J12nZxYzFWhP8Q3
Generated by Claude Code