Skip to content

Commit c32ba17

Browse files
committed
fix(qa): fail unsuccessful self-checks
1 parent e64379d commit c32ba17

7 files changed

Lines changed: 158 additions & 8 deletions

File tree

‎extensions/qa-lab/api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export {
8181
} from "./src/scenario-catalog.js";
8282
export { createQaSelfCheckScenario } from "./src/self-check-scenario.js";
8383
export {
84+
isQaSelfCheckSuccessful,
8485
type QaSelfCheckResult,
8586
resolveQaSelfCheckOutputPath,
8687
runQaSelfCheckAgainstState,

‎extensions/qa-lab/src/cli.runtime.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ describe("qa cli runtime", () => {
284284
baseUrl: "http://127.0.0.1:58000",
285285
runSelfCheck: vi.fn().mockResolvedValue({
286286
outputPath: "/tmp/report.md",
287+
report: "",
288+
checks: [{ name: "QA self-check scenario", status: "pass" }],
289+
scenarioResult: {
290+
name: "QA self-check scenario",
291+
status: "pass",
292+
steps: [],
293+
},
287294
}),
288295
stop: vi.fn(),
289296
});
@@ -2154,6 +2161,33 @@ describe("qa cli runtime", () => {
21542161
});
21552162
});
21562163

2164+
it("fails unsuccessful self-checks after stopping the lab server", async () => {
2165+
const stop = vi.fn();
2166+
startQaLabServer.mockResolvedValueOnce({
2167+
baseUrl: "http://127.0.0.1:58000",
2168+
runSelfCheck: vi.fn().mockResolvedValue({
2169+
outputPath: "/tmp/failed-report.md",
2170+
report: "",
2171+
checks: [{ name: "QA self-check scenario", status: "fail" }],
2172+
scenarioResult: {
2173+
name: "QA self-check scenario",
2174+
status: "fail",
2175+
steps: [],
2176+
},
2177+
}),
2178+
stop,
2179+
});
2180+
2181+
await expect(
2182+
runQaLabSelfCheckCommand({
2183+
repoRoot: "/tmp/openclaw-repo",
2184+
}),
2185+
).rejects.toThrow("QA self-check failed. See /tmp/failed-report.md.");
2186+
2187+
expect(stop).toHaveBeenCalledOnce();
2188+
expectWriteContains(stdoutWrite, "QA self-check report: /tmp/failed-report.md");
2189+
});
2190+
21572191
it("resolves docker scaffold paths relative to the explicit repo root", async () => {
21582192
await runQaDockerScaffoldCommand({
21592193
repoRoot: "/tmp/openclaw-repo",

‎extensions/qa-lab/src/cli.runtime.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import {
7474
type QaScorecardCategoryCoverageReport,
7575
type QaScorecardEvidenceMode,
7676
} from "./scorecard-taxonomy.js";
77+
import { isQaSelfCheckSuccessful } from "./self-check.js";
7778
import { runQaFlowSuiteFromRuntime, runQaSuite } from "./suite-launch.runtime.js";
7879
import { scenarioMatchesQaProviderLane } from "./suite-planning.js";
7980
import { readQaSuiteFailedOrSkippedScenarioCountFromFile } from "./suite-summary.js";
@@ -617,6 +618,9 @@ export async function runQaLabSelfCheckCommand(opts: QaLabSelfCheckCommandOption
617618
try {
618619
const result = await server.runSelfCheck();
619620
process.stdout.write(`QA self-check report: ${result.outputPath}\n`);
621+
if (!isQaSelfCheckSuccessful(result)) {
622+
throw new Error(`QA self-check failed. See ${result.outputPath}.`);
623+
}
620624
} finally {
621625
await server.stop();
622626
}

‎extensions/qa-lab/src/self-check.test.ts‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
11
// Qa Lab tests cover self check plugin behavior.
22
import path from "node:path";
33
import { describe, expect, it } from "vitest";
4-
import { resolveQaSelfCheckOutputPath } from "./self-check.js";
4+
import type { QaSelfCheckResult } from "./self-check.js";
5+
import { isQaSelfCheckSuccessful, resolveQaSelfCheckOutputPath } from "./self-check.js";
6+
7+
function makeSelfCheckResult(params: {
8+
scenarioStatus: "pass" | "fail";
9+
checkStatuses: Array<"pass" | "fail">;
10+
}): QaSelfCheckResult {
11+
return {
12+
outputPath: "/tmp/qa-self-check.md",
13+
report: "",
14+
checks: params.checkStatuses.map((status, index) => ({
15+
name: `check ${String(index + 1)}`,
16+
status,
17+
})),
18+
scenarioResult: {
19+
name: "QA self-check scenario",
20+
status: params.scenarioStatus,
21+
steps: [],
22+
},
23+
};
24+
}
25+
26+
describe("isQaSelfCheckSuccessful", () => {
27+
it("requires the scenario and every check to pass", () => {
28+
expect(
29+
isQaSelfCheckSuccessful(
30+
makeSelfCheckResult({ scenarioStatus: "pass", checkStatuses: ["pass"] }),
31+
),
32+
).toBe(true);
33+
expect(
34+
isQaSelfCheckSuccessful(
35+
makeSelfCheckResult({ scenarioStatus: "fail", checkStatuses: ["pass"] }),
36+
),
37+
).toBe(false);
38+
expect(
39+
isQaSelfCheckSuccessful(
40+
makeSelfCheckResult({ scenarioStatus: "pass", checkStatuses: ["pass", "fail"] }),
41+
),
42+
).toBe(false);
43+
});
44+
});
545

646
describe("resolveQaSelfCheckOutputPath", () => {
747
it("keeps explicit output paths untouched", () => {

‎extensions/qa-lab/src/self-check.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export type QaSelfCheckResult = {
1515
scenarioResult: QaScenarioResult;
1616
};
1717

18+
export function isQaSelfCheckSuccessful(result: QaSelfCheckResult): boolean {
19+
return (
20+
result.scenarioResult.status === "pass" &&
21+
result.checks.every((check) => check.status === "pass")
22+
);
23+
}
24+
1825
export function resolveQaSelfCheckOutputPath(params?: { outputPath?: string; repoRoot?: string }) {
1926
if (params?.outputPath) {
2027
return params.outputPath;

‎scripts/qa-e2e.ts‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
// Qa E2E script supports OpenClaw repository automation.
22
import { pathToFileURL } from "node:url";
33

4+
type QaE2eRuntime = Pick<
5+
typeof import("../extensions/qa-lab/api.js"),
6+
"isQaSelfCheckSuccessful" | "runQaE2eSelfCheck"
7+
>;
8+
9+
type QaE2eDeps = {
10+
env?: NodeJS.ProcessEnv;
11+
loadRuntime?: () => Promise<QaE2eRuntime>;
12+
writeStdout?: (text: string) => void;
13+
};
14+
15+
async function loadQaE2eRuntime(): Promise<QaE2eRuntime> {
16+
return await import("../extensions/qa-lab/api.js");
17+
}
18+
419
export function enablePrivateQaScriptEnv(env: NodeJS.ProcessEnv = process.env) {
520
env.OPENCLAW_BUILD_PRIVATE_QA = "1";
621
env.OPENCLAW_ENABLE_PRIVATE_QA_CLI = "1";
@@ -11,11 +26,19 @@ export function resolveQaE2eOutputPath(argv: readonly string[] = process.argv.sl
1126
return argv[0]?.trim() || ".artifacts/qa-e2e/self-check.md";
1227
}
1328

14-
export async function main(argv: readonly string[] = process.argv.slice(2)) {
15-
enablePrivateQaScriptEnv();
16-
const { runQaE2eSelfCheck } = await import("../extensions/qa-lab/api.js");
29+
export async function main(
30+
argv: readonly string[] = process.argv.slice(2),
31+
deps: QaE2eDeps = {},
32+
): Promise<number> {
33+
enablePrivateQaScriptEnv(deps.env ?? process.env);
34+
const { isQaSelfCheckSuccessful, runQaE2eSelfCheck } = await (
35+
deps.loadRuntime ?? loadQaE2eRuntime
36+
)();
1737
const result = await runQaE2eSelfCheck({ outputPath: resolveQaE2eOutputPath(argv) });
18-
process.stdout.write(`QA self-check report: ${result.outputPath}\n`);
38+
(deps.writeStdout ?? ((text: string) => process.stdout.write(text)))(
39+
`QA self-check report: ${result.outputPath}\n`,
40+
);
41+
return isQaSelfCheckSuccessful(result) ? 0 : 1;
1942
}
2043

2144
function isMainModule() {
@@ -24,5 +47,5 @@ function isMainModule() {
2447
}
2548

2649
if (isMainModule()) {
27-
await main();
50+
process.exitCode = await main();
2851
}

‎test/scripts/qa-e2e.test.ts‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
// Qa E2E tests cover qa e2e script behavior.
2-
import { describe, expect, it } from "vitest";
3-
import { enablePrivateQaScriptEnv, resolveQaE2eOutputPath } from "../../scripts/qa-e2e.js";
2+
import { describe, expect, it, vi } from "vitest";
3+
import type { QaSelfCheckResult } from "../../extensions/qa-lab/api.js";
4+
import { enablePrivateQaScriptEnv, main, resolveQaE2eOutputPath } from "../../scripts/qa-e2e.js";
5+
6+
function makeSelfCheckResult(status: "pass" | "fail"): QaSelfCheckResult {
7+
return {
8+
outputPath: "/tmp/qa-self-check.md",
9+
report: "",
10+
checks: [{ name: "QA self-check scenario", status }],
11+
scenarioResult: {
12+
name: "QA self-check scenario",
13+
status,
14+
steps: [],
15+
},
16+
};
17+
}
418

519
describe("qa-e2e script", () => {
620
it("enables private QA plugin SDK subpaths before loading QA Lab", () => {
@@ -31,4 +45,31 @@ describe("qa-e2e script", () => {
3145
expect(resolveQaE2eOutputPath([])).toBe(".artifacts/qa-e2e/self-check.md");
3246
expect(resolveQaE2eOutputPath([".artifacts/custom.md"])).toBe(".artifacts/custom.md");
3347
});
48+
49+
it.each([
50+
{ status: "pass" as const, exitCode: 0 },
51+
{ status: "fail" as const, exitCode: 1 },
52+
])("exits with $exitCode when the self-check status is $status", async ({ status, exitCode }) => {
53+
const result = makeSelfCheckResult(status);
54+
const runQaE2eSelfCheck = vi.fn(async () => result);
55+
const isQaSelfCheckSuccessful = vi.fn(() => status === "pass");
56+
const writeStdout = vi.fn();
57+
const env: NodeJS.ProcessEnv = {};
58+
59+
await expect(
60+
main([".artifacts/custom.md"], {
61+
env,
62+
loadRuntime: async () => ({
63+
isQaSelfCheckSuccessful,
64+
runQaE2eSelfCheck,
65+
}),
66+
writeStdout,
67+
}),
68+
).resolves.toBe(exitCode);
69+
70+
expect(runQaE2eSelfCheck).toHaveBeenCalledWith({ outputPath: ".artifacts/custom.md" });
71+
expect(isQaSelfCheckSuccessful).toHaveBeenCalledWith(result);
72+
expect(writeStdout).toHaveBeenCalledWith("QA self-check report: /tmp/qa-self-check.md\n");
73+
expect(env.OPENCLAW_BUILD_PRIVATE_QA).toBe("1");
74+
});
3475
});

0 commit comments

Comments
 (0)