Skip to content

Commit 7b25193

Browse files
committed
fix(qa): finalize evidence after lifecycle cleanup
Punchcard-Session: amber-workshop-workshop-36
1 parent ba4ef91 commit 7b25193

18 files changed

Lines changed: 891 additions & 525 deletions

‎.github/workflows/qa-profile-evidence.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,10 @@ jobs:
356356
timeout_outcome="none"
357357
if [[ "$qa_exit_code" -eq 137 ]] && grep -Eq "^timeout: sending signal KILL to command '[A-Za-z0-9_./+-]+'$" "$timeout_supervisor_log"; then
358358
timeout_outcome="kill"
359-
echo "::warning::QA profile '${QA_PROFILE}' timed out after 110 minutes and required SIGKILL after the 30-second grace period; partial evidence will still be uploaded."
359+
echo "::warning::QA profile '${QA_PROFILE}' timed out after 110 minutes and required SIGKILL after the 30-second grace period; canonical qa-evidence.json was not published, but diagnostic artifacts will still be uploaded."
360360
elif [[ "$qa_exit_code" -eq 124 ]] && grep -Eq "^timeout: sending signal TERM to command '[A-Za-z0-9_./+-]+'$" "$timeout_supervisor_log"; then
361361
timeout_outcome="term"
362-
echo "::warning::QA profile '${QA_PROFILE}' timed out after 110 minutes and was terminated; partial evidence will still be uploaded."
362+
echo "::warning::QA profile '${QA_PROFILE}' timed out after 110 minutes and was terminated; canonical qa-evidence.json was not published, but diagnostic artifacts will still be uploaded."
363363
fi
364364
365365
QA_EXIT_CODE="$qa_exit_code" TIMEOUT_OUTCOME="$timeout_outcome" OUTPUT_DIR="$output_dir" \

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,20 @@ vi.mock("./suite-launch.runtime.js", async (importOriginal) => ({
4343
...(await importOriginal<typeof import("./suite-launch.runtime.js")>()),
4444
runQaFlowSuiteFromRuntime,
4545
runQaSuite,
46-
runQaSuiteCore: async (
47-
params: QaSuiteRunParams,
48-
target: { canonicalPath: string; stagedPath: string },
49-
) => {
46+
runQaSuiteCore: async (params: QaSuiteRunParams) => {
5047
const result = await runQaSuite(params);
5148
const evidencePath = result?.result.evidencePath;
52-
await fs.mkdir(path.dirname(target.stagedPath), { recursive: true });
49+
let evidence = makeQaEvidence();
5350
if (evidencePath) {
5451
try {
55-
if (evidencePath === target.canonicalPath) {
56-
await fs.rename(evidencePath, target.stagedPath);
57-
} else {
58-
await fs.copyFile(evidencePath, target.stagedPath);
59-
}
60-
return result;
52+
evidence = JSON.parse(await fs.readFile(evidencePath, "utf8"));
6153
} catch (error) {
6254
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
6355
throw error;
6456
}
6557
}
6658
}
67-
await fs.writeFile(target.stagedPath, `${JSON.stringify(makeQaEvidence(), null, 2)}\n`, "utf8");
68-
return result;
59+
return Object.freeze({ result, evidence, complete: vi.fn() });
6960
},
7061
}));
7162

@@ -1106,6 +1097,8 @@ describe("qa cli runtime", () => {
11061097
expect(
11071098
(await fs.readdir(profileArtifactsDir)).filter((entry) => entry.endsWith(".staged")),
11081099
).toEqual([]);
1100+
expect(stdoutWrite.mock.calls.flat().join("")).not.toContain("QA profile scorecard:");
1101+
expect(stdoutWrite.mock.calls.flat().join("")).not.toContain("QA suite evidence:");
11091102
});
11101103

