Skip to content
Merged
3 changes: 2 additions & 1 deletion docs/decisions/ci-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/integrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down
5 changes: 3 additions & 2 deletions scripts/proof-system-lane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
25 changes: 24 additions & 1 deletion tests/proof-system-lane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, string>) => checkQualification({ body: text, repository, head: sha.chart!, cwd: dir,
async readRun(id): Promise<QualificationRun | null> { return runsById[id] ? { id, headSha: runsById[id]!, repository } : null; } });
async readRun(id): Promise<QualificationRun | null> { 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(`<!-- e.g. ${url(1)} -->\nReplay ${url(2)} and ${url(3, "circe/brain-kit")} and ${url(2)}/attempts/1`);
Expand All @@ -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<QualificationRun> => {
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)") });
Expand Down
Loading