Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/actions/log-api-budget/rate-guard.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const MAX_RESET = 999_999_999_999;
* this module, so each literal below is pinned to it by rate-guard.test.mjs:
* - `step`: one process's waits, summed. The latch's budget for rate-limit
* waits and, counted apart, a client's 5xx retries (retryServerErrors), and
* the `rate-limit-wait-seconds` ci-status passes each pinned ci-workflows
* composite.
* the `rate-limit-wait-seconds` default of check-contract and
* aggregate-results, which ci-status's report-ci-status composite keeps.
* - `ciStatusReads`: ci-status's reads, from the job's start: its
* GH_READ_JOB_SECONDS less GH_READ_MARGIN_SECONDS.
* - `rerunCiStatus`: pr-dispatch-feedback.yml's rerun-ci-status find step,
Expand All @@ -72,7 +72,7 @@ const MAX_RESET = 999_999_999_999;
* leak scan's wait, and its jobs' API_BUDGET_WAIT_SECONDS. It is
* waitBudgetMs's cap.
*/
export const WAIT_BUDGET_SECONDS = Object.freeze({ step: 60, ciStatusReads: 825, rerunCiStatus: 600, workResolveIssue: 1200 });
export const WAIT_BUDGET_SECONDS = Object.freeze({ step: 60, ciStatusReads: 765, rerunCiStatus: 600, workResolveIssue: 1200 });

export const SERVER_RETRY_BUDGET_MS = WAIT_BUDGET_SECONDS.step * 1000;

Expand Down
6 changes: 3 additions & 3 deletions .github/actions/log-api-budget/rate-guard.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,13 +1008,13 @@ const jobOf = (text, id) => {
};
const setting = (text, key) => [...text.matchAll(new RegExp(`^ +${key}: ["']?([0-9]+)["']?$`, "gm"))].map((match) => Number(match[1]));

