Skip to content

Commit 7cbeb59

Browse files
author
thomas.szbay
committed
fix(qa-lab): bound evidence checkout ref git probe with timeout
1 parent ec01949 commit 7cbeb59

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Qa Lab tests bound the evidence checkout ref git probe.
2+
import { afterEach, describe, expect, it, vi } from "vitest";
3+
4+
const execFileSyncMock = vi.hoisted(() => vi.fn());
5+
6+
vi.mock("node:child_process", async () => {
7+
const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process");
8+
return {
9+
...actual,
10+
execFileSync: execFileSyncMock,
11+
};
12+
});
13+
14+
import { resolveQaEvidenceEnvironment } from "./evidence-environment.js";
15+
16+
afterEach(() => {
17+
vi.restoreAllMocks();
18+
execFileSyncMock.mockReset();
19+
});
20+
21+
describe("resolveQaEvidenceEnvironment", () => {
22+
it("bounds the checkout ref git probe with a timeout", () => {
23+
execFileSyncMock.mockReturnValue("abc123\n");
24+
25+
const environment = resolveQaEvidenceEnvironment({ env: {} });
26+
27+
expect(environment.ref).toBe("abc123");
28+
expect(execFileSyncMock).toHaveBeenCalledWith(
29+
"git",
30+
["rev-parse", "--verify", "HEAD"],
31+
expect.objectContaining({
32+
killSignal: "SIGKILL",
33+
timeout: 5_000,
34+
}),
35+
);
36+
});
37+
38+
it("falls back to GITHUB_SHA when the git probe times out", () => {
39+
execFileSyncMock.mockImplementation(() => {
40+
throw Object.assign(new Error("Command timed out"), { code: "ETIMEDOUT" });
41+
});
42+
43+
const environment = resolveQaEvidenceEnvironment({ env: { GITHUB_SHA: "fallbacksha" } });
44+
45+
expect(environment.ref).toBe("fallbacksha");
46+
});
47+
48+
it("prefers OPENCLAW_QA_REF without invoking git", () => {
49+
const environment = resolveQaEvidenceEnvironment({
50+
env: { OPENCLAW_QA_REF: "qa-ref", GITHUB_SHA: "fallbacksha" },
51+
});
52+
53+
expect(environment.ref).toBe("qa-ref");
54+
expect(execFileSyncMock).not.toHaveBeenCalled();
55+
});
56+
57+
it("returns a null ref when the probe fails and no env fallback exists", () => {
58+
execFileSyncMock.mockImplementation(() => {
59+
throw new Error("git unavailable");
60+
});
61+
62+
const environment = resolveQaEvidenceEnvironment({ env: {} });
63+
64+
expect(environment.ref).toBeNull();
65+
});
66+
});

‎extensions/qa-lab/src/evidence-environment.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
// Qa Lab plugin module resolves evidence runtime metadata.
22
import { execFileSync } from "node:child_process";
33

4+
// A wedged git (NFS hang, credential helper prompt) must not block evidence
5+
// metadata resolution; the caller already falls back to GITHUB_SHA/null.
6+
const QA_EVIDENCE_GIT_PROBE_TIMEOUT_MS = 5_000;
7+
48
function resolveQaEvidenceCheckoutRef(repoRoot?: string) {
59
try {
610
const ref = execFileSync("git", ["rev-parse", "--verify", "HEAD"], {
711
cwd: repoRoot ?? process.cwd(),
812
encoding: "utf8",
13+
killSignal: "SIGKILL",
914
stdio: ["ignore", "pipe", "ignore"],
15+
timeout: QA_EVIDENCE_GIT_PROBE_TIMEOUT_MS,
1016
}).trim();
1117
return ref || undefined;
1218
} catch {

0 commit comments

Comments
 (0)