11111104
it("resolves suite repo-root-relative paths before dispatching", async () => {

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

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,7 @@ export async function runQaLabSelfCheckCommand(opts: QaLabSelfCheckCommandOption
628628
}
629629

630630
export async function runQaProfileCommand(opts: QaProfileCommandOptions) {
631-
const evidencePath = await runQaSuiteEvidenceLifecycle(opts, async (resolved) => {
632-
const { repoRoot, outputDir, target } = resolved;
631+
await runQaSuiteEvidenceLifecycle(opts, async ({ repoRoot, outputDir }) => {
633632
const scenarioPack = readQaScenarioPack();
634633
const scorecardReport = readQaScorecardTaxonomyReport(scenarioPack.scenarios);
635634
const profile = normalizeQaRunProfile(
@@ -720,10 +719,10 @@ export async function runQaProfileCommand(opts: QaProfileCommandOptions) {
720719
process.stdout.write(
721720
`QA run profile: ${profile}; categories: ${categories.length}; scenarios: ${scenarios.length}\n`,
722721
);
723-
let expectedCells: QaProfileEvidencePlan["expectedCells"] = [];
724-
let observedCells: QaProfileEvidencePlan["observedCells"] = [];
725-
await withTemporaryQaProfileEnv(profile, async () => {
726-
const suiteResult = await runQaSuiteCommandCore(
722+
let suiteCompletion: Awaited<ReturnType<typeof runQaSuiteCore>> | undefined;
723+
let commandCompletion: (() => Promise<void>) | undefined;
724+
const suiteResult = await withTemporaryQaProfileEnv(profile, async () =>
725+
runQaSuiteCommandCore(
727726
{
728727
repoRoot,
729728
outputDir: opts.outputDir,
@@ -741,35 +740,50 @@ export async function runQaProfileCommand(opts: QaProfileCommandOptions) {
741740
channelDriver: profileReport.channelDriver,
742741
expandScenarioChannels: true,
743742
},
744-
(params) => runQaSuiteCore({ ...params, outputDir }, target),
745-
);
746-
expectedCells =
747-
suiteResult && "expectedCells" in suiteResult ? suiteResult.expectedCells : [];
748-
observedCells =
749-
suiteResult && "observedCells" in suiteResult ? suiteResult.observedCells : [];
750-
});
743+
async (params) => {
744+
suiteCompletion = await runQaSuiteCore({ ...params, repoRoot, outputDir });
745+
return suiteCompletion.result;
746+
},
747+
(complete) => {
748+
commandCompletion = complete;
749+
},
750+
),
751+
);
751752
const profilePlan = qaProfileEvidencePlan.build({
752753
profile,
753754
membershipScenarios: taxonomyScenarios,
754755
selectedScenarios: scenarios,
755756
excludedScenarios: executionSelection.excludedScenarios,
756-
expectedCells,
757-
observedCells,
757+
expectedCells: suiteResult?.expectedCells ?? [],
758+
observedCells: suiteResult?.observedCells ?? [],
758759
});
759-
await attachQaProfileScorecardEvidenceToFile({
760-
evidencePath: target.stagedPath,
761-
evidenceMode: opts.evidenceMode,
762-
profile,
763-
profilePlan,
764-
filters: {
765-
surface: opts.surface,
766-
category: opts.category,
760+
const completion = suiteCompletion;
761+
const completeCommand = commandCompletion;
762+
if (!completion || !completeCommand) {
763+
throw new Error("QA profile suite completed without deferred publication state");
764+
}
765+
return Object.freeze({
766+
evidence: completion.evidence,
767+
result: undefined,
768+
transformStagedEvidence: (stagedPath) =>
769+
attachQaProfileScorecardEvidenceToFile({
770+
evidencePath: stagedPath,
771+
evidenceMode: opts.evidenceMode,
772+
profile,
773+
profilePlan,
774+
filters: {
775+
surface: opts.surface,
776+
category: opts.category,
777+
},
778+
categories,
779+
}),
780+
complete: async () => {
781+
await completion.complete();
782+
await completeCommand();
783+
process.stdout.write(`QA profile scorecard: ${path.join(outputDir, "qa-evidence.json")}\n`);
767784
},
768-
categories,
769785
});
770-
return target.canonicalPath;
771786
});
772-
process.stdout.write(`QA profile scorecard: ${evidencePath}\n`);
773787
}
774788

775789
function selectQaScenarioDefinitionsForChannelResolution(params: {
@@ -863,6 +877,7 @@ async function runQaSuiteCommandCore(
863877
runSuite: (
864878
params: NonNullable<Parameters<typeof runQaSuite>[0]>,
865879
) => ReturnType<typeof runQaSuite>,
880+
deferCompletion?: (complete: () => Promise<void>) => void,
866881
) {
867882
const repoRoot = path.resolve(opts.repoRoot ?? process.cwd());
868883
const transportId = normalizeQaTransportId(opts.transportId);
@@ -1086,58 +1101,38 @@ async function runQaSuiteCommandCore(
10861101
: {}),
10871102
...(runtimePair ? { runtimePair } : {}),
10881103
});
1089-
switch (runtimeResult.executionKind) {
1090-
case "suite": {
1091-
const result = runtimeResult.result;
1092-
process.stdout.write(`QA suite report: ${result.reportPath}\n`);
1093-
process.stdout.write(`QA suite evidence: ${result.evidencePath}\n`);
1094-
process.stdout.write(`QA suite summary: ${result.summaryPath}\n`);
1095-
const blockingScenarioCount = await readQaSuiteFailedOrSkippedScenarioCountFromFile(
1096-
result.summaryPath,
1097-
{
1098-
optionalScenarioNames: resolveQaReportOnlyOptionalScenarioNames({
1099-
scenarioIds,
1100-
explicitScenarioSelection: opts.explicitScenarioSelection,
1101-
}),
1102-
requireExecutedScenario: allowFailures,
1103-
},
1104-
);
1105-
if (!allowFailures && blockingScenarioCount > 0) {
1106-
process.exitCode = 1;
1107-
}
1108-
return {
1109-
...result,
1110-
expectedCells: runtimeResult.expectedCells,
1111-
observedCells: runtimeResult.observedCells,
1112-
};
1104+
const result = runtimeResult.result;
1105+
const complete = async () => {
1106+
if (runtimeResult.executionKind === "flow") {
1107+
process.stdout.write(`QA suite watch: ${runtimeResult.result.watchUrl}\n`);
11131108
}
1114-
case "flow": {
1115-
const result = runtimeResult.result;
1116-
process.stdout.write(`QA suite watch: ${result.watchUrl}\n`);
1117-
process.stdout.write(`QA suite report: ${result.reportPath}\n`);
1118-
process.stdout.write(`QA suite evidence: ${result.evidencePath}\n`);
1119-
process.stdout.write(`QA suite summary: ${result.summaryPath}\n`);
1120-
const blockingScenarioCount = await readQaSuiteFailedOrSkippedScenarioCountFromFile(
1121-
result.summaryPath,
1122-
{
1123-
optionalScenarioNames: resolveQaReportOnlyOptionalScenarioNames({
1124-
scenarioIds,
1125-
explicitScenarioSelection: opts.explicitScenarioSelection,
1126-
}),
1127-
requireExecutedScenario: allowFailures,
1128-
},
1129-
);
1130-
if (!allowFailures && blockingScenarioCount > 0) {
1131-
process.exitCode = 1;
1132-
}
1133-
return {
1134-
...result,
1135-
expectedCells: runtimeResult.expectedCells,
1136-
observedCells: runtimeResult.observedCells,
1137-
};
1109+
process.stdout.write(`QA suite report: ${result.reportPath}\n`);
1110+
process.stdout.write(`QA suite evidence: ${result.evidencePath}\n`);
1111+
process.stdout.write(`QA suite summary: ${result.summaryPath}\n`);
1112+
const blockingScenarioCount = await readQaSuiteFailedOrSkippedScenarioCountFromFile(
1113+
result.summaryPath,
1114+
{
1115+
optionalScenarioNames: resolveQaReportOnlyOptionalScenarioNames({
1116+
scenarioIds,
1117+
explicitScenarioSelection: opts.explicitScenarioSelection,
1118+
}),
1119+
requireExecutedScenario: allowFailures,
1120+
},
1121+
);
1122+
if (!allowFailures && blockingScenarioCount > 0) {
1123+
process.exitCode = 1;
11381124
}
1125+
};
1126+
if (deferCompletion) {
1127+
deferCompletion(complete);
1128+
} else {
1129+
await complete();
11391130
}
1140-
return undefined;
1131+
return {
1132+
...result,
1133+
expectedCells: runtimeResult.expectedCells,
1134+
observedCells: runtimeResult.observedCells,
1135+
};
11411136
}
11421137

11431138
export async function runQaSuiteCommand(opts: QaSuiteCommandOptions) {

‎extensions/qa-lab/src/suite-artifacts.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { renderQaMarkdownReport, type QaReportScenario } from "./report.js";
1515
import type { RuntimeId } from "./runtime-parity.js";
1616
import type { QaSeedScenarioWithSource } from "./scenario-catalog.js";
1717
import type { QaScorecardEvidenceMode } from "./scorecard-taxonomy.js";
18-
import type { QaSuiteEvidenceTarget } from "./suite-evidence-lifecycle.js";
1918
import { splitModelRef } from "./suite-planning.js";
2019
import { countQaSuiteFailedScenarios, type QaSuiteSummaryJson } from "./suite-summary.js";
2120
import { createQaSuiteReportNotes } from "./suite-support.js";
@@ -134,15 +133,13 @@ export async function writeQaSuiteArtifacts(params: {
134133
scenarioIds?: readonly string[];
135134
runtimePair?: [RuntimeId, RuntimeId];
136135
writeEvidenceFile?: boolean;
137-
evidenceTarget?: QaSuiteEvidenceTarget;
138136
runCrablineChannelDriverSmoke?: (
139137
params: Parameters<QaCrablineRuntime["runOpenClawCrablineChannelDriverSmoke"]>[0],
140138
) => Promise<QaCrablineChannelDriverSmokeResult>;
141139
}) {
142140
const reportPath = path.join(params.outputDir, "qa-suite-report.md");
143141
const summaryPath = path.join(params.outputDir, "qa-suite-summary.json");
144-
const evidencePath =
145-
params.evidenceTarget?.canonicalPath ?? path.join(params.outputDir, QA_EVIDENCE_FILENAME);
142+
const evidencePath = path.join(params.outputDir, QA_EVIDENCE_FILENAME);
146143
const crablineChannelDriverSelection = params.channelDriverSelection;
147144
// Non-Crabline package acceptance mounts this source without plugin-local
148145
// dependencies. Keep the owner runtime outside every unrelated live path.
@@ -269,11 +266,7 @@ export async function writeQaSuiteArtifacts(params: {
269266
const writeEvidenceFile = params.writeEvidenceFile ?? true;
270267
await fs.writeFile(reportPath, report, "utf8");
271268
if (evidence && writeEvidenceFile) {
272-
await fs.writeFile(
273-
params.evidenceTarget?.stagedPath ?? evidencePath,
274-
`${JSON.stringify(evidence, null, 2)}\n`,
275-
"utf8",
276-
);
269+
await fs.writeFile(evidencePath, `${JSON.stringify(evidence, null, 2)}\n`, "utf8");
277270
}
278271
await fs.writeFile(
279272
summaryPath,
@@ -290,10 +283,7 @@ export async function writeQaSuiteArtifacts(params: {
290283
await assertQaSuiteArtifactWritten("report", reportPath);
291284
await assertQaSuiteArtifactWritten("summary", summaryPath);
292285
if (evidence && writeEvidenceFile) {
293-
await assertQaSuiteArtifactWritten(
294-
"evidence",
295-
params.evidenceTarget?.stagedPath ?? evidencePath,
296-
);
286+
await assertQaSuiteArtifactWritten("evidence", evidencePath);
297287
}
298288
return { evidence, evidencePath, report, reportPath, summaryPath };
299289
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
import {
4+
QA_EVIDENCE_SUMMARY_KIND,
5+
QA_EVIDENCE_SUMMARY_SCHEMA_VERSION,
6+
type QaEvidenceSummaryJson,
7+
} from "./evidence-summary.js";
8+
import { runQaSuiteEvidenceLifecycle } from "./suite-evidence-lifecycle.js";
9+
10+
const [outputDir, mode, markerPath] = process.argv.slice(2);
11+
if (!outputDir || !mode || !markerPath || !process.send) {
12+
throw new Error("expected outputDir, mode, markerPath, and IPC");
13+
}
14+
15+
const send = (message: object) => process.send?.(message);
16+
const finish = (message: object) =>
17+
new Promise<void>((resolve) => {
18+
process.send?.(message, () => {
19+
process.disconnect();
20+
resolve();
21+
});
22+
});
23+
const evidence: QaEvidenceSummaryJson = {
24+
kind: QA_EVIDENCE_SUMMARY_KIND,
25+
schemaVersion: QA_EVIDENCE_SUMMARY_SCHEMA_VERSION,
26+
generatedAt: "2026-08-08T00:00:00.000Z",
27+
evidenceMode: "full",
28+
entries: [],
29+
profile: mode,
30+
};
31+
32+
const waitForRelease = () =>
33+
new Promise<void>((resolve) => {
34+
process.on("message", (message) => {
35+
if (message === "release") {
36+
resolve();
37+
}
38+
});
39+
});
40+
41+
try {
42+
const result = await runQaSuiteEvidenceLifecycle(
43+
{ repoRoot: path.dirname(outputDir), outputDir },
44+
async () => {
45+
send({ type: "entered" });
46+
if (mode === "hold" || mode === "crash") {
47+
await waitForRelease();
48+
}
49+
return Object.freeze({
50+
evidence,
51+
result: mode,
52+
complete: async () => {
53+
await fs.writeFile(markerPath, `${mode}\n`, "utf8");
54+
send({ type: "completed" });
55+
},
56+
});
57+
},
58+
);
59+
await finish({ type: "result", result });
60+
} catch (error) {
61+
await finish({
62+
type: "error",
63+
code: error && typeof error === "object" && "code" in error ? String(error.code) : undefined,
64+
lockPath:
65+
error && typeof error === "object" && "lockPath" in error
66+
? String(error.lockPath)
67+
: undefined,
68+
message: error instanceof Error ? error.message : String(error),
69+
});
70+
}

0 commit comments

Comments
 (0)