Skip to content

test: enable vitest isolate:false on safe packages#5962

Open
killagu wants to merge 1 commit into
nextfrom
feat/vitest-isolate-false-safe-packages
Open

test: enable vitest isolate:false on safe packages#5962
killagu wants to merge 1 commit into
nextfrom
feat/vitest-isolate-false-safe-packages

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented Jun 4, 2026

Motivation

Run test files within a project in a single reused worker thread (pool: 'threads', isolate: false) instead of spawning a fresh worker per file, to speed up the suite.

The root vitest.config.ts already declared isolate: false / pool: 'threads', but in Vitest 4 root test options are not inherited by glob-referenced projects — every project was silently running with the defaults (isolate: true, forks). This sets the options explicitly on each project that is verified safe.

On the tegg-plugin pilot this cut wall-clock from ~25s to ~18s.

Scope

66 projects confirmed green under isolate: false + threads (each run individually via its committed config, 0 failures).

Deliberately excluded (follow-up)

  • packages/cluster, plugins/schedule, plugins/mock, packages/egg, plugins/development, plugins/view-nunjucks — these spawn real Egg cluster/app child processes via mm.cluster, whose fixed-port allocation in plugins/mock/src/lib/cluster.ts (globalThis.eggMockMasterPort = 17000 + (process.pid % 1000)) assumes one OS process per test file. Sharing a worker resets/collides that counter → flaky EADDRINUSE. These can opt in after the mock port allocation is made isolation-safe (idempotent seed via ??=, or bind an ephemeral port: 0 and read it back from the existing egg-ready message).
  • packages/logger — sets fileParallelism: false (→ maxWorkers: 1); under isolate: false Vitest 4 requires a uniform maxWorkers per sequence.groupOrder, which would abort whole-suite collection.

The root vitest.config.ts is intentionally left unchanged in this PR (its dead isolate/pool options can be cleaned up separately).

Test evidence

  • Full-suite collection verified clean (vitest list → 3280 tests, no sequence.groupOrder error).
  • All 66 included projects run green via their committed configs (vitest run --project=<name>).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Optimized testing infrastructure across all packages and plugins by configuring test worker thread pooling. Test files now reuse shared worker resources instead of spawning isolated workers, improving resource utilization and reducing test execution time.

Run test files within a project in a single reused worker thread
(`pool: 'threads'`, `isolate: false`) instead of spawning a fresh worker
per file, to speed up the suite.

The root `vitest.config.ts` already declared these options, but in Vitest 4
root `test` options are NOT inherited by glob-referenced projects, so every
project was silently running with the defaults (`isolate: true`, `forks`).
This sets the options explicitly on each project that is verified safe.

Scope: 66 projects confirmed green under `isolate: false` + `threads`.

Deliberately excluded (tracked as follow-up):
- packages/cluster, plugins/schedule, plugins/mock, packages/egg,
  plugins/development, plugins/view-nunjucks — these spawn real Egg
  cluster/app child processes via `mm.cluster`, whose fixed-port allocation
  in plugins/mock (`globalThis.eggMockMasterPort = 17000 + process.pid % 1000`)
  assumes one OS process per test file. Sharing a worker resets/collides that
  counter, causing flaky EADDRINUSE failures. Needs a mock port-allocation fix
  (idempotent seed or ephemeral `port: 0`) before they can opt in.
- packages/logger — sets `fileParallelism: false` (maxWorkers: 1); under
  isolate:false Vitest 4 requires a uniform maxWorkers per sequence.groupOrder,
  so it would abort whole-suite collection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 4, 2026 16:57
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d4e1450e-a644-4d7a-a793-5dc9472e75e8

📥 Commits

Reviewing files that changed from the base of the PR and between 7e6be0e and 0eb57bf.

