Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

docs(tests): make the network-escape guard's Fix: text say where the teardown goes - #7803

Merged
os-sam merged 1 commit into
mainfrom
claude/issue-7765-network-escape-guard-fix-text
Sep 5, 2026
Merged

os-sam merged 1 commit into
mainfrom
claude/issue-7765-network-escape-guard-fix-text

Conversation

@claude

@claude claude Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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 said
nothing 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:

objectui#7764 comment guard message now says
"Vitest runs afterEach hooks in reverse registration order, so a teardown in THIS file runs FIRST — before the root setup's RTL cleanup() and before the network-escape guard's assertion" same sentence, trimmed to "before this assertion"
"installed ONCE, here at module scope, and is deliberately NEVER torn down" "Install ONE at module scope and leave it up for the whole file"
"no test can ever end with the real fetch back in place" verbatim
"any refreshAfter... notifyDataChanged... Both are fire-and-forget by design: nothing in the console awaits them, and no test barrier here waits for them either" "any refreshAfter, any notifyDataChanged consumer, any fire-and-forget refresh no barrier awaits"

One clause is not from objectui#7764. The referenced example the message has
always pointed at,
packages/plugin-report/src/__tests__/DatasetReportRenderer.test.tsx, already
hardened its own teardown: its afterEach (lines 137-148) calls cleanup()
before vi.unstubAllGlobals(), with a comment stating the same reverse-order
fact 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 the
shape 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_ESCAPES untouched, and the four prohibitions all held.
  • Mechanically checked, not asserted: lines 110-235 of the guard — the whole
    KNOWN_ESCAPES set, guardedFetch, and the afterEach filter and verdict —
    diff byte-identical against origin/main. The single changed hunk is
    @@ -239,2 +239,18 @@, inside the throw new Error(...) template literal.
  • No file under packages/*/src changed. Diff is 2 files, anchored on the
    recorded base dfcbedee5 (origin/main advanced to 7c67a773 mid-run, so a
    two-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.ts calling
fetch('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:

HEAD blob:      a60eff61085e7e53a9b241ead7200c87c0c04885
mutated blob:   c82fac446f75e221820de5998a4d930e820bfe35   (non-empty, differs)

The guard went red and printed the whole new clause, thrown from
vitest.setup.network-escape-guard.ts:227:

 Test Files  1 failed (1)
      Tests  1 failed | 12 skipped (13)

Error: Network escape: this test reached a REAL socket at http://127.0.0.1:3000/api/v1/lit-control-7765.
...
WHERE that pair is torn down is part of the shape, not a detail
(objectui#7439). Vitest runs afterEach hooks in REVERSE registration order,
so a teardown written in THIS file runs FIRST — before the root setup's
RTL cleanup() and before this assertion. ...
  - call cleanup() BEFORE vi.unstubAllGlobals(), as that
    DatasetReportRenderer afterEach already does; and
  - if the component can issue a read AFTER the test body returns — any
    refreshAfter, any notifyDataChanged consumer, any fire-and-forget
    refresh no barrier awaits — do not tear the double down at all.

Restoration was under trap ... EXIT INT TERM with an absolute path, but the
proof is state, not that the trap fired:

HEAD blob:      a60eff61085e7e53a9b241ead7200c87c0c04885
worktree blob:  a60eff61085e7e53a9b241ead7200c87c0c04885   HASH EQUALITY: PASS
marker residue: 0
git diff HEAD:  (empty)          git status: clean

Green readings — the guard is a ROOT setup, so scale matters

It loads through vitest.setup.base.ts for every project, so a single file
would not show it undamaged.

reading files tests exit
vitest run --project unit 905 passed (905) 14927 passed, 9 skipped (14936) 0
vitest run --project dom --shard=1/8 191 passed (191) 1898 passed (1898) 0
vitest run scripts/__tests__/network-escape-ledger.test.ts (the pin for a file changed here, named) 1 passed (1) 3 passed (3) 0

Gates, each read from its own printed verdict rather than a bare $?:

  • pnpm type-check:vitest-setup — exit 0, no diagnostics. This is the gate
    for a repo-root setup file; turbo's type-check structurally cannot reach one.
    It resolves @object-ui/components, /fields, /plugin-dashboard,
    /plugin-grid through their built declarations, so it was run after
    building 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-existing
    no-explicit-any at 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 either
    changed 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:

Compared the working tree with dfcbedee5 (merge-base with origin/main): 2 file(s) changed, 0 of them published source of a package the release covers, 0 of them a manifest whose published contract moved, 0 under a package changesets ignores, 0 changeset(s) added.
✅  No source or published contract of a released package changed in this range, so no changeset is owed.

Acted on that verdict: no changeset added.

What was NOT measured — stated plainly

  • Card fact 1 was not independently re-measured here. No probe was
    registered to re-observe fetch is still the double? false. What this PR adds
    is corroboration from a third, independent site: the
    DatasetReportRenderer.test.tsx afterEach comment states the same
    reverse-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.
  • Card fact 2 was not confirmed. The lit control's fetch sits inside the
    test 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

…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
@github-actions github-actions Bot added the tests label Sep 5, 2026
Merged via the queue into main with commit a617bb8 Sep 5, 2026
31 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The network-escape guard prescribes a stubGlobal + unstubAllGlobals pair that races a component re-read started after the test body returns

1 participant