Repository navigation
test(studio): run vitest without isolation in web and server - #2203
Merged
Merged
Conversation
kantord
force-pushed
the
studio-vitest-settings
branch
from
October 8, 2026 16:14
bf30d39 to
66cba0c
Compare
kantord
marked this pull request as ready for review
October 8, 2026 16:15
peppescg
approved these changes
Oct 8, 2026
Merged
2 tasks
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
Studio (
apps/web,apps/server) now runs vitest withisolate: false. Tests share one module cache per worker, which removes per-file environment setup and, more importantly, makes cross-file state leaks fail loudly while the suite is still small instead of rotting in.apps/lint/) fail the build onvi.mock/vi.doMockand on direct Web Storage spies. Their messages point at theNO-ISOLATE RULEScomment at the top ofapps/web/src/test-setup.ts, which lists each known-bad pattern next to its idiomatic fix.test-setup.tsruns after every test: RTL cleanup, real timers, text selection, Web Storage,account-storageandapi-clientmodule state, and the shared generated client'sbaseUrl/fetch. Spies, stubbed globals and env use vitest'srestoreMocks/unstubGlobals/unstubEnvsflags.vi.mockfiles (8 in web, 1 in server) plus 3 that landed on main meanwhile now render real modules under real providers and fake the network at theapiClient/fetchboundary.Findings worth knowing
vi.restoreAllMocks()and therestoreMocksflag do not restore a spy on happy-dom'slocalStorage; one leaked spy broke ~30 unrelated tests.spyOnLocalStorage()(web/src/test-storage.ts) registers its own restore, and Biome bans direct storage spies.window/documentare shared across files underisolate: false(properties,<body>attributes, the text selection).test-setup.tsevaluates the production route tree first, which avoids it (commented there).Review notes
createApptakes an optionalstudioBuildId(replaces avi.mockofbuild-info.js);api-client.tsgainsresetApiClientState().error-routes.test.tsxcan no longer put the private sentinel into a real render crash, so it asserts the sentinel and the rawCannot read propertiestext are absent. The four test-router tests still throw the sentinel directly. Twoglobal-searchassertions moved from SDK-call arguments to what is visible on the wire (cache: no-store, no query string).global-search.test.tsx > checks fresh identity before reopening cached private resultsfails in roughly a quarter to a half of shuffled serial runs (--no-file-parallelism --sequence.shuffle.files), never in normal runs, and passes 20/20 alone and with isolation on. Minimal polluter:chat-workspace.transcript.integration.test.tsx. Cause not found.apps/server's integration suite (needs themecatedbinary) andsdk/typescript, which keeps default isolation and is untouched.Not ported:
sdk/typescriptsdk/typescriptandsdk/typescript/examples/slack-botkeep vitest's default isolation. They were not touched and were not assessed (different package, probably a node environment rather than happy-dom). The method below is what worked here, so a future port can follow it.Method for porting a package to
isolate: falsevitest run --no-isolatewith no config change. Failures that differ between runs are scheduling-dependent leaks.--no-file-parallelism(one worker) plus a fixed file order. A tinyBaseSequencersubclass that sorts by an explicit order list (env var) lets you run any[polluter, victim]subset in a chosen order. Alphabetical order hides leaks whose victim sorts before the polluter, so also sweep--sequence.shuffle.files --sequence.seed=Nover 10+ seeds.[P, victim]pair (parallelised, ~3s each) to list single-file polluters, and ddmin over all predecessors when no single file reproduces it. For an intermittent failure, capture the file order of a failing run (JSON reporter, sort bystartTime) and count a subset as failing if any of ~4 trials fails.--isolate). If it still fails, it is the test, not the isolation setting.afterEachin a setup file for global state (storage, selection, timers, module-level singletons with a reset function owned by the module);restoreMocks/unstubGlobals/unstubEnvsflags for spies, stubs and env;vi.mock(real modules, real providers, fake the network at the client boundary) and enforce that with a lint rule so it cannot come back;cleanup()for Testing Library, whose auto-cleanup only registers in the first file of a worker.restoreAllMocksonlocalStorage).document.body.innerHTML = "") or callhappyDOM.abort()after each test: the latter leaves the window unusable (385 failures here). Add a reset only for state a shuffled serial run proves is shared.The throwaway tooling (an order sequencer config, a pair scanner and a ddmin script, ~100 lines in total) was not committed.
Test plan
cd apps && pnpm check(Biome, typecheck, server 182/182, web 651/651, generated files in sync)Fully or partially written by an AI agent.
🤖 Generated with Claude Code