📒 Files selected for processing (66)
  • packages/cookies/vitest.config.ts
  • packages/core/vitest.config.ts
  • packages/errors/vitest.config.ts
  • packages/extend2/vitest.config.ts
  • packages/koa-static-cache/vitest.config.ts
  • packages/koa/vitest.config.ts
  • packages/loader-fs/vitest.config.ts
  • packages/path-matching/vitest.config.ts
  • packages/router/vitest.config.ts
  • packages/supertest/vitest.config.ts
  • packages/tsconfig/vitest.config.ts
  • packages/utils/vitest.config.ts
  • plugins/i18n/vitest.config.ts
  • plugins/jsonp/vitest.config.ts
  • plugins/logrotator/vitest.config.ts
  • plugins/onerror/vitest.config.ts
  • plugins/redis/vitest.config.ts
  • plugins/session/vitest.config.ts
  • plugins/static/vitest.config.ts
  • plugins/tracer/vitest.config.ts
  • plugins/typebox-validate/vitest.config.ts
  • plugins/view/vitest.config.ts
  • plugins/watcher/vitest.config.ts
  • tegg/core/agent-runtime/vitest.config.ts
  • tegg/core/ajv-decorator/vitest.config.ts
  • tegg/core/aop-decorator/vitest.config.ts
  • tegg/core/aop-runtime/vitest.config.ts
  • tegg/core/background-task/vitest.config.ts
  • tegg/core/common-util/vitest.config.ts
  • tegg/core/controller-decorator/vitest.config.ts
  • tegg/core/core-decorator/vitest.config.ts
  • tegg/core/dal-decorator/vitest.config.ts
  • tegg/core/dal-runtime/vitest.config.ts
  • tegg/core/dynamic-inject-runtime/vitest.config.ts
  • tegg/core/dynamic-inject/vitest.config.ts
  • tegg/core/eventbus-decorator/vitest.config.ts
  • tegg/core/eventbus-runtime/vitest.config.ts
  • tegg/core/langchain-decorator/vitest.config.ts
  • tegg/core/lifecycle/vitest.config.ts
  • tegg/core/loader/vitest.config.ts
  • tegg/core/mcp-client/vitest.config.ts
  • tegg/core/metadata/vitest.config.ts
  • tegg/core/orm-decorator/vitest.config.ts
  • tegg/core/runtime/vitest.config.ts
  • tegg/core/schedule-decorator/vitest.config.ts
  • tegg/core/standalone-decorator/vitest.config.ts
  • tegg/core/tegg/vitest.config.ts
  • tegg/core/test-util/vitest.config.ts
  • tegg/core/transaction-decorator/vitest.config.ts
  • tegg/core/types/vitest.config.ts
  • tegg/core/vitest/vitest.config.ts
  • tegg/plugin/ajv/vitest.config.ts
  • tegg/plugin/aop/vitest.config.ts
  • tegg/plugin/common/vitest.config.ts
  • tegg/plugin/config/vitest.config.ts
  • tegg/plugin/controller/vitest.config.ts
  • tegg/plugin/dal/vitest.config.ts
  • tegg/plugin/eventbus/vitest.config.ts
  • tegg/plugin/langchain/vitest.config.ts
  • tegg/plugin/mcp-client/vitest.config.ts
  • tegg/plugin/mcp-proxy/vitest.config.ts
  • tegg/plugin/orm/vitest.config.ts
  • tegg/plugin/schedule/vitest.config.ts
  • tegg/plugin/tegg/vitest.config.ts
  • tegg/standalone/standalone/vitest.config.ts
  • tools/create-egg/vitest.config.ts

📝 Walkthrough

Walkthrough

This PR standardizes Vitest worker pool configuration across 70+ monorepo packages and plugins by adding or updating defineProject configurations to consistently set pool: 'threads' and isolate: false, enabling shared thread reuse and disabling per-file test isolation.

Changes

Vitest Worker Pool and Isolation Settings