test("ci-status's read deadline and both pinned composites' waits are WAIT_BUDGET_SECONDS'", () => {
test("ci-status's read deadline is WAIT_BUDGET_SECONDS', and its composite keeps the step waits' default", () => {
const job = jobOf(workflow("pr-require-checks.yml"), "ci-status");
const [jobSeconds] = setting(job, "GH_READ_JOB_SECONDS");
const [margin] = setting(job, "GH_READ_MARGIN_SECONDS");
assert.equal(jobSeconds - margin, WAIT_BUDGET_SECONDS.ciStatusReads);
assert.deepEqual(setting(job, "rate-limit-wait-seconds"), [WAIT_BUDGET_SECONDS.step, WAIT_BUDGET_SECONDS.step], "check-contract, then aggregate-results");
assert.equal(job.match(/uses: melodic-software\/ci-workflows\/\.github\/actions\/pr-require-checks\/(check-contract|aggregate-results)@/g)?.length, 2, "ci-status calls two composites that take the input");
assert.deepEqual(setting(job, "rate-limit-wait-seconds"), [], "report-ci-status takes no wait input");
assert.equal(job.match(/uses: melodic-software\/ci-workflows\/\.github\/actions\/pr-require-checks\/report-ci-status@/g)?.length, 1, "ci-status calls the report-ci-status composite once");
});

test("rerun-ci-status's poll limit is WAIT_BUDGET_SECONDS.rerunCiStatus", () => {
Expand Down
34 changes: 25 additions & 9 deletions .github/scripts/pr-verify/resolve-pr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,20 @@ export const HOLD_STEP = "Fail a lanes App pull request on kill switch, hold pat
const OLD_HOLD_STEP = "Fail a lanes App pull request its body or a member holds";
const HOLD_STEPS = [HOLD_STEP, OLD_HOLD_STEP];
export const AGGREGATE_STEP = "Aggregate lane results";
// The ci-status step that runs ci-workflows' check-contract (title,
// `do-not-merge` label, issue linkage), and the one error line its run.sh
// writes for the label, whose name pr-require-checks.yml leaves the default.
export const CONTRACT_STEP = "Check the pull-request contract";
/**
* The ci-status step that fails on ci-workflows' check-contract (title,
* `do-not-merge` label, issue linkage), its own error line, and the one error
* line check-contract's run.sh writes for the label, whose name
* pr-require-checks.yml leaves the default. check-contract runs inside the
* report-ci-status composite, which AGGREGATE_STEP names: that step still
* succeeds, but its log keeps check-contract's lines and exit. A run from
* before the composite reports OLD_CONTRACT_STEP, which ran check-contract
* itself.
*/
export const CONTRACT_STEP = "Fail on the contract or draft policy";
export const CONTRACT_LINE = "ci-status: the pull-request contract or the draft policy failed; see the step above.";
const OLD_CONTRACT_STEP = "Check the pull-request contract";
const CONTRACT_STEPS = [CONTRACT_STEP, OLD_CONTRACT_STEP];
export const DO_NOT_MERGE_LINE = "check-contract: this PR carries the 'do-not-merge' label; remove it to merge.";
// What merge-holds.mjs `holds` writes after each hold an approving review of
// the head lifts, and the line the runner adds for the step's failing exit.
Expand Down Expand Up @@ -336,7 +346,9 @@ export const errorLines = (log) =>
// both, the lanes aggregate succeeded, and every error that job logged is one
// of `number`'s holds an approval lifts (at least one when HOLD_STEP failed),
// DO_NOT_MERGE_LINE (exactly once when CONTRACT_STEP failed, never otherwise)
// or a failed step's exit. ci-status still fails, so such a head never merges
// or a failed step's exit; CONTRACT_STEP adds CONTRACT_LINE and check-contract's
// exit inside the composite, once each, as a held run logs them
// (https://github.com/melodic-software/ci-workflows/actions/runs/44383672751). ci-status still fails, so such a head never merges
// unapproved or labeled; the verdict a judgment writes lifts no hold path and
// no label. A read that fails, a job or step list cut short, or any other
// error is false.
Expand Down Expand Up @@ -366,8 +378,9 @@ async function heldShape(read) {
const names = failed.map((step) => step?.name);
if (
failed.length === 0 ||
failed.some((step) => step.conclusion !== "failure" || ![...HOLD_STEPS, CONTRACT_STEP].includes(step.name)) ||
failed.some((step) => step.conclusion !== "failure" || ![...HOLD_STEPS, ...CONTRACT_STEPS].includes(step.name)) ||
new Set(names).size !== names.length ||
names.filter((name) => CONTRACT_STEPS.includes(name)).length > 1 ||
!steps.some((step) => step?.name === AGGREGATE_STEP && step.conclusion === "success")
) {
return null;
Expand All @@ -384,11 +397,14 @@ async function heldOnly(readLog, { ciId, names }, number) {
const reasons = errors.filter((line) => line !== STEP_EXIT);
const person = reasons.filter((line) => personHoldLine(line, number));
const label = reasons.filter((line) => line === DO_NOT_MERGE_LINE);
const own = reasons.filter((line) => line === CONTRACT_LINE);
const composite = names.includes(CONTRACT_STEP) ? 1 : 0;
return (
errors.length - reasons.length === names.length &&
person.length + label.length === reasons.length &&
errors.length - reasons.length === names.length + composite &&
person.length + label.length + own.length === reasons.length &&
(person.length > 0) === names.some((name) => HOLD_STEPS.includes(name)) &&
label.length === (names.includes(CONTRACT_STEP) ? 1 : 0)
label.length === (names.some((name) => CONTRACT_STEPS.includes(name)) ? 1 : 0) &&
own.length === composite
);
} catch {
return false;
Expand Down
74 changes: 57 additions & 17 deletions .github/scripts/pr-verify/resolve-pr.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { createHash } from "node:crypto";

import { createGitHub, GitHubError } from "../../actions/check-trusted-trigger/check-trusted-trigger.mjs";
import { createRateLimitLatch } from "../../actions/log-api-budget/rate-guard.mjs";
import { CARRY_MAX, carryMain, closing, CONTRACT_STEP, DO_NOT_MERGE_LINE, DRAFT_STEP, failureAnnotation, HOLD_STEP, linkedIssues, main, packReads, ratedBy, RELINK_QUERY, resolvePull, SIBLINGS_MAX, siblingNumbers, takeReads, upstreamPages } from "./resolve-pr.mjs";
import { CARRY_MAX, carryMain, closing, CONTRACT_LINE, CONTRACT_STEP, DO_NOT_MERGE_LINE, DRAFT_STEP, failureAnnotation, HOLD_STEP, linkedIssues, main, packReads, ratedBy, RELINK_QUERY, resolvePull, SIBLINGS_MAX, siblingNumbers, takeReads, upstreamPages } from "./resolve-pr.mjs";
import { KEPT_JOBS, keptJobs, shapeJobs } from "./upstream-jobs.mjs";
import { artifactName } from "./write-verdict.mjs";
import { bodyVersion, loadRules, REFINE_MARKER, splitItemsLine } from "../intake-triage/admit.mjs";
Expand Down Expand Up @@ -914,15 +914,22 @@ const COST_NAMED = holds("", [], [`infra/x${LIFT}.tf`], [])[0];
const OLD_WORDING = "#41: it changes plugins/x/scripts/risk.py, a hold path; an approving review of this head by a person on the trusted-actor list lifts it, and the approval carries over later merges of the base that leave its net change the same; then re-run ci-status.";
const CI_STEPS = [
["Set up job", "success"],
["Check the pull-request contract", "success"],
["Note a draft", "skipped"],
["Fail a pull request carrying the human-gated label", "success"],
["Fail a head a pr-unblock lane stopped", "success"],
["Fail a lanes App pull request on kill switch, hold path, verifier or veto", "failure"],
["Check each skipped lane against scope", "success"],
["Aggregate lane results", "success"],
["Fail on the contract or draft policy", "skipped"],
["Complete job", "success"],
];
/** The steps before the report-ci-status composite, when ci-status ran check-contract as a step of its own. */
const OLD_CONTRACT_STEP = "Check the pull-request contract";
const OLD_CI_STEPS = [
["Set up job", "success"],
[OLD_CONTRACT_STEP, "success"],
...CI_STEPS.slice(1).filter(([n]) => n !== CONTRACT_STEP),
];
const ciJob = (steps = CI_STEPS, conclusion = "failure") => ({ id: 9001, name: "ci-status", conclusion, steps: steps.map(([name, c]) => ({ name, conclusion: c })) });
const heldJobs = (ci = ciJob(), others = [{ id: 9002, name: "Lint Repo", conclusion: "success" }, { id: 9003, name: "pr-unblock / address-feedback", conclusion: "neutral" }]) => {
const jobs = [...others, ci];
Expand Down Expand Up @@ -988,22 +995,42 @@ test("a run that failed on anything but a hold an approval lifts starts nothing"
assert.equal(await reason({ run: upstream({ conclusion: "failure" }), jobs: heldJobs() }), "not-a-passing-run");
});

// A session holds a pull request with `do-not-merge`, which fails
// check-contract's step of ci-status. Its log lines follow that action's
// run.sh: the label's `::error::` line, then the step's exit.
const contractLog = (...lines) =>
/**
* A session holds a pull request with `do-not-merge`, which fails
* check-contract inside the report-ci-status composite. Its log lines follow
* a held run's: check-contract's run.sh writes the label's `::error::` line,
* then its exit, inside "Aggregate lane results", which still succeeds; then
* "Fail on the contract or draft policy" writes its own line and exit.
*/
const oldContractLog = (...lines) =>
[
'2026-10-28T16:21:30.0000000Z ##[group]Run bash "$GITHUB_ACTION_PATH/run.sh"',
...lines.map((line) => `2026-10-28T16:21:31.0000000Z ##[error]${line}`),
"2026-10-28T16:21:31.0000001Z ##[error]Process completed with exit code 1.",
].join("\r\n");
const failStep = [
`2026-10-28T16:21:33.0000000Z ##[error]${CONTRACT_LINE}`,
"2026-10-28T16:21:33.0000001Z ##[error]Process completed with exit code 1.",
].join("\r\n");
const contractLog = (...lines) => `${oldContractLog(...lines)}\r\n${failStep}`;
const failing = (...names) => ({
jobs: heldJobs(ciJob(CI_STEPS.map(([n, c]) => [n, names.includes(n) ? "failure" : n === HOLD_STEP ? "success" : c]))),
});
const oldFailing = (...names) => ({
jobs: heldJobs(ciJob(OLD_CI_STEPS.map(([n, c]) => [n, names.includes(n) ? "failure" : n === HOLD_STEP ? "success" : c]))),
});

test("a run that failed only on do-not-merge, alone or beside a hold an approval lifts, is judged", async () => {
assert.equal(await held(contractLog(DO_NOT_MERGE_LINE), failing(CONTRACT_STEP)), "ok");
assert.equal(await held(`${contractLog(DO_NOT_MERGE_LINE)}\r\n${logOf(PATH_HOLD)}`, failing(CONTRACT_STEP, HOLD_STEP)), "ok");
assert.equal(await held(`${logOf(PATH_HOLD)}\r\n${contractLog(DO_NOT_MERGE_LINE)}`, failing(CONTRACT_STEP, HOLD_STEP)), "ok");
});

/** A run reports its own commit's step names, so a held run from before the composite still reports check-contract's own step, with no fail step. */
test("a held run from before the composite, with check-contract's own step, is judged the same way", async () => {
assert.equal(await held(oldContractLog(DO_NOT_MERGE_LINE), oldFailing(OLD_CONTRACT_STEP)), "ok");
assert.equal(await held(`${oldContractLog(DO_NOT_MERGE_LINE)}\r\n${logOf(PATH_HOLD)}`, oldFailing(OLD_CONTRACT_STEP, HOLD_STEP)), "ok");
assert.equal(await held(contractLog(DO_NOT_MERGE_LINE), oldFailing(OLD_CONTRACT_STEP)), "not-a-passing-run");
assert.equal(await held(oldContractLog(DO_NOT_MERGE_LINE), failing(CONTRACT_STEP)), "not-a-passing-run");
});

// A run reports its own commit's step names, so a held run from before the
Expand All @@ -1013,7 +1040,7 @@ test("a held run that still reports the hold step's earlier name is judged the s
const jobs = heldJobs(ciJob(CI_STEPS.map(([n, c]) => [n === HOLD_STEP ? oldName : n, c])));
assert.equal(await held(logOf(PATH_HOLD), { jobs }), "ok");
assert.equal(await held(logOf(COST), { jobs }), "not-a-passing-run");
assert.equal(await held(`${contractLog(DO_NOT_MERGE_LINE)}\r\n${logOf(PATH_HOLD)}`, { jobs: heldJobs(ciJob(CI_STEPS.map(([n, c]) => [n === HOLD_STEP ? oldName : n, n === CONTRACT_STEP ? "failure" : c]))) }), "ok");
assert.equal(await held(`${logOf(PATH_HOLD)}\r\n${contractLog(DO_NOT_MERGE_LINE)}`, { jobs: heldJobs(ciJob(CI_STEPS.map(([n, c]) => [n === HOLD_STEP ? oldName : n, n === CONTRACT_STEP ? "failure" : c]))) }), "ok");
assert.equal(await held(logOf(), { jobs }), "not-a-passing-run");
});

Expand All @@ -1025,25 +1052,38 @@ test("a contract failure other than do-not-merge, or a label line its step does
"no label line": [contractLog(), failing(CONTRACT_STEP)],
"the label line twice": [contractLog(DO_NOT_MERGE_LINE, DO_NOT_MERGE_LINE), failing(CONTRACT_STEP)],
"the label line with the label text changed": [contractLog(DO_NOT_MERGE_LINE.replace("do-not-merge", "hold")), failing(CONTRACT_STEP)],
"the label line while the contract step passed": [`${contractLog(DO_NOT_MERGE_LINE)}\r\n${logOf(PATH_HOLD)}`.replace(/\r\n[^\r\n]*exit code 1\.(?=\r\n)/, ""), failing(HOLD_STEP)],
"both steps failed with one exit": [`${contractLog(DO_NOT_MERGE_LINE)}\r\n${logOf(PATH_HOLD)}`.replace(/\r\n[^\r\n]*exit code 1\.(?=\r\n)/, ""), failing(CONTRACT_STEP, HOLD_STEP)],
"the hold step failed with only the label": [`${contractLog(DO_NOT_MERGE_LINE)}\r\n${logOf()}`, failing(CONTRACT_STEP, HOLD_STEP)],
"the label line while the contract step passed": [`${logOf(PATH_HOLD)}\r\n${oldContractLog(DO_NOT_MERGE_LINE)}`, failing(HOLD_STEP)],
"both steps failed with one exit": [`${logOf(PATH_HOLD)}\r\n${contractLog(DO_NOT_MERGE_LINE)}`.replace(/\r\n[^\r\n]*exit code 1\.(?=\r\n)/, ""), failing(CONTRACT_STEP, HOLD_STEP)],
"the hold step failed with only the label": [`${logOf()}\r\n${contractLog(DO_NOT_MERGE_LINE)}`, failing(CONTRACT_STEP, HOLD_STEP)],
"the contract step cancelled": [contractLog(DO_NOT_MERGE_LINE), { jobs: heldJobs(ciJob(CI_STEPS.map(([n, c]) => [n, n === CONTRACT_STEP ? "cancelled" : n === HOLD_STEP ? "success" : c]))) }],
"the fail step's line missing": [`${oldContractLog(DO_NOT_MERGE_LINE)}\r\n2026-10-28T16:21:33.0000001Z ##[error]Process completed with exit code 1.`, failing(CONTRACT_STEP)],
"the fail step's line twice": [`${contractLog(DO_NOT_MERGE_LINE)}\r\n2026-10-28T16:21:33.0000002Z ##[error]${CONTRACT_LINE}`, failing(CONTRACT_STEP)],
"the fail step's line with no contract failure": [`${failStep}`, failing(CONTRACT_STEP)],
"the old and new contract steps both failed": [contractLog(DO_NOT_MERGE_LINE), { jobs: heldJobs(ciJob([[OLD_CONTRACT_STEP, "failure"], ...CI_STEPS.map(([n, c]) => [n, n === CONTRACT_STEP ? "failure" : n === HOLD_STEP ? "success" : c])])) }],
};
for (const [name, [log, setup]] of Object.entries(cases)) {
assert.equal(await held(log, setup), "not-a-passing-run", name);
}
});

// Judging a held head loosens no hold: ci-status still fails on the label
// (check-contract, its default label name, no continue-on-error), and the
// merge queue's step still refuses a queued pull request that carries it.
/**
* Judging a held head loosens no hold: ci-status still fails on the label
* (check-contract in the report-ci-status composite, its default label name,
* and the fail step on the composite's contract output, with its own line),
* and the merge queue's step still refuses a queued pull request that carries it.
*/
test("do-not-merge still fails ci-status and the merge queue", () => {
const workflow = readFileSync(new URL("../../workflows/pr-require-checks.yml", import.meta.url), "utf8");
const step = (name) => new RegExp(`^ {6}- name: ${name}\\n((?: {8}.*\\n|\\n)*)`, "m").exec(workflow)?.[1] ?? "";
const contract = step(CONTRACT_STEP);
assert.match(contract, /^ {8}uses: melodic-software\/ci-workflows\/\.github\/actions\/pr-require-checks\/check-contract@[0-9a-f]{40} /m);
assert.doesNotMatch(contract, /do-not-merge-label|continue-on-error|^ {8}if:/m);
const report = step("Aggregate lane results");
assert.match(report, /^ {8}id: report$/m);
assert.match(report, /^ {8}uses: melodic-software\/ci-workflows\/\.github\/actions\/pr-require-checks\/report-ci-status@[0-9a-f]{40} /m);
assert.doesNotMatch(report, /do-not-merge-label|continue-on-error/m);
const fail = step(CONTRACT_STEP);
assert.match(fail, /^ {8}if: \$\{\{ !cancelled\(\) && \(steps\.report\.outputs\.contract != 'success' \|\| steps\.report\.outputs\.draft != 'success'\) \}\}$/m);
assert.ok(fail.includes(`echo "::error::${CONTRACT_LINE}"\n exit 1\n`), "the fail step writes CONTRACT_LINE and exits 1");
assert.doesNotMatch(fail, /continue-on-error/m);
assert.doesNotMatch(workflow, /pr-require-checks\/check-contract@/);
assert.match(step("Fail a queued pull request carrying a hold label"), /^ {8}if: github\.event_name == 'merge_group'$/m);
assert.deepEqual(labelHolds([{ name: "do-not-merge" }], null, 41), [
"#41 carries the 'do-not-merge' label; the merge queue removes it. Remove the label and re-queue to merge.",
Expand Down
Loading
Loading