From c7bd31b4e368a72bba027998ff8c700efededff2 Mon Sep 17 00:00:00 2001 From: Scanner Date: Sun, 19 Jul 2026 17:07:31 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20fix:=20document=20isolate:true?= =?UTF-8?q?=20requirement=20to=20prevent=20#21284=20recurrence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the afterAll comment in setup.ts to accurately describe the current isolate:true behaviour (afterAll runs once per FILE, correctly cleaning up vi.stubGlobal() stubs) and to warn that setting isolate:false causes afterAll to run only once per shard — the root cause of 1598 test failures in Coverage Suite run #4339. Root-cause summary for #21284: PR #21283 set isolate:process.env.CI?false:true to work around suspected OOM crashes from chunk-splitting (#21083). With isolate:false all test files in a shard share one Vitest worker process. vi.stubGlobal() calls made at module scope in one file leaked into every subsequent file; the afterAll vi.unstubAllGlobals() in setup.ts ran only once at the end of the shard, not once per file, so contamination accumulated. Restoring isolate:true (PR #21290, commit 0f81cb019) fixed the failures. This commit updates setup.ts to make that constraint explicit and to point future maintainers at the full explanation in vite.config.ts. Fixes #21284 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Scanner --- web/src/test/setup.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/web/src/test/setup.ts b/web/src/test/setup.ts index d95ff30279..256cce8bc7 100644 --- a/web/src/test/setup.ts +++ b/web/src/test/setup.ts @@ -239,12 +239,17 @@ afterEach(() => { vi.useRealTimers() }) -// Clear global stubs after every test file. -// In vitest 4.x with pool:'forks'/isolate:false and maxWorkers:1 (CI), all test -// files in a shard share one worker process, so vi.stubGlobal() calls in one -// file's beforeAll leak into subsequent files. -// afterAll in setupFiles runs once per worker (end of shard), not once per file. -// Belt-and-suspenders: primary cleanup now happens in afterEach above (#20007). +// Clear global stubs when this test file finishes. +// With isolate:true (current setting in vite.config.ts), the setupFile runs inside +// each test file's own subprocess, so this afterAll executes once per FILE — +// correctly cleaning up any vi.stubGlobal() calls the file made at module scope, +// in beforeAll, or inside test callbacks. +// +// WARNING: if isolate is ever set to false, afterAll in setupFiles runs only once +// per shard (at the end of the worker), NOT once per file. That means +// vi.stubGlobal() calls in one file leak into all subsequent files in the same +// shard, which caused 1598 test failures in Coverage Suite run #4339 (#21284). +// Do NOT set isolate:false — see web/vite.config.ts for the full explanation. afterAll(() => { vi.unstubAllGlobals() })