test: fix Node 24+ test runner and subagent registry mocks

This commit is contained in:
Peter Steinberger
2026-03-09 06:45:02 +00:00
parent 2d55ad05f3
commit 8d2d6db9ad
4 changed files with 28 additions and 16 deletions

View File

@@ -104,11 +104,11 @@ const hostMemoryGiB = Math.floor(os.totalmem() / 1024 ** 3);
const highMemLocalHost = !isCI && hostMemoryGiB >= 96; const highMemLocalHost = !isCI && hostMemoryGiB >= 96;
const lowMemLocalHost = !isCI && hostMemoryGiB < 64; const lowMemLocalHost = !isCI && hostMemoryGiB < 64;
const nodeMajor = Number.parseInt(process.versions.node.split(".")[0] ?? "", 10); const nodeMajor = Number.parseInt(process.versions.node.split(".")[0] ?? "", 10);
// vmForks is a big win for transform/import heavy suites, but Node 24 had // vmForks is a big win for transform/import heavy suites, but Node 24+
// regressions with Vitest's vm runtime in this repo, and low-memory local hosts // regressed with Vitest's vm runtime in this repo, and low-memory local hosts
// are more likely to hit per-worker V8 heap ceilings. Keep it opt-out via // are more likely to hit per-worker V8 heap ceilings. Keep it opt-out via
// OPENCLAW_TEST_VM_FORKS=0, and let users force-enable with =1. // OPENCLAW_TEST_VM_FORKS=0, and let users force-enable with =1.
const supportsVmForks = Number.isFinite(nodeMajor) ? nodeMajor !== 24 : true; const supportsVmForks = Number.isFinite(nodeMajor) ? nodeMajor < 24 : true;
const useVmForks = const useVmForks =
process.env.OPENCLAW_TEST_VM_FORKS === "1" || process.env.OPENCLAW_TEST_VM_FORKS === "1" ||
(process.env.OPENCLAW_TEST_VM_FORKS !== "0" && !isWindows && supportsVmForks && !lowMemLocalHost); (process.env.OPENCLAW_TEST_VM_FORKS !== "0" && !isWindows && supportsVmForks && !lowMemLocalHost);

View File

@@ -17,11 +17,15 @@ vi.mock("../infra/agent-events.js", () => ({
onAgentEvent: vi.fn((_handler: unknown) => noop), onAgentEvent: vi.fn((_handler: unknown) => noop),
})); }));
vi.mock("../config/config.js", () => ({ vi.mock("../config/config.js", async (importOriginal) => {
loadConfig: vi.fn(() => ({ const actual = await importOriginal<typeof import("../config/config.js")>();
agents: { defaults: { subagents: { archiveAfterMinutes: 60 } } }, return {
})), ...actual,
})); loadConfig: vi.fn(() => ({
agents: { defaults: { subagents: { archiveAfterMinutes: 60 } } },
})),
};
});
vi.mock("./subagent-announce.js", () => ({ vi.mock("./subagent-announce.js", () => ({
runSubagentAnnounceFlow: vi.fn(async () => true), runSubagentAnnounceFlow: vi.fn(async () => true),

View File

@@ -49,9 +49,13 @@ vi.mock("../infra/agent-events.js", () => ({
onAgentEvent: onAgentEventMock, onAgentEvent: onAgentEventMock,
})); }));
vi.mock("../config/config.js", () => ({ vi.mock("../config/config.js", async (importOriginal) => {
loadConfig: loadConfigMock, const actual = await importOriginal<typeof import("../config/config.js")>();
})); return {
...actual,
loadConfig: loadConfigMock,
};
});
vi.mock("./subagent-announce.js", () => ({ vi.mock("./subagent-announce.js", () => ({
runSubagentAnnounceFlow: announceSpy, runSubagentAnnounceFlow: announceSpy,

View File

@@ -1,11 +1,15 @@
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest"; import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import "./subagent-registry.mocks.shared.js"; import "./subagent-registry.mocks.shared.js";
vi.mock("../config/config.js", () => ({ vi.mock("../config/config.js", async (importOriginal) => {
loadConfig: vi.fn(() => ({ const actual = await importOriginal<typeof import("../config/config.js")>();
agents: { defaults: { subagents: { archiveAfterMinutes: 0 } } }, return {
})), ...actual,
})); loadConfig: vi.fn(() => ({
agents: { defaults: { subagents: { archiveAfterMinutes: 0 } } },
})),
};
});
vi.mock("./subagent-announce.js", () => ({ vi.mock("./subagent-announce.js", () => ({
runSubagentAnnounceFlow: vi.fn(async () => true), runSubagentAnnounceFlow: vi.fn(async () => true),