mirror of
https://github.com/Fission-AI/OpenSpec.git
synced 2026-10-02 05:24:34 +08:00
fix(vitest): cap worker parallelism to prevent process storms (#500)
Vitest v3 defaults to `pool: "forks"` and scales worker processes with CPU count. This repo's tests spawn many Node processes (CLI invocations, temp FS operations), which can cause runaway CPU/memory usage when combined with high parallelism. Changes: - Explicitly set pool to 'forks' (tests rely on process isolation) - Add resolveMaxWorkers() to cap workers at min(4, availableCPUs) - Allow VITEST_MAX_WORKERS env override for CI/automation tuning
This commit is contained in:
+23
-2
@@ -1,12 +1,33 @@
|
||||
import { defineConfig } from 'vitest/config';
|
||||
import os from 'node:os';
|
||||
|
||||
function resolveMaxWorkers(): number | undefined {
|
||||
// Allow callers (CI/agents) to override without editing config.
|
||||
const raw = process.env.VITEST_MAX_WORKERS;
|
||||
if (raw) {
|
||||
const parsed = Number(raw);
|
||||
if (Number.isFinite(parsed) && parsed > 0) {
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
|
||||
// Vitest v3 defaults to `pool: "forks"` and scales worker processes with CPU.
|
||||
// This repo's tests can spawn many Node processes (CLI invocations, temp FS),
|
||||
// so cap parallelism to avoid runaway CPU/memory usage in automation.
|
||||
const cpuCount = typeof os.availableParallelism === 'function'
|
||||
? os.availableParallelism()
|
||||
: os.cpus().length;
|
||||
return Math.min(4, Math.max(1, cpuCount));
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
globalSetup: './vitest.setup.ts',
|
||||
// Keep default pool settings; some tests rely on process.chdir,
|
||||
// which is not supported in worker threads
|
||||
// Tests rely on per-file process isolation (e.g., `process.cwd()` assumptions).
|
||||
pool: 'forks',
|
||||
maxWorkers: resolveMaxWorkers(),
|
||||
include: ['test/**/*.test.ts'],
|
||||
coverage: {
|
||||
reporter: ['text', 'json', 'html'],
|
||||
|
||||
Reference in New Issue
Block a user