qa-lab: parse compose ps json arrays

This commit is contained in:
Gustavo Madeira Santana
2026-04-10 19:15:42 -04:00
parent 08de16d138
commit ae9bb37751
3 changed files with 26 additions and 8 deletions

View File

@@ -174,6 +174,29 @@ function normalizeDockerServiceStatus(row?: { Health?: string; State?: string })
return "unknown";
}
function parseDockerComposePsRows(stdout: string) {
const trimmed = stdout.trim();
if (!trimmed) {
return [] as Array<{ Health?: string; State?: string }>;
}
try {
const parsed = JSON.parse(trimmed) as
| Array<{ Health?: string; State?: string }>
| { Health?: string; State?: string };
if (Array.isArray(parsed)) {
return parsed;
}
return [parsed];
} catch {
return trimmed
.split("\n")
.map((line) => line.trim())
.filter(Boolean)
.map((line) => JSON.parse(line) as { Health?: string; State?: string });
}
}
export async function waitForDockerServiceHealth(
service: string,
composeFile: string,
@@ -194,12 +217,7 @@ export async function waitForDockerServiceHealth(
["compose", "-f", composeFile, "ps", "--format", "json", service],
repoRoot,
);
const rows = stdout
.trim()
.split("\n")
.map((line) => line.trim())
.filter(Boolean)
.map((line) => JSON.parse(line) as { Health?: string; State?: string });
const rows = parseDockerComposePsRows(stdout);
const row = rows[0];
lastStatus = normalizeDockerServiceStatus(row);
if (lastStatus === "healthy" || lastStatus === "running") {

View File

@@ -49,7 +49,7 @@ describe("runQaDockerUp", () => {
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: '[{"Health":"healthy","State":"running"}]\n', stderr: "" };
}
return { stdout: "", stderr: "" };
},

View File

@@ -62,7 +62,7 @@ describe("matrix harness runtime", () => {
async runCommand(command, args, cwd) {
calls.push([command, ...args, `@${cwd}`].join(" "));
if (args.join(" ").includes("ps --format json")) {
return { stdout: '{"State":"running"}\n', stderr: "" };
return { stdout: '[{"State":"running"}]\n', stderr: "" };
}
return { stdout: "", stderr: "" };
},