From 4846ebce12dcf0ce03a8079b06ec7666e7296fd0 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 3 Apr 2026 21:07:56 +0900 Subject: [PATCH] fix(test): serialize local heavy checks (#60273) --- scripts/test-projects.mjs | 18 ++++++++++++++++++ test/setup.shared.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/test-projects.mjs b/scripts/test-projects.mjs index 2b5bb949b69..e638f6792d7 100644 --- a/scripts/test-projects.mjs +++ b/scripts/test-projects.mjs @@ -1,8 +1,24 @@ import { spawn } from "node:child_process"; +import { acquireLocalHeavyCheckLockSync } from "./lib/local-heavy-check-runtime.mjs"; import { buildVitestArgs } from "./test-projects.test-support.mjs"; const command = process.platform === "win32" ? "pnpm.cmd" : "pnpm"; const vitestArgs = buildVitestArgs(process.argv.slice(2)); +const releaseLock = acquireLocalHeavyCheckLockSync({ + cwd: process.cwd(), + env: process.env, + lockName: "test", + toolName: "test", +}); +let lockReleased = false; + +const releaseLockOnce = () => { + if (lockReleased) { + return; + } + lockReleased = true; + releaseLock(); +}; const child = spawn(command, vitestArgs, { stdio: "inherit", @@ -10,6 +26,7 @@ const child = spawn(command, vitestArgs, { }); child.on("exit", (code, signal) => { + releaseLockOnce(); if (signal) { process.kill(process.pid, signal); return; @@ -18,6 +35,7 @@ child.on("exit", (code, signal) => { }); child.on("error", (error) => { + releaseLockOnce(); console.error(error); process.exit(1); }); diff --git a/test/setup.shared.ts b/test/setup.shared.ts index 15a4857d22e..71a533cee72 100644 --- a/test/setup.shared.ts +++ b/test/setup.shared.ts @@ -36,7 +36,7 @@ process.env.VITEST = "true"; // Config validation walks plugin manifests; keep an aggressive cache in tests to avoid // repeated filesystem discovery across suites/workers. process.env.OPENCLAW_PLUGIN_MANIFEST_CACHE_MS ??= "60000"; -// Vitest vm forks can load transitive lockfile helpers many times per worker. +// Vitest fork workers can load transitive lockfile helpers many times per worker. // Raise listener budget to avoid noisy MaxListeners warnings and warning-stack overhead. const TEST_PROCESS_MAX_LISTENERS = 128; if (process.getMaxListeners() > 0 && process.getMaxListeners() < TEST_PROCESS_MAX_LISTENERS) {