fix(test): pre-warm vite dep optimization for browser suites so mid-run re-optimize never reloads the tester (#389) - #422
Conversation
…un re-optimize never reloads the tester (#389) On cold CI runners, vite can discover a dependency mid-run (esbuild's static scan can't resolve solid-conditioned packages like lucide-solid until vite-plugin-solid's own optimizeDeps.include crawl catches up), re-optimize, and full-reload the __vitest_test__ tester frame. Vitest browser mode has no birpc reconnect, so that reload kills the whole package run (vitest-dev/vitest#10791). Add a shared browserOptimizeDeps() helper in @conciv/vitest-config that declares the known late-discovered dep (lucide-solid) in optimizeDeps.include as a sibling of each browser project's `test` config, matching vitest's own suggested fix ("please add mentioned dependencies to your config's `optimizeDeps.include` field manually"). Wired into every vitest browser project: app, ui-kit-chat, ui-kit-chat-tools, ui-kit-system, ui-kit-terminal, extensions/terminal. Two riskier approaches were tried and reverted after they reproduced the exact failure locally: a broad optimizeDeps.entries glob crawled into node-only test helpers and broke the client scan (fsevents), and forcing optimizeDeps.extensions: ['.jsx'] caused vite to pre-bundle lucide-solid's raw JSX source without a transform, corrupting the optimized output and killing the browser connection outright. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR adds a shared ChangesVitest browser optimizeDeps configuration
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Comment |
There was a problem hiding this comment.
Pull request overview
Pre-warms Vite browser-test dependencies to prevent mid-run optimizer reloads from disconnecting Vitest.
Changes:
- Adds shared
browserOptimizeDeps()configuration forlucide-solid. - Applies it to six browser-test projects.
- Three applicable browser projects remain unconfigured.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/vitest-config/src/reporters.ts |
Adds the shared optimization helper. |
apps/conciv/vitest.config.ts |
Enables dependency pre-warming. |
packages/ui-kit-chat/vitest.config.ts |
Enables dependency pre-warming. |
packages/ui-kit-chat-tools/vitest.config.ts |
Enables dependency pre-warming. |
packages/ui-kit-system/vitest.config.ts |
Enables dependency pre-warming. |
packages/ui-kit-terminal/vitest.config.ts |
Enables dependency pre-warming. |
packages/extensions/terminal/vitest.config.ts |
Enables dependency pre-warming. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| const LATE_DISCOVERED_BROWSER_DEPS = ['lucide-solid'] | ||
|
|
||
| export function browserOptimizeDeps(): { |
Summary
__vitest_test__tester frame; vitest browser mode has no birpc reconnect (Browser mode: run hangs forever when a tester page dies without closing its websocket (no run-level deadline on createTesters) vitest-dev/vitest#10791), so the reload kills the whole package run. Root-caused withpw:protocollogging in comment on #389:prepareDuration: 61547mson cold runners →Failed to fetch dynamically imported moduleon the in-flight test →Page.frameStartedNavigating navigationType:"reload"→Inspector.detached "Render process gone."→[vitest] Browser connection was closed/[birpc] rpc is closed.browserOptimizeDeps()to@conciv/vitest-config(packages/vitest-config/src/reporters.ts), a single shared definition ofoptimizeDeps.includefor deps known to be discovered late — currentlylucide-solid, which resolves through vite-plugin-solid's'solid'export condition and only gets pre-bundled once that plugin's own package crawl completes. This matches vitest's own suggested remediation (its custom logger literally recommendsoptimizeDeps.includewhen it detects a mid-run reload).optimizeDeps: browserOptimizeDeps()as a vite-level sibling of each browser project'stestconfig in all six vitest browser projects:apps/conciv,packages/ui-kit-chat,packages/ui-kit-chat-tools,packages/ui-kit-system,packages/ui-kit-terminal,packages/extensions/terminal.Investigation notes
@vitest/browser's dist that vitest's ownvitest:browser:testsplugin already setsoptimizeDeps.entriesto the full set of browser test files + setup files via aconfig()hook, and that Vite'smergeConfigconcatenates array-valuedoptimizeDeps.*fields across pluginconfig()hooks and the project config — sobrowserOptimizeDeps()'sincludelist additively extends vitest's own entries rather than fighting them.optimizeDeps.entriestosrc/**/*.{ts,tsx}+test/**/*.{ts,tsx}globs pulled node-only unit-test helpers into the client dependency scan and broke the build entirely (UNLOADABLE_DEPENDENCYonfsevents).optimizeDeps.extensions: ['.jsx']to force-optimizelucide-solid's raw JSX source caused vite to pre-bundle it without the solid-plugin's own JSX handling, producing invalid JS in the deps cache (Failed to parse source for import analysis... make sure to name the file with the .jsx or .tsx extension) and killing every subsequent browser test file withFailed to fetch dynamically imported module.include-only change produces one benignCannot optimize dependency: lucide-solid, present in client 'optimizeDeps.include'warning (vite-plugin-solid's own crawl already optimizes it through the'solid'condition, so the explicit include is a documented no-op/safety net today) but does not affect test outcomes.Test plan
env TURBO_CONCURRENCY=1 VITEST_MAX_FORKS=1 pnpm turbo run test --concurrency=1 --filter=@conciv/app --forceon a cold.vitecache: 28/28 files, 105/105 tests, no "optimized dependencies changed" / reload messages in the log.@conciv/ui-kit-chat: 28/28 files, 145/145 tests, no reload messages.env TURBO_CONCURRENCY=70% pnpm turbo run typecheck --filter=@conciv/vitest-config --filter=@conciv/app --filter=@conciv/ui-kit-chat --filter=@conciv/ui-kit-chat-tools --filter=@conciv/ui-kit-system --filter=@conciv/ui-kit-terminal --filter=@conciv/extension-terminal: all green.pnpm exec oxfmt --check/pnpm exec oxlinton touched files: clean.pnpm exec fallow audit --changed-since origin/main --format json: verdictpass, 0 introduced findings.diag/389-app-browser(temporary lone-suite diagnostic branch, 7 runs triggered): watch for absence of the reload/birpc-closed signature across repeated cold runs.🤖 Generated with Claude Code
Summary by CodeRabbit