Layer / File(s) Summary
Thread pool and isolation configuration
packages/*/vitest.config.ts, plugins/*/vitest.config.ts, tegg/*/vitest.config.ts, tools/*/vitest.config.ts
70+ vitest.config.ts files are updated to use defineProject with pool: 'threads' and isolate: false, enabling shared worker thread reuse across all test files in each Vitest workspace project across the monorepo.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • eggjs/egg#5563: Established initial Vitest workspace configuration for the tracer plugin with the same thread pooling pattern.
  • eggjs/egg#5823: Previously added empty Vitest configurations that this PR completes with thread pool settings.
  • eggjs/egg#5546: Initial Vitest workspace setup for packages that this PR enhances with pooling configuration.

Suggested reviewers

  • fengmk2
  • gxkl

Poem

🐰 Thread pools dance in harmony,
No isolation walls to see,
Tests now sprint with worker's grace,
Shared resources fill the space,
Faster tests across the lands,
Vitest config takes the stands! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: enabling vitest's isolate:false configuration across safe packages to optimize test performance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vitest-isolate-false-safe-packages

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0eb57bf
Status: ✅  Deploy successful!
Preview URL: https://794095be.egg-cci.pages.dev
Branch Preview URL: https://feat-vitest-isolate-false-sa.egg-cci.pages.dev

View logs

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request configures Vitest across multiple packages and plugins to reuse a single worker thread and disable isolation (pool: 'threads' and isolate: false) to speed up the test suite. Feedback suggests removing the unnecessary and incorrect UserWorkspaceConfig type annotations to let TypeScript infer the correct type, and replacing defineConfig with defineProject in plugins/redis and tegg/core/vitest configurations to ensure proper workspace integration.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +1 to +11
import { defineProject, type UserWorkspaceConfig } from 'vitest/config';

