fix(test): cap native worker pools for serial Vitest

This commit is contained in:
Vincent Koc
2026-04-25 01:29:11 -07:00
parent bc21f500d4
commit 734748d4f4
3 changed files with 70 additions and 2 deletions

View File

@@ -40,12 +40,42 @@ export function resolveVitestNoOutputTimeoutMs(env = process.env) {
export function resolveVitestSpawnParams(env = process.env, platform = process.platform) {
return {
env,
env: resolveVitestSpawnEnv(env),
detached: shouldUseDetachedVitestProcessGroup(platform),
stdio: ["inherit", "pipe", "pipe"],
};
}
export function resolveVitestSpawnEnv(env = process.env) {
if (!shouldApplyNativeWorkerBudget(env)) {
return env;
}
const nativeWorkerCount = String(resolveNativeWorkerCount(env));
return {
...env,
RAYON_NUM_THREADS: env.RAYON_NUM_THREADS?.trim() || nativeWorkerCount,
TOKIO_WORKER_THREADS: env.TOKIO_WORKER_THREADS?.trim() || nativeWorkerCount,
};
}
function shouldApplyNativeWorkerBudget(env) {
if (env.RAYON_NUM_THREADS?.trim() && env.TOKIO_WORKER_THREADS?.trim()) {
return false;
}
return (
env.OPENCLAW_TEST_PROJECTS_SERIAL === "1" || resolveExplicitVitestWorkerBudget(env) !== null
);
}
function resolveNativeWorkerCount(env) {
return Math.min(resolveExplicitVitestWorkerBudget(env) ?? 1, 4);
}
function resolveExplicitVitestWorkerBudget(env) {
return parsePositiveInt(env.OPENCLAW_VITEST_MAX_WORKERS ?? env.OPENCLAW_TEST_WORKERS);
}
export function shouldSuppressVitestStderrLine(line) {
return SUPPRESSED_VITEST_STDERR_PATTERNS.some((pattern) => line.includes(pattern));
}

View File

@@ -230,7 +230,11 @@ const TOOLING_SOURCE_TEST_TARGETS = new Map([
["scripts/lib/vitest-local-scheduling.mjs", ["test/scripts/vitest-local-scheduling.test.ts"]],
[
"scripts/run-vitest.mjs",
["test/scripts/test-projects.test.ts", "test/scripts/vitest-local-scheduling.test.ts"],
[
"test/scripts/run-vitest.test.ts",
"test/scripts/test-projects.test.ts",
"test/scripts/vitest-local-scheduling.test.ts",
],
],
["scripts/run-oxlint.mjs", ["test/scripts/run-oxlint.test.ts"]],
["scripts/test-extension-batch.mjs", ["test/scripts/test-extension.test.ts"]],