On high-core dev machines (e.g. 28-core M-series), per-package vitest defaulted to cpus().length - 1 workers (27), and `pnpm test` ran 4 workspace packages concurrently — easily 100+ vitest threads per sweep. When the dashboard had agents running tests, 2+ concurrent sweeps would saturate CPU and the UI became sluggish. - Cap defaultMaxWorkers to min(6, cpus()-1) in cli/dashboard/desktop/ mobile/plugin-sdk vitest configs (engine and core were already capped) - Lower root `pnpm test` workspace-concurrency 4 → 2 - VITEST_MAX_WORKERS override still respected for explicit fast runs Worst-case fan-out drops from ~108 workers to ~12 per `pnpm test`. CI runners with fewer cores are unaffected (cap doesn't bind). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
2.8 KiB
TypeScript
53 lines
2.8 KiB
TypeScript
import { defineConfig } from "vitest/config";
|
|
import { resolve } from "node:path";
|
|
import { cpus } from "node:os";
|
|
|
|
// Cap fan-out to 6 so high-core dev machines don't spawn 27+ workers per
|
|
// package — that saturates the box when multiple workspace packages test
|
|
// concurrently or when the dashboard has agents running tests in parallel.
|
|
// Override with VITEST_MAX_WORKERS for explicit fast/serial runs.
|
|
const defaultMaxWorkers = Math.min(6, Math.max(1, cpus().length - 1));
|
|
const requestedMaxWorkers = Number.parseInt(process.env.VITEST_MAX_WORKERS ?? String(defaultMaxWorkers), 10);
|
|
const maxWorkers = Math.max(1, Number.isFinite(requestedMaxWorkers) ? requestedMaxWorkers : defaultMaxWorkers);
|
|
process.env.VITEST_MAX_WORKERS = String(maxWorkers);
|
|
|
|
export default defineConfig({
|
|
resolve: {
|
|
// Keep these aliases exact and ordered (subpaths before package roots).
|
|
// In fresh worktrees, internal packages may not have dist/ built yet, and
|
|
// Vite otherwise resolves workspace package exports.import to dist/*.js.
|
|
// Anchored regex aliases force CLI tests to use source entrypoints instead.
|
|
alias: [
|
|
{ find: /^@fusion\/core\/gh-cli$/, replacement: resolve(__dirname, "../core/src/gh-cli.ts") },
|
|
{ find: /^@fusion\/core$/, replacement: resolve(__dirname, "../core/src/index.ts") },
|
|
{ find: /^@fusion\/dashboard\/planning$/, replacement: resolve(__dirname, "../dashboard/src/planning.ts") },
|
|
{ find: /^@fusion\/dashboard$/, replacement: resolve(__dirname, "../dashboard/src/index.ts") },
|
|
{ find: /^@fusion\/engine$/, replacement: resolve(__dirname, "../engine/src/index.ts") },
|
|
{ find: /^@fusion\/plugin-sdk$/, replacement: resolve(__dirname, "../plugin-sdk/src/index.ts") },
|
|
{ find: /^@fusion\/test-utils$/, replacement: resolve(__dirname, "../core/src/__test-utils__/workspace.ts") },
|
|
],
|
|
},
|
|
test: {
|
|
include: ["src/**/*.test.ts", "src/**/*.test.tsx"],
|
|
// build-exe + build-exe-cross live in their own vitest project
|
|
// (see vitest.build-exe.config.ts) so the rest of the CLI suite can
|
|
// run with file parallelism enabled.
|
|
exclude: ["**/node_modules/**", "**/dist/**", "src/__tests__/build-exe*.test.ts"],
|
|
setupFiles: [
|
|
"./src/__tests__/setup-test-isolation.ts",
|
|
resolve(__dirname, "../core/src/__test-utils__/vitest-setup.ts"),
|
|
],
|
|
globalSetup: [resolve(__dirname, "../core/src/__test-utils__/vitest-teardown.ts")],
|
|
maxWorkers,
|
|
poolOptions: { threads: { minThreads: 1, maxThreads: maxWorkers }, forks: { minForks: 1, maxForks: maxWorkers } },
|
|
fileParallelism: true,
|
|
coverage: {
|
|
enabled: false,
|
|
reporter: ["text", "html", "json"],
|
|
reportsDirectory: "./coverage",
|
|
include: ["src/**/*.ts"],
|
|
exclude: ["**/*.test.ts", "**/*.d.ts", "dist/**"],
|
|
},
|
|
},
|
|
});
|