From 4e60653959b992c8cd3b17e45dd583145a9ed88c Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 3 Apr 2026 21:18:12 +0900 Subject: [PATCH] fix(test): default local Vitest to one worker (#60281) --- test/vitest-config.test.ts | 12 ++++++------ vitest.config.ts | 20 ++------------------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/test/vitest-config.test.ts b/test/vitest-config.test.ts index 61b33abf1a8..ec41399a2c4 100644 --- a/test/vitest-config.test.ts +++ b/test/vitest-config.test.ts @@ -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); }); }); diff --git a/vitest.config.ts b/vitest.config.ts index e261bca57be..3293583112f 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -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));