diff --git a/docs/decisions/ci-utility.md b/docs/decisions/ci-utility.md index 2b79f2b8c1..41124f4a7a 100644 --- a/docs/decisions/ci-utility.md +++ b/docs/decisions/ci-utility.md @@ -1399,7 +1399,8 @@ glob. - **Off-main qualification** ([#3271](https://github.com/schlessera/brain-kit/issues/3271), answer 3). The PR body needs an `Off-main qualification` heading whose section, outside HTML comments, links a GitHub Actions run of this - repository whose head SHA is the candidate head, or an ancestor of it whose + repository that completed with conclusion `success` and whose head SHA is + the candidate head, or an ancestor of it whose diff to the head is not a proof-system change. At most five linked runs are read. Whether the evidence is sufficient stays a review question. - **Exemption.** A declared red-main fix skips both gates: one merged with diff --git a/scripts/integrate.ts b/scripts/integrate.ts index 1af166b418..bdc06296b6 100644 --- a/scripts/integrate.ts +++ b/scripts/integrate.ts @@ -138,7 +138,7 @@ if (import.meta.main) { const qualification = await checkQualification({ body: (await api.json(`pulls/${desired.pr}`)).body, repository, head: desired.head, cwd: store!.root, ensure: ensureCommit, async readRun(id) { const run = await api.json(`actions/runs/${id}`).catch(() => null); - return run ? { id, headSha: run.head_sha ?? null, repository: run.repository?.full_name ?? null } : null; + return run ? { id, headSha: run.head_sha ?? null, repository: run.repository?.full_name ?? null, status: run.status ?? null, conclusion: run.conclusion ?? null } : null; } }); if ("refusal" in qualification) problems.push(qualification.refusal); const lane = laneRefusal(await readLane(desired.base, mainRunAt, { cwd: store!.root })); diff --git a/scripts/proof-system-lane.ts b/scripts/proof-system-lane.ts index 7474d14113..21d8933cbe 100644 --- a/scripts/proof-system-lane.ts +++ b/scripts/proof-system-lane.ts @@ -181,13 +181,14 @@ export function qualificationRunIds(text: string, repository: string): number[] return ids; } -export interface QualificationRun { id: number; headSha: string | null; repository: string | null } +export interface QualificationRun { id: number; headSha: string | null; repository: string | null; status: string | null; conclusion: string | null } export interface QualificationEvidence { run: number; headSha: string; via: "head" | "ancestor" } -/** Whether a run's head SHA qualifies `head`: it is the head, or an ancestor +/** Whether a completed, successful run's head SHA qualifies `head`: it is the head, or an ancestor * whose diff to the head is not a proof-system change. Returns why not. */ export function qualifies(run: QualificationRun, repository: string, head: string, options: ClassifyOptions = {}): "head" | "ancestor" | string { if (run.repository?.toLowerCase() !== repository.toLowerCase()) return `run ${run.id} is not a run in ${repository}`; + if (run.status !== "completed" || run.conclusion !== "success") return `run ${run.id} is ${run.status ?? "unknown"} with conclusion ${run.conclusion ?? "none"}; only completed runs with conclusion success qualify`; if (!run.headSha || !/^[a-f0-9]{40}$/.test(run.headSha)) return `run ${run.id} has no head SHA`; if (run.headSha === head) return "head"; const cwd = options.cwd ?? process.cwd(); diff --git a/tests/integration-command.test.ts b/tests/integration-command.test.ts index 0e994f7b53..5131d17db6 100644 --- a/tests/integration-command.test.ts +++ b/tests/integration-command.test.ts @@ -208,7 +208,7 @@ fi`); chmodSync(shim, 0o755); else if(path.endsWith("/pulls/7"))value={number:7,state:s.merged?"closed":"open",draft:s.draft,merged:s.merged,merge_commit_sha:squash,head:{sha:s.mode==="changed-head"||(s.mode==="confirm-changed"&&s.requested&&s.now>${NOW})?"e".repeat(40):head,repo:{full_name:repo}},base:{ref:"main",sha:base,repo:{full_name:repo}},milestone:{title:"0.44.0"},body}; else if(path.endsWith("git/ref/heads/main"))value={object:{sha:s.mode==="changed-base"?"d".repeat(40):base}}; else if(path.includes("actions/workflows/ci.yml/runs?event=push"))value={workflow_runs:Object.entries(mainRuns).filter(([sha])=>path.includes("head_sha="+sha)).map(([sha,run])=>({...run,head_sha:sha}))}; - else if(/actions\\/runs\\/555$/.test(path))value={id:555,head_sha:qualificationRuns[555],repository:{full_name:repo}}; + else if(/actions\\/runs\\/555$/.test(path))value={id:555,head_sha:qualificationRuns[555],status:"completed",conclusion:"success",repository:{full_name:repo}}; else if(path.includes("actions/workflows/ci.yml/runs"))value={workflow_runs:[run(s.mode.startsWith("confirm-")&&!s.requested?90:91,"ci")]}; else if(path.includes("actions/workflows/contract.yml/runs"))value={workflow_runs:s.mode.endsWith("contract-absent")?[] // A creation or push-and-edit burst: the newest run was cancelled while pending, an older one passed (#3573). diff --git a/tests/proof-system-lane.test.ts b/tests/proof-system-lane.test.ts index 2c4612b56f..5f6f761373 100644 --- a/tests/proof-system-lane.test.ts +++ b/tests/proof-system-lane.test.ts @@ -146,7 +146,7 @@ describe("off-main qualification (#3271)", () => { const url = (id: number, repo = repository) => `https://github.com/${repo}/actions/runs/${id}`; const body = (section: string) => `Odysseus re-rigs the shards.\n\n## Off-main qualification\n\n${section}\n\n## Anything left open\n\n${url(999)}\n`; const check = (text: string | null, runsById: Record) => checkQualification({ body: text, repository, head: sha.chart!, cwd: dir, - async readRun(id): Promise { return runsById[id] ? { id, headSha: runsById[id]!, repository } : null; } }); + async readRun(id): Promise { return runsById[id] ? { id, headSha: runsById[id]!, repository, status: "completed", conclusion: "success" } : null; } }); test("reads only the qualification section, without comments, and only this repository's runs", () => { const text = body(`\nReplay ${url(2)} and ${url(3, "circe/brain-kit")} and ${url(2)}/attempts/1`); @@ -166,6 +166,29 @@ describe("off-main qualification (#3271)", () => { expect(await check(body(`Dispatch ${url(42)}.`), { 42: sha.shards! })).toEqual({ evidence: { run: 42, headSha: sha.shards!, via: "ancestor" } }); }); + test.each([ + ["completed", "failure"], ["completed", "cancelled"], ["completed", "skipped"], + ["completed", "timed_out"], ["completed", null], ["in_progress", null], ["queued", null], + ["in_progress", "success"], ["queued", "success"], + ])("refuses qualification run state %s / %s", async (status, conclusion) => { + const result = await checkQualification({ body: body(url(45)), repository, head: sha.chart!, cwd: dir, + async readRun() { return { id: 45, headSha: sha.chart!, repository, status: status!, conclusion }; } }); + expect(result).toEqual({ refusal: expect.stringContaining(`run 45 is ${status} with conclusion ${conclusion ?? "none"}`) }); + }); + + test("a refused run leaves later successful evidence usable within the five-run bound", async () => { + const reads: number[] = []; + const input = { body: body([1, 2, 3, 4, 5, 6].map(id => url(id)).join("\n")), repository, head: sha.chart!, cwd: dir }; + const readRun = async (id: number): Promise => { + reads.push(id); + return { id, headSha: sha.chart!, repository, status: "completed", conclusion: id === 6 ? "success" : "failure" }; + }; + expect(await checkQualification({ ...input, readRun })).toHaveProperty("refusal"); + expect(reads).toEqual([1, 2, 3, 4, 5]); + expect(await checkQualification({ ...input, readRun: async id => ({ ...await readRun(id), conclusion: id === 2 ? "success" : "failure" }) })) + .toEqual({ evidence: { run: 2, headSha: sha.chart!, via: "head" } }); + }); + test("a run whose head SHA has proof-system changes after it is refused", async () => { const result = await check(body(`Replay ${url(43)}.`), { 43: sha.mast! }); expect(result).toEqual({ refusal: expect.stringContaining("is a proof-system change (scripts/ci-shards.ts)") });