Skip to content

Commit a99df04

Browse files
cliffhallclaude
andcommitted
test(web): document the isolate:true dependency (empirically confirmed) + fix pre-check-blindness wording (round 15)
Round-15 review of PR #1793 (merge-verdict; comment-only): - Finding 1: the auto-settle's module-level afterEach depends on isolate:true (the default) to re-register per test file; under isolate:false the module evaluates once per worker and the hook binds to only the first importing file, so other files arm with no consuming hook — the drain silently never runs and the state leaks across files. Reproduced it (vitest --no-isolate --pool=threads --no-file-parallelism over two real-transitions files leaves one file's arming unconsumed) and documented the assumption + the onTestFinished escape hatch on the arming-state comment. - Nit: the "sequence.hooks is why the pre-check can't see the concurrent detach" clause was wrong — the pre-check is blind because it runs synchronously before the await (a property of where it sits, not the hook mode). Reworded to state that, and that the concurrent case *additionally* needs sequence.hooks: "parallel". ViewHeader unchanged; npm run ci green. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5
1 parent 661c963 commit a99df04

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

‎clients/web/src/test/renderWithMantine.tsx‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,25 @@ const DEFAULT_SETTLE_MS = 500;
109109
// and did NOT unmount itself — the `afterEach` asserts each is still connected
110110
// (a still-mounted tree that got detached means `cleanup()` ran too early). A
111111
// test's own `unmount()` removes its container from the set (its detach is
112-
// legitimate) but leaves `armedSettleMs` armed so the drain still runs. This
113-
// module-level state assumes **sequential** tests: it isn't concurrency-safe, so
114-
// don't use `renderWithMantineTransitions` under `test.concurrent` /
115-
// `describe.concurrent` (two in-flight tests would share this arming).
112+
// legitimate) but leaves `armedSettleMs` armed so the drain still runs.
113+
//
114+
// Two config assumptions this module-level state depends on:
115+
// 1. **Sequential tests.** It isn't concurrency-safe, so don't use
116+
// `renderWithMantineTransitions` under `test.concurrent` /
117+
// `describe.concurrent` (two in-flight tests would share this arming).
118+
// 2. **`isolate: true`** (Vitest's default; nothing in vite.config.ts
119+
// overrides it). The `afterEach` below is registered when this module is
120+
// first evaluated during a test file's collection, so isolation — a fresh
121+
// module registry per file — is what re-registers it for every file. Under
122+
// `isolate: false` the module evaluates once per worker, so the hook binds
123+
// to only the first importing file; other files then arm with no hook to
124+
// consume it — the drain silently never runs (reopening #1760/#1786 with no
125+
// guard trip) and this state leaks across files. Confirmed by probe:
126+
// `vitest --no-isolate --pool=threads --no-file-parallelism` over two
127+
// real-transitions files leaves one file's arming unconsumed. If isolation
128+
// is ever disabled, move arming to `onTestFinished` inside
129+
// `renderWithMantineTransitions` (per-test, immune to module caching) — but
130+
// mind that its ordering vs `setup.ts`'s `cleanup()` must be re-established.
116131
let armedSettleMs: number | null = null;
117132
const liveArmedContainers = new Set<HTMLElement>();
118133

@@ -166,11 +181,13 @@ export async function settleTransitions(ms: number = DEFAULT_SETTLE_MS) {
166181
// containers, which guard against a future regression that makes cleanup run
167182
// before this settle finishes — e.g. cleanup moved to a *same-level* hook: the
168183
// pre-settle check catches it running entirely first, the post-settle check
169-
// catches it detaching the tree concurrently while this hook awaits — a race
170-
// that can only arise if the unit project's `sequence.hooks` is changed from
171-
// "stack" to "parallel" (same-level hooks run sequentially under "stack"/"list"),
172-
// which is exactly why the pre-check can't see it. Neither fires in the current
173-
// outer-cleanup setup. A container the test unmounted itself isn't in
184+
// catches it detaching the tree concurrently while this hook awaits. The
185+
// pre-check runs synchronously *before* the await, so it structurally can't
186+
// observe a mid-settle detach — that's why the post-check exists. That
187+
// concurrent case additionally needs the unit project's `sequence.hooks` set to
188+
// "parallel" (same-level hooks run sequentially under "stack"/"list", so they
189+
// can't overlap this hook's await). Neither fires in the current outer-cleanup
190+
// setup. A container the test unmounted itself isn't in
174191
// the set, so its legitimate detach is never mistaken for that regression.
175192
afterEach(async () => {
176193
const ms = armedSettleMs;

0 commit comments

Comments
 (0)