diff --git a/scripts/test-planner/executor.mjs b/scripts/test-planner/executor.mjs index 343547feea5..761d81a77dd 100644 --- a/scripts/test-planner/executor.mjs +++ b/scripts/test-planner/executor.mjs @@ -343,6 +343,7 @@ const partitionUnitsBySurface = (units, surface) => { export async function executePlan(plan, options = {}) { const env = options.env ?? process.env; const artifacts = options.artifacts ?? createExecutionArtifacts(env); + const spawnImpl = options.spawn ?? spawn; const pnpmInvocation = resolvePnpmCommandInvocation({ npmExecPath: env.npm_execpath, nodeExecPath: process.execPath, @@ -740,7 +741,7 @@ export async function executePlan(plan, options = {}) { childEnv.OPENCLAW_VITEST_FS_MODULE_CACHE_PATH = vitestFsModuleCachePath; laneLogStream.write(`[test-parallel] fsModuleCachePath=${vitestFsModuleCachePath}\n`); } - child = spawn(pnpmInvocation.command, spawnArgs, { + child = spawnImpl(pnpmInvocation.command, spawnArgs, { stdio: ["inherit", "pipe", "pipe"], env: childEnv, shell: false, diff --git a/test/scripts/test-planner.executor-fallback.test.ts b/test/scripts/test-planner.executor-fallback.test.ts index 91678863c77..b8dbe3ce51b 100644 --- a/test/scripts/test-planner.executor-fallback.test.ts +++ b/test/scripts/test-planner.executor-fallback.test.ts @@ -1,7 +1,7 @@ import { EventEmitter } from "node:events"; import { PassThrough } from "node:stream"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import { importFreshModule } from "../helpers/import-fresh.js"; +import { createExecutionArtifacts, executePlan } from "../../scripts/test-planner/executor.mjs"; beforeEach(() => { vi.spyOn(console, "log").mockImplementation(() => {}); @@ -13,7 +13,6 @@ beforeEach(() => { afterEach(() => { vi.useRealTimers(); vi.restoreAllMocks(); - vi.resetModules(); }); describe("test planner executor", () => { @@ -33,13 +32,6 @@ describe("test planner executor", () => { }, 0); return fakeChild; }); - vi.doMock("node:child_process", () => ({ - spawn: spawnMock, - })); - - const { executePlan, createExecutionArtifacts } = await importFreshModule< - typeof import("../../scripts/test-planner/executor.mjs") - >(import.meta.url, "../../scripts/test-planner/executor.mjs?scope=exit-fallback"); const artifacts = createExecutionArtifacts({ OPENCLAW_TEST_CLOSE_GRACE_MS: "10" }); const executePromise = executePlan( { @@ -51,6 +43,7 @@ describe("test planner executor", () => { { env: { OPENCLAW_TEST_CLOSE_GRACE_MS: "10" }, artifacts, + spawn: spawnMock, }, ); @@ -93,13 +86,6 @@ describe("test planner executor", () => { }, 0); return child; }); - vi.doMock("node:child_process", () => ({ - spawn: spawnMock, - })); - - const { executePlan, createExecutionArtifacts } = await importFreshModule< - typeof import("../../scripts/test-planner/executor.mjs") - >(import.meta.url, "../../scripts/test-planner/executor.mjs?scope=collect-all"); const artifacts = createExecutionArtifacts({}); const report = await executePlan( { @@ -125,6 +111,7 @@ describe("test planner executor", () => { { env: {}, artifacts, + spawn: spawnMock, }, ); @@ -159,13 +146,6 @@ describe("test planner executor", () => { }, 0); return fakeChild; }); - vi.doMock("node:child_process", () => ({ - spawn: spawnMock, - })); - - const { executePlan, createExecutionArtifacts } = await importFreshModule< - typeof import("../../scripts/test-planner/executor.mjs") - >(import.meta.url, "../../scripts/test-planner/executor.mjs?scope=localstorage-file"); const artifacts = createExecutionArtifacts({ NODE_OPTIONS: "--max_old_space_size=4096 --localstorage-file", }); @@ -193,6 +173,7 @@ describe("test planner executor", () => { NODE_OPTIONS: "--max_old_space_size=4096 --localstorage-file", }, artifacts, + spawn: spawnMock, }, ), ).resolves.toMatchObject({