Skip to content

Commit 2970ccb

Browse files
authored
fix(qa): report failed evaluations and scenario runs accurately (#118120)
1 parent 0cd7d43 commit 2970ccb

5 files changed

Lines changed: 316 additions & 64 deletions

File tree

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ describe("qa cli runtime", () => {
306306
runQaCharacterEval.mockResolvedValue({
307307
reportPath: "/tmp/character-report.md",
308308
summaryPath: "/tmp/character-summary.json",
309+
runs: [{ model: "qa/candidate", status: "pass" }],
310+
judgments: [{ model: "qa/judge", rankings: [{ model: "qa/candidate", rank: 1 }] }],
309311
});
310312
runQaManualLane.mockResolvedValue({
311313
model: "openai/gpt-5.6-luna",
@@ -2627,6 +2629,54 @@ describe("qa cli runtime", () => {
26272629
});
26282630
});
26292631

2632+
it("keeps a successful character eval exit status clear", async () => {
2633+
const priorExitCode = process.exitCode;
2634+
process.exitCode = undefined;
2635+
try {
2636+
await runQaCharacterEvalCommand({ model: ["qa/candidate"] });
2637+
2638+
expect(process.exitCode).toBeUndefined();
2639+
expectWriteContains(stdoutWrite, "QA character eval report: /tmp/character-report.md");
2640+
expectWriteContains(stdoutWrite, "QA character eval summary: /tmp/character-summary.json");
2641+
} finally {
2642+
process.exitCode = priorExitCode;
2643+
}
2644+
});
2645+
2646+
it.each([
2647+
{
2648+
label: "candidate failure",
2649+
runs: [{ model: "qa/candidate", status: "fail" }],
2650+
judgments: [{ model: "qa/judge", rankings: [{ model: "qa/candidate", rank: 1 }] }],
2651+
expectedVerdict: "QA character eval failed: 1 candidate(s), 0 judge(s).",
2652+
},
2653+
{
2654+
label: "judge failure",
2655+
runs: [{ model: "qa/candidate", status: "pass" }],
2656+
judgments: [{ model: "qa/judge", rankings: [], error: "judge unavailable" }],
2657+
expectedVerdict: "QA character eval failed: 0 candidate(s), 1 judge(s).",
2658+
},
2659+
])("returns a failing exit code on $label without hiding artifacts", async (failure) => {
2660+
runQaCharacterEval.mockResolvedValueOnce({
2661+
reportPath: "/tmp/character-report.md",
2662+
summaryPath: "/tmp/character-summary.json",
2663+
runs: failure.runs,
2664+
judgments: failure.judgments,
2665+
});
2666+
const priorExitCode = process.exitCode;
2667+
process.exitCode = undefined;
2668+
try {
2669+
await runQaCharacterEvalCommand({ model: ["qa/candidate"] });
2670+
2671+
expect(process.exitCode).toBe(1);
2672+
expectWriteContains(stderrWrite, failure.expectedVerdict);
2673+
expectWriteContains(stdoutWrite, "QA character eval report: /tmp/character-report.md");
2674+
expectWriteContains(stdoutWrite, "QA character eval summary: /tmp/character-summary.json");
2675+
} finally {
2676+
process.exitCode = priorExitCode;
2677+
}
2678+
});
2679+
26302680
it("rejects invalid character eval thinking levels", async () => {
26312681
await expect(
26322682
runQaCharacterEvalCommand({

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ import {
9898
runQaSuiteWithInfraRetry,
9999
} from "./suite-launch.runtime.js";
100100
import { resolveQaSuiteScenarioChannel, resolveQaSuiteScenarioChannels } from "./suite-planning.js";
101-
import { readQaSuiteFailedOrSkippedScenarioCountFromFile } from "./suite-summary.js";
101+
import {
102+
readQaSuiteFailedOrSkippedScenarioCountFromFile,
103+
resolveQaReportOnlyOptionalScenarioNames as resolveQaReportOnlyOptionalScenarioNamesFromCatalog,
104+
} from "./suite-summary.js";
102105
import {
103106
buildTokenEfficiencyReport,
104107
renderTokenEfficiencyMarkdownReport,
@@ -815,22 +818,7 @@ function resolveQaReportOnlyOptionalScenarioNames(params: {
815818
if (params.explicitScenarioSelection || params.scenarioIds.length > 0) {
816819
return undefined;
817820
}
818-
return new Set(
819-
readQaScenarioPack()
820-
.scenarios.filter((scenario) => {
821-
if (scenario.execution.kind !== "flow") {
822-
return false;
823-
}
824-
const toolCoverage = scenario.execution.config?.toolCoverage;
825-
return (
826-
typeof toolCoverage === "object" &&
827-
toolCoverage !== null &&
828-
"required" in toolCoverage &&
829-
toolCoverage.required === false
830-
);
831-
})
832-
.map((scenario) => scenario.title),
833-
);
821+
return resolveQaReportOnlyOptionalScenarioNamesFromCatalog(readQaScenarioPack().scenarios);
834822
}
835823

836824
export async function runQaSuiteCommand(opts: QaSuiteCommandOptions) {
@@ -1381,6 +1369,16 @@ export async function runQaCharacterEvalCommand(opts: {
13811369
});
13821370
process.stdout.write(`QA character eval report: ${result.reportPath}\n`);
13831371
process.stdout.write(`QA character eval summary: ${result.summaryPath}\n`);
1372+
const failedCandidateCount = result.runs.filter((run) => run.status === "fail").length;
1373+
const failedJudgeCount = result.judgments.filter(
1374+
(judgment) => judgment.rankings.length === 0,
1375+
).length;
1376+
if (failedCandidateCount > 0 || failedJudgeCount > 0) {
1377+
process.stderr.write(
1378+
`QA character eval failed: ${failedCandidateCount} candidate(s), ${failedJudgeCount} judge(s).\n`,
1379+
);
1380+
process.exitCode = 1;
1381+
}
13841382
}
13851383

13861384
export async function runQaManualLaneCommand(opts: {

‎extensions/qa-lab/src/lab-server.test.ts‎

Lines changed: 202 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,62 @@ async function createQaLabRepoRootFixture(params?: {
343343
return repoRoot;
344344
}
345345

346+
type QaLabSuiteScenarioFixture = {
347+
name: string;
348+
status: "pass" | "fail" | "skip";
349+
steps: unknown[];
350+
details?: string;
351+
};
352+
353+
async function createQaLabSuiteResultFixture(params?: {
354+
scenarios?: QaLabSuiteScenarioFixture[];
355+
watchUrl?: string;
356+
}) {
357+
const outputDir = await mkdtemp(path.join(os.tmpdir(), "qa-lab-suite-result-"));
358+
cleanups.push(async () => {
359+
await rm(outputDir, { recursive: true, force: true });
360+
});
361+
const scenarios = params?.scenarios ?? [
362+
{ name: "Channel chat baseline", status: "pass" as const, steps: [] },
363+
];
364+
const report = "# QA report\n";
365+
const evidencePath = path.join(outputDir, "qa-evidence.json");
366+
const reportPath = path.join(outputDir, "qa-suite-report.md");
367+
const summaryPath = path.join(outputDir, "qa-suite-summary.json");
368+
await Promise.all([
369+
writeFile(
370+
evidencePath,
371+
JSON.stringify({
372+
entries: scenarios.map((scenario) => ({ result: { status: scenario.status } })),
373+
}),
374+
"utf8",
375+
),
376+
writeFile(reportPath, report, "utf8"),
377+
writeFile(
378+
summaryPath,
379+
JSON.stringify({
380+
counts: {
381+
total: scenarios.length,
382+
passed: scenarios.filter((scenario) => scenario.status === "pass").length,
383+
failed: scenarios.filter((scenario) => scenario.status === "fail").length,
384+
skipped: scenarios.filter((scenario) => scenario.status === "skip").length,
385+
},
386+
scenarios,
387+
}),
388+
"utf8",
389+
),
390+
]);
391+
return {
392+
evidencePath,
393+
outputDir,
394+
report,
395+
reportPath,
396+
scenarios,
397+
summaryPath,
398+
...(params?.watchUrl ? { watchUrl: params.watchUrl } : {}),
399+
};
400+
}
401+
346402
describe("qa-lab server", () => {
347403
it("dispatches explicit mixed-kind selections through the suite planner", async () => {
348404
const lab = await startQaLabServerForTest();
@@ -351,14 +407,7 @@ describe("qa-lab server", () => {
351407
});
352408
suiteLaunchMock.runQaSuite.mockResolvedValue({
353409
executionKind: "suite",
354-
result: {
355-
evidencePath: "/tmp/qa-evidence.json",
356-
outputDir: "/tmp/qa-output",
357-
report: "# QA report\n",
358-
reportPath: "/tmp/qa-report.md",
359-
scenarios: [],
360-
summaryPath: "/tmp/qa-summary.json",
361-
},
410+
result: await createQaLabSuiteResultFixture(),
362411
});
363412

364413
const response = await fetch(`${lab.baseUrl}/api/scenario/suite`, {
@@ -431,22 +480,156 @@ describe("qa-lab server", () => {
431480
});
432481
});
433482

483+
it.each([
484+
{ label: "failed", status: "fail" as const },
485+
{ label: "skipped", status: "skip" as const },
486+
])(
487+
"marks $label suite results failed while preserving generated artifacts",
488+
async ({ status }) => {
489+
const lab = await startQaLabServerForTest();
490+
cleanups.push(async () => {
491+
await lab.stop();
492+
});
493+
const result = await createQaLabSuiteResultFixture({
494+
scenarios: [{ name: "Channel chat baseline", status, steps: [] }],
495+
});
496+
suiteLaunchMock.runQaSuite.mockResolvedValue({ executionKind: "flow", result });
497+
498+
const response = await fetch(`${lab.baseUrl}/api/scenario/suite`, {
499+
method: "POST",
500+
headers: { "content-type": "application/json" },
501+
body: JSON.stringify({
502+
channelDriver: "crabline",
503+
providerMode: "live-frontier",
504+
scenarioIds: ["dm-chat-baseline"],
505+
}),
506+
});
507+
508+
expect(response.status).toBe(202);
509+
await vi.waitFor(async () => {
510+
const bootstrap = (await (await fetchWithRetry(`${lab.baseUrl}/api/bootstrap`)).json()) as {
511+
latestReport: { outputPath: string; markdown: string };
512+
runner: {
513+
status: string;
514+
error: string;
515+
artifacts: {
516+
outputDir: string;
517+
evidencePath: string;
518+
reportPath: string;
519+
summaryPath: string;
520+
};
521+
};
522+
};
523+
expect(bootstrap.runner.status).toBe("failed");
524+
expect(bootstrap.runner.error).toBe("QA suite reported 1 failed or skipped scenario(s).");
525+
expect(bootstrap.runner.artifacts).toEqual(
526+
expect.objectContaining({
527+
outputDir: result.outputDir,
528+
evidencePath: result.evidencePath,
529+
reportPath: result.reportPath,
530+
summaryPath: result.summaryPath,
531+
}),
532+
);
533+
expect(bootstrap.latestReport).toEqual(
534+
expect.objectContaining({ outputPath: result.reportPath, markdown: result.report }),
535+
);
536+
});
537+
},
538+
);
539+
540+
it.each([
541+
{
542+
label: "invalid",
543+
summary: "{invalid-summary",
544+
expectedError: "Could not parse QA summary JSON",
545+
},
546+
{
547+
label: "empty",
548+
summary: JSON.stringify({
549+
counts: { total: 0, passed: 0, failed: 0, skipped: 0 },
550+
scenarios: [],
551+
}),
552+
expectedError: "did not include any executed scenarios",
553+
},
554+
])(
555+
"fails closed on an $label suite summary while preserving artifacts",
556+
async (invalidResult) => {
557+
const lab = await startQaLabServerForTest();
558+
cleanups.push(async () => {
559+
await lab.stop();
560+
});
561+
const result = await createQaLabSuiteResultFixture();
562+
await writeFile(result.summaryPath, invalidResult.summary, "utf8");
563+
suiteLaunchMock.runQaSuite.mockResolvedValue({ executionKind: "flow", result });
564+
565+
const response = await fetch(`${lab.baseUrl}/api/scenario/suite`, {
566+
method: "POST",
567+
headers: { "content-type": "application/json" },
568+
body: JSON.stringify({
569+
channelDriver: "crabline",
570+
providerMode: "live-frontier",
571+
scenarioIds: ["dm-chat-baseline"],
572+
}),
573+
});
574+
575+
expect(response.status).toBe(202);
576+
await vi.waitFor(async () => {
577+
const bootstrap = (await (await fetchWithRetry(`${lab.baseUrl}/api/bootstrap`)).json()) as {
578+
runner: { status: string; error: string; artifacts: { summaryPath: string } };
579+
};
580+
expect(bootstrap.runner.status).toBe("failed");
581+
expect(bootstrap.runner.error).toContain(invalidResult.expectedError);
582+
expect(bootstrap.runner.artifacts.summaryPath).toBe(result.summaryPath);
583+
});
584+
},
585+
);
586+
587+
it("keeps implicit suites green for catalog-verified report-only optional skips", async () => {
588+
const lab = await startQaLabServerForTest();
589+
cleanups.push(async () => {
590+
await lab.stop();
591+
});
592+
const result = await createQaLabSuiteResultFixture({
593+
scenarios: [
594+
{ name: "Channel chat baseline", status: "pass", steps: [] },
595+
{
596+
name: "Runtime tool fixture — image_generate",
597+
status: "skip",
598+
steps: [],
599+
details: "image_generate mock provider report-only: tool unavailable",
600+
},
601+
],
602+
});
603+
suiteLaunchMock.runQaSuite.mockResolvedValue({ executionKind: "flow", result });
604+
605+
const response = await fetch(`${lab.baseUrl}/api/scenario/suite`, {
606+
method: "POST",
607+
headers: { "content-type": "application/json" },
608+
body: JSON.stringify({
609+
profile: "all",
610+
channelDriver: "crabline",
611+
providerMode: "live-frontier",
612+
}),
613+
});
614+
615+
expect(response.status).toBe(202);
616+
await vi.waitFor(async () => {
617+
const bootstrap = (await (await fetchWithRetry(`${lab.baseUrl}/api/bootstrap`)).json()) as {
618+
runner: { status: string; error: string | null };
619+
};
620+
expect(bootstrap.runner.status).toBe("completed");
621+
expect(bootstrap.runner.error).toBeNull();
622+
});
623+
});
624+
434625
it("keeps mock providers independent from real channel adapters", async () => {
435626
const lab = await startQaLabServerForTest();
436627
cleanups.push(async () => {
437628
await lab.stop();
438629
});
439630
suiteLaunchMock.runQaSuite.mockResolvedValue({
440631
executionKind: "flow",
441-
result: {
442-
evidencePath: "/tmp/qa-evidence.json",
443-
outputDir: "/tmp/qa-output",
444-
report: "# QA report\n",
445-
reportPath: "/tmp/qa-report.md",
446-
scenarios: [],
447-
summaryPath: "/tmp/qa-summary.json",
448-
watchUrl: "http://runtime-watch.invalid",
449-
},
632+
result: await createQaLabSuiteResultFixture({ watchUrl: "http://runtime-watch.invalid" }),
450633
});
451634

452635
const response = await fetch(`${lab.baseUrl}/api/scenario/suite`, {
@@ -509,14 +692,7 @@ describe("qa-lab server", () => {
509692
expect(suiteLaunchMock.runQaSuite).toHaveBeenCalledTimes(1);
510693
finishSuite?.({
511694
executionKind: "flow",
512-
result: {
513-
evidencePath: "/tmp/qa-evidence.json",
514-
outputDir: "/tmp/qa-output",
515-
report: "# QA report\n",
516-
reportPath: "/tmp/qa-report.md",
517-
scenarios: [],
518-
summaryPath: "/tmp/qa-summary.json",
519-
},
695+
result: await createQaLabSuiteResultFixture(),
520696
});
521697
await vi.waitFor(async () => {
522698
const bootstrap = (await (await fetchWithRetry(`${lab.baseUrl}/api/bootstrap`)).json()) as {
@@ -550,15 +726,7 @@ describe("qa-lab server", () => {
550726
});
551727
suiteLaunchMock.runQaSuite.mockResolvedValue({
552728
executionKind: "flow",
553-
result: {
554-
evidencePath: "/tmp/qa-evidence.json",
555-
outputDir: "/tmp/qa-output",
556-
report: "# QA report\n",
557-
reportPath: "/tmp/qa-report.md",
558-
scenarios: [],
559-
summaryPath: "/tmp/qa-summary.json",
560-
watchUrl: lab.baseUrl,
561-
},
729+
result: await createQaLabSuiteResultFixture({ watchUrl: lab.baseUrl }),
562730
});
563731

564732
const response = await fetch(`${lab.baseUrl}/api/scenario/suite`, {

0 commit comments

Comments
 (0)