fix(test): prevent Vitest shard stalls

This commit is contained in:
Peter Steinberger
2026-04-23 06:20:22 +01:00
parent e6d0342629
commit ebf351b138
6 changed files with 210 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import { EventEmitter } from "node:events";
import { describe, expect, it, vi } from "vitest";
import {
installVitestNoOutputWatchdog,
resolveDirectNodeVitestArgs,
resolveVitestNodeArgs,
resolveVitestNoOutputTimeoutMs,
resolveVitestSpawnParams,
@@ -13,6 +14,18 @@ describe("scripts/run-vitest", () => {
expect(resolveVitestNodeArgs({ PATH: "/usr/bin" })).toEqual(["--no-maglev"]);
});
it("detects pnpm exec node wrappers that can be spawned directly", () => {
expect(
resolveDirectNodeVitestArgs([
"exec",
"node",
"--no-maglev",
"node_modules/vitest/vitest.mjs",
]),
).toEqual(["--no-maglev", "node_modules/vitest/vitest.mjs"]);
expect(resolveDirectNodeVitestArgs(["exec", "vitest", "run"])).toBeNull();
});
it("allows opting back into Maglev explicitly", () => {
expect(
resolveVitestNodeArgs({

View File

@@ -1,6 +1,9 @@
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
DEFAULT_TEST_PROJECTS_VITEST_NO_OUTPUT_TIMEOUT_MS,
applyDefaultMultiSpecVitestCachePaths,
applyDefaultVitestNoOutputTimeout,
applyParallelVitestCachePaths,
buildFullSuiteVitestRunPlans,
buildVitestRunPlans,
@@ -807,3 +810,127 @@ describe("scripts/test-projects parallel cache paths", () => {
expect(spec?.env.OPENCLAW_VITEST_FS_MODULE_CACHE_PATH).toBeUndefined();
});
});
describe("scripts/test-projects Vitest stall watchdog", () => {
it("adds a default no-output timeout to non-watch specs", () => {
const [spec] = applyDefaultVitestNoOutputTimeout(
[
{
config: "test/vitest/vitest.extension-feishu.config.ts",
env: { PATH: "/usr/bin" },
includeFilePath: null,
includePatterns: null,
pnpmArgs: [],
watchMode: false,
},
],
{ env: { PATH: "/usr/bin" } },
);
expect(spec?.env.OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS).toBe(
DEFAULT_TEST_PROJECTS_VITEST_NO_OUTPUT_TIMEOUT_MS,
);
});
it("keeps explicit watchdog settings and watch mode untouched", () => {
const specs = applyDefaultVitestNoOutputTimeout(
[
{
config: "test/vitest/vitest.extension-feishu.config.ts",
env: { PATH: "/usr/bin" },
includeFilePath: null,
includePatterns: null,
pnpmArgs: [],
watchMode: true,
},
{
config: "test/vitest/vitest.extension-memory.config.ts",
env: { OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS: "0", PATH: "/usr/bin" },
includeFilePath: null,
includePatterns: null,
pnpmArgs: [],
watchMode: false,
},
],
{ env: { PATH: "/usr/bin" } },
);
expect(specs[0]?.env.OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS).toBeUndefined();
expect(specs[1]?.env.OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS).toBe("0");
});
});
describe("scripts/test-projects Vitest cache isolation", () => {
it("assigns isolated fs-module caches to multi-spec non-watch runs", () => {
const specs = applyDefaultMultiSpecVitestCachePaths(
[
{
config: "test/vitest/vitest.unit-fast.config.ts",
env: {},
includeFilePath: null,
includePatterns: null,
pnpmArgs: [],
watchMode: false,
},
{
config: "test/vitest/vitest.extension-memory.config.ts",
env: {},
includeFilePath: null,
includePatterns: null,
pnpmArgs: [],
watchMode: false,
},
],
{ cwd: "/repo", env: {} },
);
expect(specs.map((spec) => spec.env.OPENCLAW_VITEST_FS_MODULE_CACHE_PATH)).toEqual([
path.join(
"/repo",
"node_modules",
".experimental-vitest-cache",
"0-test-vitest-vitest.unit-fast.config.ts",
),
path.join(
"/repo",
"node_modules",
".experimental-vitest-cache",
"1-test-vitest-vitest.extension-memory.config.ts",
),
]);
});
it("keeps single-spec and watch runs on the default cache", () => {
const single = [
{
config: "test/vitest/vitest.unit-fast.config.ts",
env: {},
includeFilePath: null,
includePatterns: null,
pnpmArgs: [],
watchMode: false,
},
];
expect(applyDefaultMultiSpecVitestCachePaths(single, { cwd: "/repo", env: {} })).toBe(single);
const watch = [
{
config: "vitest.config.ts",
env: {},
includeFilePath: null,
includePatterns: null,
pnpmArgs: [],
watchMode: true,
},
{
config: "test/vitest/vitest.unit-fast.config.ts",
env: {},
includeFilePath: null,
includePatterns: null,
pnpmArgs: [],
watchMode: false,
},
];
expect(applyDefaultMultiSpecVitestCachePaths(watch, { cwd: "/repo", env: {} })).toBe(watch);
});
});