diff --git a/extensions/qa-lab/src/docker-up.runtime.test.ts b/extensions/qa-lab/src/docker-up.runtime.test.ts index 320a6e6f357..a224def4298 100644 --- a/extensions/qa-lab/src/docker-up.runtime.test.ts +++ b/extensions/qa-lab/src/docker-up.runtime.test.ts @@ -5,6 +5,8 @@ import path from "node:path"; import { describe, expect, it, vi } from "vitest"; import { runQaDockerUp } from "./docker-up.runtime.js"; +type QaDockerUpDeps = NonNullable[1]>; + async function occupyPortOrAcceptExisting(port: number): Promise<{ close: () => Promise }> { const server = createServer(); const listening = await new Promise((resolve, reject) => { @@ -30,6 +32,20 @@ async function occupyPortOrAcceptExisting(port: number): Promise<{ close: () => }; } +function createHealthyDockerDeps(calls: string[]): QaDockerUpDeps { + return { + async runCommand(command, args, cwd) { + calls.push([command, ...args, `@${cwd}`].join(" ")); + if (args.join(" ").includes("ps --format json openclaw-qa-gateway")) { + return { stdout: '{"Health":"healthy","State":"running"}\n', stderr: "" }; + } + return { stdout: "", stderr: "" }; + }, + fetchImpl: vi.fn(async () => ({ ok: true })), + sleepImpl: vi.fn(async () => {}), + }; +} + describe("runQaDockerUp", () => { it("builds the QA UI, writes the harness, starts compose, and waits for health", async () => { const calls: string[] = []; @@ -96,17 +112,7 @@ describe("runQaDockerUp", () => { bindUiDist: true, skipUiBuild: true, }, - { - async runCommand(command, args, cwd) { - calls.push([command, ...args, `@${cwd}`].join(" ")); - if (args.join(" ").includes("ps --format json openclaw-qa-gateway")) { - return { stdout: '{"Health":"healthy","State":"running"}\n', stderr: "" }; - } - return { stdout: "", stderr: "" }; - }, - fetchImpl: vi.fn(async () => ({ ok: true })), - sleepImpl: vi.fn(async () => {}), - }, + createHealthyDockerDeps(calls), ); expect(calls).toEqual([ @@ -133,17 +139,7 @@ describe("runQaDockerUp", () => { usePrebuiltImage: true, skipUiBuild: true, }, - { - async runCommand(command, args, cwd) { - calls.push([command, ...args, `@${cwd}`].join(" ")); - if (args.join(" ").includes("ps --format json openclaw-qa-gateway")) { - return { stdout: '{"Health":"healthy","State":"running"}\n', stderr: "" }; - } - return { stdout: "", stderr: "" }; - }, - fetchImpl: vi.fn(async () => ({ ok: true })), - sleepImpl: vi.fn(async () => {}), - }, + createHealthyDockerDeps(calls), ); expect(result.outputDir).toBe(path.join(repoRoot, ".artifacts/qa-docker"));