Skip to content

Commit 3db41b2

Browse files
committed
perf: leave Vitest workers uncapped in CI
1 parent a5e2103 commit 3db41b2

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

scripts/lib/vitest-concurrency.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
* leaves roughly 3 cores for runners, subprocesses, simulators, and the OS.
55
*/
66
export const DEFAULT_VITEST_MAX_WORKERS = 2;
7+
8+
export function resolveVitestMaxWorkers(env: NodeJS.ProcessEnv = process.env): number | undefined {
9+
return env.CI === 'true' ? undefined : DEFAULT_VITEST_MAX_WORKERS;
10+
}

src/__tests__/hermetic-env-setup.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import os from 'node:os';
22
import path from 'node:path';
33
import { afterEach, test, vi } from 'vitest';
44
import assert from 'node:assert/strict';
5-
import { DEFAULT_VITEST_MAX_WORKERS } from '../../scripts/lib/vitest-concurrency.ts';
5+
import {
6+
DEFAULT_VITEST_MAX_WORKERS,
7+
resolveVitestMaxWorkers,
8+
} from '../../scripts/lib/vitest-concurrency.ts';
69
import vitestConfig from '../../vitest.config.ts';
710

811
const HERMETIC_ENV_SETUP = 'src/__tests__/hermetic-env-setup.ts';
@@ -15,7 +18,9 @@ const VITEST_CLAIMS_DIR = path.join(os.tmpdir(), `agent-device-vitest-claims-${p
1518
type ProjectShape = { test?: { name?: string; setupFiles?: readonly string[] } };
1619

1720
test('vitest caps aggregate worker concurrency for parallel worktrees', () => {
18-
assert.equal(vitestConfig.test?.maxWorkers, DEFAULT_VITEST_MAX_WORKERS);
21+
assert.equal(vitestConfig.test?.maxWorkers, resolveVitestMaxWorkers());
22+
assert.equal(resolveVitestMaxWorkers({}), DEFAULT_VITEST_MAX_WORKERS);
23+
assert.equal(resolveVitestMaxWorkers({ CI: 'true' }), undefined);
1924
});
2025

2126
// Wiring: the scrub only helps if every project loads it as a setup file. CI runs with the

vitest.config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import contentionRetryReporter, {
44
FAILURE_FILE_ENV,
55
} from './scripts/lib/contention-retry-reporter.ts';
66
import { SUBPROCESS_STUB_TESTS } from './scripts/lib/contention-retry.ts';
7-
import { DEFAULT_VITEST_MAX_WORKERS } from './scripts/lib/vitest-concurrency.ts';
7+
import { resolveVitestMaxWorkers } from './scripts/lib/vitest-concurrency.ts';
88
import slowTestGateReporter from './scripts/vitest-slow-test-reporter.ts';
99

1010
// Tests that stub a real binary (adb/xcrun/npx) by mutating process.env.PATH and
@@ -52,8 +52,10 @@ export default defineConfig({
5252
// Vitest otherwise derives 11 workers from this 12-core host. Three
5353
// concurrent Codex worktrees can then request 33 workers and starve the
5454
// subprocess/test-server paths behind exact timeout budgets. Two workers
55-
// per invocation preserves useful parallelism while leaving host headroom.
56-
maxWorkers: DEFAULT_VITEST_MAX_WORKERS,
55+
// per local invocation preserves useful parallelism while leaving host
56+
// headroom. CI stays uncapped so Vitest derives the runner-appropriate
57+
// worker count from the isolated machine's available CPU pool.
58+
maxWorkers: resolveVitestMaxWorkers(),
5759
reporters: reporters(),
5860
projects: [
5961
{

0 commit comments

Comments
 (0)