fix(test): default local Vitest to one worker (#60281)

This commit is contained in:
Vincent Koc 2026-04-03 21:18:12 +09:00 committed by GitHub
parent 69da71c0ce
commit 4e60653959
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 24 deletions

View File

@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
import baseConfig, { resolveLocalVitestMaxWorkers } from "../vitest.config.ts";
describe("resolveLocalVitestMaxWorkers", () => {
it("derives a moderate local cap for 64 GiB hosts", () => {
it("defaults local runs to a single worker even on larger hosts", () => {
expect(
resolveLocalVitestMaxWorkers(
{
@ -13,7 +13,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 64 * 1024 ** 3,
},
),
).toBe(4);
).toBe(1);
});
it("lets OPENCLAW_VITEST_MAX_WORKERS override the inferred cap", () => {
@ -45,7 +45,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
).toBe(3);
});
it("keeps memory-constrained hosts conservative", () => {
it("keeps memory-constrained hosts on the same single-worker default", () => {
expect(
resolveLocalVitestMaxWorkers(
{},
@ -54,10 +54,10 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 16 * 1024 ** 3,
},
),
).toBe(2);
).toBe(1);
});
it("lets roomy hosts use a higher default cap", () => {
it("keeps roomy hosts on the same single-worker default", () => {
expect(
resolveLocalVitestMaxWorkers(
{},
@ -66,7 +66,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 128 * 1024 ** 3,
},
),
).toBe(6);
).toBe(1);
});
});

View File

@ -1,4 +1,3 @@
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig } from "vitest/config";
@ -16,27 +15,12 @@ function parsePositiveInt(value) {
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
}
export function resolveLocalVitestMaxWorkers(
env = process.env,
system = {
cpuCount: os.cpus().length || 1,
totalMemoryBytes: os.totalmem(),
},
) {
export function resolveLocalVitestMaxWorkers(env = process.env, _system = undefined) {
const override = parsePositiveInt(env.OPENCLAW_VITEST_MAX_WORKERS ?? env.OPENCLAW_TEST_WORKERS);
if (override !== null) {
return clamp(override, 1, 16);
}
const cpuCount = Math.max(1, system.cpuCount || 1);
const memoryGiB = (system.totalMemoryBytes || 0) / 1024 ** 3;
let workers = cpuCount >= 16 ? 6 : cpuCount >= 10 ? 4 : cpuCount >= 6 ? 3 : 2;
if (memoryGiB < 24) {
workers = Math.min(workers, 2);
} else if (memoryGiB < 48) {
workers = Math.min(workers, 3);
}
return clamp(workers, 1, 16);
return 1;
}
const repoRoot = path.dirname(fileURLToPath(import.meta.url));