const config: UserWorkspaceConfig = defineProject({
test: {
// Reuse a single worker thread across this project's test files instead of
// spawning a fresh worker per file. The root vitest.config.ts cannot set
// these for glob-matched projects, so each project opts in explicitly.
pool: 'threads',
isolate: false,
},
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The explicit UserWorkspaceConfig type annotation is incorrect for a project configuration (which should be UserProjectConfig or inferred) and is unnecessary. We can let TypeScript automatically infer the correct type returned by defineProject and remove the unused import.

This suggestion can be applied to all the newly added vitest.config.ts files in this PR to keep them clean and consistent.

Suggested change
import { defineProject, type UserWorkspaceConfig } from 'vitest/config';
const config: UserWorkspaceConfig = defineProject({
test: {
// Reuse a single worker thread across this project's test files instead of
// spawning a fresh worker per file. The root vitest.config.ts cannot set
// these for glob-matched projects, so each project opts in explicitly.
pool: 'threads',
isolate: false,
},
});
import { defineProject } from 'vitest/config';
const config = defineProject({
test: {
// Reuse a single worker thread across this project's test files instead of
// spawning a fresh worker per file. The root vitest.config.ts cannot set
// these for glob-matched projects, so each project opts in explicitly.
pool: 'threads',
isolate: false,
},
});

Comment on lines +5 to +6
pool: 'threads',
isolate: false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Vitest workspaces, individual project configurations should use defineProject instead of defineConfig to ensure correct configuration merging and behavior within the workspace. Additionally, the explicit UserWorkspaceConfig type annotation can be removed to let TypeScript automatically infer the correct UserProjectConfig type returned by defineProject.

Please consider updating this file to use defineProject and remove the explicit type annotation, similar to the other project configurations.

Comment on lines +23 to +24
pool: 'threads',
isolate: false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to other workspace projects, tegg/core/vitest should use defineProject instead of defineConfig to ensure proper integration and configuration merging within the Vitest workspace.

Please consider updating the import and changing defineConfig to defineProject in this file.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.31%. Comparing base (b015dce) to head (0eb57bf).
⚠️ Report is 1 commits behind head on next.

❗ There is a different number of reports uploaded between BASE (b015dce) and HEAD (0eb57bf). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (b015dce) HEAD (0eb57bf)
6 3
Additional details and impacted files
@@             Coverage Diff             @@
##             next    #5962       +/-   ##
===========================================
- Coverage   85.30%   53.31%   -32.00%     
===========================================
  Files         670       12      -658     
  Lines       19552      287    -19265     
  Branches     3863       69     -3794     
===========================================
- Hits        16678      153    -16525     
+ Misses       2481      113     -2368     
+ Partials      393       21      -372     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes Vitest project configs explicitly opt into pool: 'threads' + isolate: false so that glob-referenced workspace projects actually run with the intended shared-worker settings (improving test wall-clock time) rather than silently falling back to Vitest defaults.

Changes:

  • Updated existing vitest.config.ts files to add test.pool = 'threads' and test.isolate = false.
  • Added new per-project vitest.config.ts files for projects that previously relied on defaults, explicitly opting them into shared-worker execution.
  • Kept package-specific overrides (timeouts, include/exclude, etc.) intact while enabling the shared-worker mode where configured.

Reviewed changes

Copilot reviewed 66 out of 66 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/create-egg/vitest.config.ts Enable threads pool + isolate: false for this project’s tests
tegg/standalone/standalone/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/tegg/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/schedule/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/orm/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/mcp-proxy/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/mcp-client/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/langchain/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/eventbus/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/dal/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/controller/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/config/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/common/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/aop/vitest.config.ts New project config opting into threads + isolate: false
tegg/plugin/ajv/vitest.config.ts Add threads pool + isolate: false while preserving hook timeout
tegg/core/vitest/vitest.config.ts Add threads pool + isolate: false to the custom-runner project config
tegg/core/types/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/transaction-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/test-util/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/tegg/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/standalone-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/schedule-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/runtime/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/orm-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/metadata/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/mcp-client/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/loader/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/lifecycle/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/langchain-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/eventbus-runtime/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/eventbus-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/dynamic-inject/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/dynamic-inject-runtime/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/dal-runtime/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/dal-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/core-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/controller-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/common-util/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/background-task/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/aop-runtime/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/aop-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/ajv-decorator/vitest.config.ts New project config opting into threads + isolate: false
tegg/core/agent-runtime/vitest.config.ts Convert empty project config to explicitly set threads + isolate: false
plugins/watcher/vitest.config.ts Add threads pool + isolate: false to plugin tests
plugins/view/vitest.config.ts Add threads pool + isolate: false to plugin tests
plugins/typebox-validate/vitest.config.ts New project config opting into threads + isolate: false
plugins/tracer/vitest.config.ts New project config opting into threads + isolate: false
plugins/static/vitest.config.ts New project config opting into threads + isolate: false
plugins/session/vitest.config.ts New project config opting into threads + isolate: false
plugins/redis/vitest.config.ts Add threads pool + isolate: false while preserving plugin test settings
plugins/onerror/vitest.config.ts Add threads pool + isolate: false to plugin tests
plugins/logrotator/vitest.config.ts Add threads pool + isolate: false to plugin tests
plugins/jsonp/vitest.config.ts New project config opting into threads + isolate: false
plugins/i18n/vitest.config.ts New project config opting into threads + isolate: false
packages/utils/vitest.config.ts Add threads pool + isolate: false to package tests
packages/tsconfig/vitest.config.ts New project config opting into threads + isolate: false
packages/supertest/vitest.config.ts New project config opting into threads + isolate: false
packages/router/vitest.config.ts New project config opting into threads + isolate: false
packages/path-matching/vitest.config.ts New project config opting into threads + isolate: false
packages/loader-fs/vitest.config.ts New project config opting into threads + isolate: false
packages/koa/vitest.config.ts New project config opting into threads + isolate: false
packages/koa-static-cache/vitest.config.ts New project config opting into threads + isolate: false
packages/extend2/vitest.config.ts New project config opting into threads + isolate: false
packages/errors/vitest.config.ts New project config opting into threads + isolate: false
packages/core/vitest.config.ts Add threads pool + isolate: false to package tests
packages/cookies/vitest.config.ts New project config opting into threads + isolate: false

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0eb57bf
Status: ✅  Deploy successful!
Preview URL: https://71a95941.egg-v3.pages.dev
Branch Preview URL: https://feat-vitest-isolate-false-sa.egg-v3.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants