Skip to content

Commit 6600930

Browse files
steipeteampagent
andauthored
test: parallelize doctor process coverage (#122563)
Co-authored-by: Amp <[email protected]>
1 parent 7e2ec43 commit 6600930

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

‎src/commands/doctor-config-preflight.process.test.ts‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Process regression for typed gateway startup-migration refusal and lease cleanup.
2-
import { spawnSync } from "node:child_process";
2+
import { execFile, spawnSync } from "node:child_process";
33
import fs from "node:fs";
44
import os from "node:os";
55
import path from "node:path";
66
import { DatabaseSync } from "node:sqlite";
77
import { pathToFileURL } from "node:url";
8-
import { afterEach, describe, expect, it } from "vitest";
8+
import { promisify } from "node:util";
9+
import { afterAll, describe, expect, it } from "vitest";
910
import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js";
1011
import type { OpenClawConfig } from "../config/types.openclaw.js";
1112
import { hasActiveStartupMigrationLease } from "../infra/startup-migration-checkpoint.js";
@@ -14,14 +15,15 @@ const STARTUP_REFUSAL =
1415
"OpenClaw startup migrations did not complete cleanly; refusing to report the gateway ready.";
1516
const STARTUP_RECOVERY =
1617
'Run "openclaw doctor --fix" against the same state/config, then restart the gateway.';
17-
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
18+
const tempDirs = useAutoCleanupTempDirTracker(afterAll);
19+
const execFileAsync = promisify(execFile);
1820

1921
function runIsolatedModuleScript(
2022
env: NodeJS.ProcessEnv,
2123
script: string,
2224
options: { runtimeRoot?: string; timeoutMs?: number } = {},
2325
) {
24-
return spawnSync(
26+
return execFileAsync(
2527
process.execPath,
2628
[
2729
...(options.runtimeRoot ? ["--preserve-symlinks"] : []),
@@ -116,7 +118,7 @@ function seedPluginStateConflict(stateDir: string): void {
116118
}
117119
}
118120

119-
describe("gateway startup-migration refusal", () => {
121+
describe.concurrent("gateway startup-migration refusal", () => {
120122
it("exits cleanly after reporting the refusal once and releasing its lease", async () => {
121123
const temporaryRoot = await fs.promises.mkdtemp(
122124
path.join(os.tmpdir(), "openclaw-startup-migration-exit-"),
@@ -225,10 +227,7 @@ describe("gateway startup-migration refusal", () => {
225227
runtimeRoot,
226228
timeoutMs: 60_000,
227229
});
228-
const readResult = (result: ReturnType<typeof runIsolatedModuleScript>) => {
229-
expect(result.error, `${result.stderr}\n${result.stdout}`).toBeUndefined();
230-
expect(result.status, `${result.stderr}\n${result.stdout}`).toBe(0);
231-
expect(result.signal, `${result.stderr}\n${result.stdout}`).toBeNull();
230+
const readResult = (result: Awaited<ReturnType<typeof runIsolatedModuleScript>>) => {
232231
const resultLine = result.stdout.split("\n").find((line) => line.startsWith("__RESULT__"));
233232
expect(resultLine, `${result.stderr}\n${result.stdout}`).toBeDefined();
234233
return JSON.parse(resultLine!.slice("__RESULT__".length)) as {
@@ -237,8 +236,8 @@ describe("gateway startup-migration refusal", () => {
237236
};
238237
};
239238

240-
const first = readResult(run());
241-
const second = readResult(run());
239+
const first = readResult(await run());
240+
const second = readResult(await run());
242241

243242
expect(first).toEqual({ activeLease: false, stateMigrationsImported: true });
244243
expect(second).toEqual({ activeLease: false, stateMigrationsImported: false });
@@ -306,7 +305,7 @@ describe("gateway startup-migration refusal", () => {
306305
import.meta.url,
307306
).href;
308307
const prompterUrl = new URL("./doctor-prompter.ts", import.meta.url).href;
309-
const result = runIsolatedModuleScript(
308+
const result = await runIsolatedModuleScript(
310309
env,
311310
`
312311
const fs = await import("node:fs");
@@ -356,9 +355,6 @@ describe("gateway startup-migration refusal", () => {
356355
`,
357356
{ timeoutMs: 60_000 },
358357
);
359-
expect(result.error, `${result.stderr}\n${result.stdout}`).toBeUndefined();
360-
expect(result.status, `${result.stderr}\n${result.stdout}`).toBe(0);
361-
expect(result.signal, `${result.stderr}\n${result.stdout}`).toBeNull();
362358
const resultLine = result.stdout.split("\n").find((line) => line.startsWith("__RESULT__"));
363359
expect(resultLine, `${result.stderr}\n${result.stdout}`).toBeDefined();
364360
expect(JSON.parse(resultLine!.slice("__RESULT__".length))).toEqual({

0 commit comments

Comments
 (0)