perf: default unit vitest lanes to threads

This commit is contained in:
Peter Steinberger
2026-03-22 12:24:47 -07:00
parent e64dbb00b3
commit e39d5b9ef8
2 changed files with 236 additions and 220 deletions

View File

@@ -85,14 +85,13 @@ const testProfile =
const isMacMiniProfile = testProfile === "macmini";
// Vitest executes Node tests through Vite's SSR/module-runner pipeline, so the
// shared unit lane still retains transformed ESM/module state even when the
// tests themselves are not "server rendering" a website. vmForks can win in
// ideal transform-heavy cases, but for this repo we measured higher aggregate
// CPU load and fatal heap OOMs on memory-constrained dev machines and CI when
// unit-fast stayed on vmForks. Keep forks as the default unless that evidence
// is re-run and replaced:
// PR: https://github.com/openclaw/openclaw/pull/51145
// OOM evidence: https://github.com/openclaw/openclaw/pull/51145#issuecomment-4099663958
// Preserve OPENCLAW_TEST_VM_FORKS=1 as the explicit override/debug escape hatch.
// tests themselves are not "server rendering" a website. We previously kept
// forks as the default after vmFork OOM regressions on constrained hosts. On
// 2026-03-22, a direct full-unit threads run finished 1109/1110 green; the sole
// correctness exception stayed on the manifest fork lane, so the wrapper now
// defaults unit runs to threads while preserving explicit fork/vmFork escapes.
// Preserve OPENCLAW_TEST_UNIT_DEFAULT_POOL=forks or OPENCLAW_TEST_VM_FORKS=1 as
// explicit debug escape hatches.
const supportsVmForks = Number.isFinite(nodeMajor) ? nodeMajor <= 24 : true;
const useVmForks = process.env.OPENCLAW_TEST_VM_FORKS === "1" && supportsVmForks;
const forceIsolation =
@@ -103,6 +102,15 @@ const disableIsolation =
process.env.OPENCLAW_TEST_NO_ISOLATE !== "false";
const includeGatewaySuite = process.env.OPENCLAW_TEST_INCLUDE_GATEWAY === "1";
const includeExtensionsSuite = process.env.OPENCLAW_TEST_INCLUDE_EXTENSIONS === "1";
const parsePoolOverride = (value, fallback) => {
if (value === "threads" || value === "forks") {
return value;
}
if (value === "vmForks") {
return supportsVmForks ? value : "forks";
}
return fallback;
};
// Even on low-memory hosts, keep the isolated lane split so files like
// git-commit.test.ts still get the worker/process isolation they require.
const shouldSplitUnitRuns = testProfile !== "serial";
@@ -263,8 +271,16 @@ const allKnownTestFiles = [
...walkTestFiles(path.join("ui", "src", "ui")),
]),
];
const defaultUnitPool = parsePoolOverride(process.env.OPENCLAW_TEST_UNIT_DEFAULT_POOL, "threads");
const isTargetedIsolatedUnitFile = (fileFilter) =>
unitBehaviorIsolatedFiles.includes(fileFilter) ||
unitSingletonBatchFiles.includes(fileFilter) ||
unitMemorySingletonFiles.includes(fileFilter);
const inferTarget = (fileFilter) => {
const isolated = unitBehaviorIsolatedFiles.includes(fileFilter);
const isolated = isTargetedIsolatedUnitFile(fileFilter);
if (isUnitConfigTestFile(fileFilter)) {
return { owner: "unit", isolated };
}
if (fileFilter.endsWith(".live.test.ts")) {
return { owner: "live", isolated };
}
@@ -465,7 +481,7 @@ const unitFastEntries = unitFastBuckets.flatMap((files, index) => {
"run",
"--config",
"vitest.unit.config.ts",
`--pool=${useVmForks ? "vmForks" : "forks"}`,
`--pool=${defaultUnitPool}`,
...(disableIsolation ? ["--isolate=false"] : []),
],
}));
@@ -638,7 +654,7 @@ const createTargetedEntry = (owner, isolated, filters) => {
"run",
"--config",
"vitest.unit.config.ts",
`--pool=${forceForks ? "forks" : useVmForks ? "vmForks" : "forks"}`,
`--pool=${forceForks ? "forks" : defaultUnitPool}`,
...(disableIsolation ? ["--isolate=false"] : []),
...filters,
],