Skip to content

Commit 911a2aa

Browse files
committed
fix(qa-lab): build evidence model before sending /api/evidence success headers
1 parent 23819f1 commit 911a2aa

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,14 @@ describe("qa-lab server", () => {
518518
},
519519
});
520520

521+
// A missing evidence path must return a controlled JSON error, not a reset connection
522+
// (the model must build before any success header is written).
523+
const missingEvidenceUrl = new URL("/api/evidence", lab.baseUrl);
524+
missingEvidenceUrl.searchParams.set("path", ".artifacts/qa-e2e/server/does-not-exist.json");
525+
const missingEvidenceResponse = await fetchWithRetry(missingEvidenceUrl.toString());
526+
expect(missingEvidenceResponse.status).toBe(404);
527+
expect(await missingEvidenceResponse.text()).not.toBe("");
528+
521529
const artifactUrl = new URL("/api/evidence/artifact", lab.baseUrl);
522530
artifactUrl.searchParams.set("evidencePath", ".artifacts/qa-e2e/server/qa-evidence.json");
523531
artifactUrl.searchParams.set("artifactPath", "artifact.log");

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,18 +439,15 @@ export async function startQaLabServer(
439439
res.end(JSON.stringify({ evidence: null }));
440440
return;
441441
}
442+
// Build the model before sending any headers so a thrown QaEvidenceGalleryError
443+
// still routes through writeQaLabServerError (writing headers first would make the
444+
// error response throw ERR_HTTP_HEADERS_SENT and reset the connection).
445+
const evidence = await buildQaEvidenceGalleryModel({ evidencePath, repoRoot });
442446
res.writeHead(200, {
443447
"content-type": "application/json; charset=utf-8",
444448
"cache-control": "no-store",
445449
});
446-
res.end(
447-
JSON.stringify({
448-
evidence: await buildQaEvidenceGalleryModel({
449-
evidencePath,
450-
repoRoot,
451-
}),
452-
}),
453-
);
450+
res.end(JSON.stringify({ evidence }));
454451
return;
455452
}
456453
if (

0 commit comments

Comments
 (0)