test: share qa docker healthy deps

This commit is contained in:
Peter Steinberger
2026-04-20 18:06:58 +01:00
parent f76b426e2b
commit b97f993b0c

View File

@@ -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<Parameters<typeof runQaDockerUp>[1]>;
async function occupyPortOrAcceptExisting(port: number): Promise<{ close: () => Promise<void> }> {
const server = createServer();
const listening = await new Promise<boolean>((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"));