Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

ci: preserve required checks after pull request edits (#1944)

Michael D'Angeloe3ba88229582
diff --git a/.github/scripts/check-ci-results.mjs b/.github/scripts/check-ci-results.mjs
index dc55d6036..b40804f5f 100644
--- a/.github/scripts/check-ci-results.mjs
+++ b/.github/scripts/check-ci-results.mjs
@@ -4,6 +4,7 @@ export function failedChecks(needs) {
if (needs["classify-changes"]?.result !== "success")
return ["classify-changes"];
const selected = needs["classify-changes"].outputs;
+ if (selected["source-run"]) return [];
const required = ["static-checks"];
const groups = {
"package-required": ["native", "package", "compatibility"],
diff --git a/.github/scripts/test-ci-selection.mjs b/.github/scripts/test-ci-selection.mjs
index 034844ed5..7aaa22dd4 100644
--- a/.github/scripts/test-ci-selection.mjs
+++ b/.github/scripts/test-ci-selection.mjs
@@ -396,3 +396,17 @@ test("documentation requires static checks and explicit selection, without skipp
);
}
});
+
+test("only an authenticated, successful classifier can propagate a source result", () => {
+ const classification = {
+ result: "success",
+ outputs: { "source-run": "123" },
+ };
+ assert.deepEqual(failedChecks({ "classify-changes": classification }), []);
+ for (const result of ["failure", "cancelled", "skipped"]) {
+ assert.deepEqual(
+ failedChecks({ "classify-changes": { ...classification, result } }),
+ ["classify-changes"],
+ );
+ }
+});
diff --git a/.github/scripts/test-verify-pr-source.mjs b/.github/scripts/test-verify-pr-source.mjs
new file mode 100644
index 000000000..2cfa29f1e
--- /dev/null
+++ b/.github/scripts/test-verify-pr-source.mjs
@@ -0,0 +1,275 @@
+import assert from "node:assert/strict";
+import { execFileSync } from "node:child_process";
+import { mkdtempSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import test from "node:test";
+import { pathToFileURL } from "node:url";
+import {
+ checkCheckout,
+ confirmEdit,
+ realSource,
+ verifyEdit,
+} from "./verify-pr-source.mjs";
+
+const pr = {
+ number: 42,
+ base: { ref: "main", sha: "base", repo: { id: 1 } },
+ head: { ref: "feature", sha: "head", repo: { id: 2 } },
+};
+const sha = "merge",
+ target = { ...pr, merge_commit_sha: sha };
+const passed = { status: "completed", conclusion: "success" };
+function run(id, changes = {}) {
+ return {
+ id,
+ run_number: id,
+ run_attempt: 1,
+ run_started_at: id,
+ updated_at: id + 1,
+ event: "pull_request",
+ head_sha: "head",
+ pull_requests: [pr],
+ referenced_workflows: [{ ref: "refs/pull/42/merge", sha }],
+ display_title: "Source CI · PR #42 → main",
+ ...passed,
+ ...changes,
+ };
+}
+const edit = (id, changes) =>
+ run(id, { display_title: "PR edit CI · PR #42 → main", ...changes });
+function evidence(id, selected = "success") {
+ const names = [
+ "ci",
+ "classify changes",
+ ...["ubuntu", "macos", "windows"].map((os) => os + "-latest / node-22"),
+ ];
+ const selection = {
+ name: "Select required checks",
+ status: "completed",
+ conclusion: selected,
+ };
+ const jobs = names.map((name) => ({
+ name,
+ run_id: id,
+ run_attempt: 1,
+ ...passed,
+ steps: [selection],
+ }));
+ return { total_count: jobs.length, jobs };
+}
+function fixture(
+ history,
+ { jobs = evidence, targets = [target], wait = false, runAttempt = 1 } = {},
+) {
+ let current = [],
+ live = target;
+ const api = async (path) => {
+ if (path.startsWith("pulls/")) {
+ live = targets.shift() ?? live;
+ if (live instanceof Error) throw live;
+ return live;
+ }
+ const runId = path.match(/runs\/(\d+)\/jobs/);
+ if (runId) return jobs(Number(runId[1]));
+ current = history.shift() ?? current;
+ if (current instanceof Error) throw current;
+ if (!Array.isArray(current)) return current;
+ const runs = [edit(99, { run_attempt: runAttempt }), ...current];
+ return { total_count: runs.length, workflow_runs: runs };
+ };
+ const input = { pr, sha, runId: 99, runAttempt, api };
+ return {
+ check: () => verifyEdit(input, () => wait),
+ finish: (id, classifierAttempt = runAttempt) =>
+ confirmEdit(input, id, classifierAttempt),
+ };
+}
+
+test("the usual source and repeated metadata edits verify a single actual source job list", async () => {
+ const source = run(2),
+ edits = [edit(8), edit(5), source];
+ const inspected = [];
+ const result = await fixture([edits], {
+ jobs: (id) => {
+ inspected.push(id);
+ return evidence(id);
+ },
+ }).check();
+ assert.equal(result, 2);
+ assert.deepEqual(inspected, [2]);
+});
+
+test("full qualification covers missing, ambiguous, ineligible and retargeted histories", async () => {
+ for (const invalid of [
+ { event: "workflow_dispatch" },
+ { head_sha: "another" },
+ { pull_requests: [] },
+ { display_title: "Source CI · PR #42 → another-target" },
+ { pull_requests: [{ ...pr, base: { ...pr.base, sha: "old" } }] },
+ { pull_requests: [{ ...pr, head: { ...pr.head, repo: { id: 9 } } }] },
+ { referenced_workflows: [] },
+ { referenced_workflows: [{ ref: "refs/pull/3/merge", sha }] },
+ { referenced_workflows: [{ ref: "refs/pull/42/merge", sha: "old" }] },
+ { run_attempt: 2 },
+ { conclusion: "cancelled" },
+ ])
+ assert.equal(await fixture([[run(2, invalid)]]).check(), "full");
+ for (const history of [
+ [],
+ [run(99)],
+ [run(5), run(2)],
+ [run(2), edit(5, { conclusion: "failure" }), edit(8)],
+ [run(2), edit(5, { conclusion: "cancelled" }), edit(8)],
+ { total_count: 1, workflow_runs: [run(2)] }, // Snapshot predates this edit.
+ { total_count: 2, workflow_runs: [run(2)] },
+ ]) {
+ assert.equal(await fixture([history]).check(), "full");
+ }
+});
+
+test("only fresh canonical source jobs and genuine selection can qualify a source", () => {
+ const source = run(2),
+ page = evidence(2);
+ assert.ok(realSource(page, source));
+ for (const change of [
+ { total_count: 99 },
+ { jobs: page.jobs.slice(1) },
+ { total_count: 6, jobs: [...page.jobs, page.jobs[0]] },
+ { jobs: page.jobs.map((j) => ({ ...j, run_id: 1 })) },
+ { jobs: page.jobs.map((j) => ({ ...j, run_attempt: 2 })) },
+ {
+ jobs: page.jobs.map((j) =>
+ j.name === "ci" ? { ...j, conclusion: "failure" } : j,
+ ),
+ },
+ evidence(2, "skipped"),
+ ])
+ assert.ok(!realSource({ ...page, ...change }, source));
+});
+
+test("pending sources settle, genuine red remains red, and newer attempts cannot be masked", async () => {
+ const green = run(3),
+ red = run(3, { conclusion: "failure" }),
+ pending = run(3, { status: "in_progress" });
+ assert.equal(await fixture([[pending], [green]], { wait: true }).check(), 3);
+ assert.equal(
+ await fixture([[pending], [red]], { wait: true }).check(),
+ "failed",
+ );
+ assert.equal(await fixture([[pending]]).check(), "full");
+ assert.equal(await fixture([[green], [red]]).check(), "failed");
+ assert.equal(
+ await fixture([[green, run(1, { run_attempt: 2 })]]).check(),
+ "full",
+ );
+ assert.equal(
+ await fixture([[edit(8, { conclusion: "failure" }), red]]).check(),
+ "failed",
+ );
+ for (const changed of [
+ [run(3, { run_attempt: 2 })],
+ [run(5, { conclusion: "failure" }), green],
+ ]) {
+ await assert.rejects(
+ fixture([changed]).finish(3),
+ /source qualification changed/,
+ );
+ }
+});
+
+test("retrying a failed edit cannot replace its full checks with older green results", async () => {
+ const retry = fixture([[run(2)]], { runAttempt: 2 });
+ assert.equal(await retry.check(), "full");
+ await assert.rejects(retry.finish(2, 1), /Re-run all jobs/);
+ await assert.rejects(retry.finish(undefined, 1), /Re-run all jobs/);
+ await assert.rejects(retry.finish(2), /source qualification changed/);
+ await retry.finish();
+});
+
+test("even full fallback needs a current target; repeat this check just before the aliases", async () => {
+ const stale = { ...target, base: { ...pr.base, ref: "other" } },
+ unavailable = new Error("target unavailable");
+ for (const history of [
+ [],
+ [run(3, { status: "in_progress" })],
+ new Error("history unavailable"),
+ ]) {
+ await assert.rejects(
+ fixture([history], { targets: [target, stale] }).check(),
+ /target changed/,
+ );
+ await assert.rejects(
+ fixture([history], { targets: [target, unavailable] }).check(),
+ /target unavailable/,
+ );
+ }
+ assert.equal(
+ await fixture([new Error("history unavailable")]).check(),
+ "full",
+ );
+ await assert.rejects(
+ fixture([], { targets: [stale] }).finish(),
+ /target changed/,
+ );
+ await assert.rejects(
+ fixture([], { targets: [unavailable] }).finish(),
+ /target unavailable/,
+ );
+});
+
+test("the final gate reads both actual merge parents from a depth-one checkout", (t) => {
+ const root = mkdtempSync(join(tmpdir(), "ci-source-parents-"));
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ const repo = join(root, "source"),
+ checkout = join(root, "checkout");
+ function git(cwd, ...args) {
+ return execFileSync(
+ "git",
+ [
+ "-c",
+ "user.name=CI Fixture",
+ "-c",
+ ...args,
+ ],
+ { cwd, encoding: "utf8", input: "" },
+ ).trim();
+ }
+ git(root, "init", "--quiet", "-b", "main", repo);
+ const tree = git(repo, "mktree"),
+ base = git(repo, "commit-tree", tree, "-m", "base"),
+ head = git(repo, "commit-tree", tree, "-m", "head");
+ const merge = git(
+ repo,
+ "commit-tree",
+ tree,
+ "-p",
+ base,
+ "-p",
+ head,
+ "-m",
+ "merge",
+ );
+ git(repo, "update-ref", "refs/heads/main", merge);
+ git(
+ root,
+ "clone",
+ "--quiet",
+ "--depth=1",
+ pathToFileURL(repo).href,
+ checkout,
+ );
+ assert.equal(git(checkout, "rev-parse", "--is-shallow-repository"), "true");
+ const pull = { base: { sha: base }, head: { sha: head } };
+ checkCheckout(pull, merge, checkout);
+ assert.throws(
+ () => checkCheckout({ ...pull, base: { sha: head } }, merge, checkout),
+ /checked-out merge/,
+ );
+ assert.throws(
+ () => checkCheckout({ ...pull, head: { sha: base } }, merge, checkout),
+ /checked-out merge/,
+ );
+ assert.throws(() => checkCheckout(pull, base, checkout), /checked-out merge/);
+});
diff --git a/.github/scripts/verify-pr-source.mjs b/.github/scripts/verify-pr-source.mjs
new file mode 100644
index 000000000..2622ad2d8
--- /dev/null
+++ b/.github/scripts/verify-pr-source.mjs
@@ -0,0 +1,212 @@
+import { execFileSync } from "node:child_process";
+import { appendFileSync, readFileSync } from "node:fs";
+import { setTimeout as sleep } from "node:timers/promises";
+import { pathToFileURL } from "node:url";
+
+const utf8 = { encoding: "utf8" };
+const successful = (job) =>
+ job.status === "completed" && job.conclusion === "success";
+
+function samePull(candidate, pr) {
+ return (
+ candidate?.number === pr.number &&
+ ["head", "base"].every(
+ (side) =>
+ candidate[side]?.ref === pr[side].ref &&
+ candidate[side]?.sha === pr[side].sha &&
+ candidate[side].repo?.id === pr[side].repo.id,
+ )
+ );
+}
+
+export function checkCheckout(pr, sha, cwd) {
+ const git = (args) =>
+ execFileSync("git", args, { encoding: "utf8", cwd }).trim();
+ // The CI gate uses a depth-one checkout. Read its parent IDs from the raw object.
+ const headers = git(["cat-file", "-p", "HEAD"])
+ .split("\n\n", 1)[0]
+ .split("\n");
+ const parents = headers
+ .filter((h) => h.startsWith("parent "))
+ .map((h) => h.slice(7));
+ if (
+ git(["rev-parse", "HEAD"]) !== sha ||
+ parents.join(" ") !== `${pr.base.sha} ${pr.head.sha}`
+ )
+ throw new Error(
+ "The checked-out merge does not match the pull request base and head. Reopen the pull request or push a commit to qualify its current target.",
+ );
+}
+
+export async function confirmTarget(pr, sha, api) {
+ const live = await api(`pulls/${pr.number}`);
+ if (!samePull(live, pr) || live.merge_commit_sha !== sha)
+ throw new Error(
+ "The pull request target changed while its checks were running.",
+ );
+}
+
+export function realSource(page, run) {
+ const required = [
+ "ci",
+ "classify changes",
+ ...["ubuntu", "macos", "windows"].map((os) => `${os}-latest / node-22`),
+ ];
+ const jobs = page.jobs.filter((job) => required.includes(job.name));
+ if (
+ page.total_count !== page.jobs.length ||
+ jobs.length !== required.length ||
+ new Set(jobs.map((j) => j.name)).size !== required.length ||
+ !jobs.every(
+ (job) =>
+ job.run_id === run.id && job.run_attempt === 1 && successful(job),
+ )
+ )
+ return false;
+ return jobs
+ .find((job) => job.name === "classify changes")
+ .steps.some(
+ (step) => step.name === "Select required checks" && successful(step),
+ );
+}
+
+function sourceCandidate(runs, { pr, sha }) {
+ const target = `PR #${pr.number} → ${pr.base.ref}`;
+ const source = `Source CI · ${target}`;
+ const edit = `PR edit CI · ${target}`;
+ function identified(run) {
+ const refs = run.referenced_workflows;
+ return (
+ run.event === "pull_request" &&
+ run.head_sha === pr.head.sha &&
+ run.run_attempt === 1 &&
+ run.pull_requests.some((p) => samePull(p, pr)) &&
+ refs?.length &&
+ refs.every(
+ (ref) => ref.sha === sha && ref.ref === `refs/pull/${pr.number}/merge`,
+ ) &&
+ [source, edit].includes(run.display_title)
+ );
+ }
+ if (!runs.length || !runs.every(identified)) return "full";
+ const [first, ...later] = runs; // Oldest first.
+ if (
+ first.display_title !== source ||
+ later.some((r) => r.display_title !== edit)
+ )
+ return "full";
+ if (runs.some((r) => r.status !== "completed")) return "pending";
+ if (runs.every(successful)) return first;
+ if (runs.every((r) => r.conclusion === "failure")) return "failed";
+ return "full";
+}
+
+async function verifyHistory(input, wait) {
+ // A retry keeps the ID of its potentially failed previous qualification.
+ if (input.runAttempt !== 1) return "full";
+ const { pr, runId, api } = input;
+ async function candidate() {
+ const page = await api(
+ `actions/workflows/node-ci.yml/runs?event=pull_request&head_sha=${pr.head.sha}&per_page=100`,
+ );
+ if (
+ page.total_count !== page.workflow_runs.length ||
+ !page.workflow_runs.some(
+ (run) => run.id === runId && run.run_attempt === 1,
+ )
+ )
+ return "full";
+ // A head may belong to several PRs. Keep unassociated runs so ambiguous histories go full.
+ const runs = page.workflow_runs.filter(
+ (run) =>
+ run.id !== runId &&
+ (!run.pull_requests.length ||
+ run.pull_requests.some((p) => p.number === pr.number)),
+ );
+ return sourceCandidate(
+ runs.sort((a, b) => a.run_number - b.run_number),
+ input,
+ );
+ }
+ let source = await candidate();
+ while (source === "pending" && wait && (await wait()))
+ source = await candidate();
+ if (typeof source === "string") return source === "pending" ? "full" : source;
+ const page = await api(
+ `actions/runs/${source.id}/jobs?filter=latest&per_page=100`,
+ );
+ if (!realSource(page, source)) return "full";
+ const latest = await candidate();
+ if (latest === "failed") return "failed";
+ return latest.id === source.id ? source.id : "full";
+}
+
+export async function verifyEdit(input, wait) {
+ const { pr, sha, api } = input;
+ await confirmTarget(pr, sha, api);
+ let result;
+ try {
+ result = await verifyHistory(input, wait);
+ } catch (error) {
+ console.log(
+ `Source evidence unavailable. Running full qualification. ${error.message}`,
+ );
+ result = "full";
+ }
+ // A history failure can select full CI only while the originating PR target is still current.
+ await confirmTarget(pr, sha, api);
+ return result;
+}
+
+export async function confirmEdit(input, expectedId, classifierAttempt) {
+ if (input.runAttempt !== classifierAttempt)
+ throw new Error("Re-run all jobs to qualify this pull request edit.");
+ if (expectedId && (await verifyHistory(input)) !== expectedId)
+ throw new Error(
+ "The selected source qualification changed before the CI gate finished.",
+ );
+ await confirmTarget(input.pr, input.sha, input.api);
+}
+
+if (
+ process.argv[1] &&
+ import.meta.url === pathToFileURL(process.argv[1]).href
+) {
+ const env = process.env;
+ const { pull_request: pr } = JSON.parse(
+ readFileSync(env.GITHUB_EVENT_PATH, "utf8"),
+ );
+ const sha = env.GITHUB_SHA;
+ checkCheckout(pr, sha);
+ function api(path) {
+ const endpoint = `repos/${env.GITHUB_REPOSITORY}/${path}`;
+ return JSON.parse(execFileSync("gh", ["api", endpoint], utf8));
+ }
+ const input = {
+ pr,
+ sha,
+ runId: Number(env.GITHUB_RUN_ID),
+ runAttempt: Number(env.GITHUB_RUN_ATTEMPT),
+ api,
+ };
+ if (process.argv[2] === "confirm-target")
+ await confirmEdit(
+ input,
+ Number(env.VERIFIED_SOURCE_RUN),
+ Number(env.CLASSIFIER_ATTEMPT),
+ );
+ else {
+ // Leave five minutes of the 40-minute classifier budget for ordinary full selection.
+ const deadline = Date.now() + 35 * 60_000;
+ const result = await verifyEdit(input, async () => {
+ if (Date.now() >= deadline) return false;
+ await sleep(30_000);
+ return true;
+ });
+ console.log(`Source qualification: ${result}`);
+ appendFileSync(env.GITHUB_OUTPUT, `edit-attempt=${input.runAttempt}\n`);
+ if (result === "failed") process.exitCode = 1;
+ if (typeof result === "number")
+ appendFileSync(env.GITHUB_OUTPUT, `source-run=${result}\n`);
+ }
+}
diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml
index 71213c9cc..6fbccb609 100644
--- a/.github/workflows/node-ci.yml
+++ b/.github/workflows/node-ci.yml
@@ -1,4 +1,6 @@
name: node-ci
+run-name: >-
+ ${{ github.event_name == 'pull_request' && format('{0} · PR #{1} → {2}', github.event.action == 'edited' && github.event.changes.base == null && 'PR edit CI' || 'Source CI', github.event.number, github.base_ref) || '' }}
on:
push:
@@ -20,10 +22,15 @@ concurrency:
jobs:
classify-changes:
name: classify changes
- if: github.event_name != 'pull_request' || github.event.action != 'edited' || github.event.changes.base != null
runs-on: ubuntu-latest
- timeout-minutes: 10
+ timeout-minutes: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.base == null && 40 || 10 }}
+ permissions:
+ contents: read
+ actions: read
+ pull-requests: read
outputs:
+ source-run: ${{ steps.proof.outputs.source-run }}
+ edit-attempt: ${{ steps.proof.outputs.edit-attempt }}
source-required: ${{ steps.scope.outputs.source-required }}
package-required: ${{ steps.scope.outputs.package-required }}
action-ci: ${{ steps.scope.outputs.action-ci }}
@@ -39,11 +46,18 @@ jobs:
with:
fetch-depth: 2
persist-credentials: false
+ - name: Verify pull request source
+ id: proof
+ if: &metadata-edit github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.base == null
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: node .github/scripts/verify-pr-source.mjs
- name: Select required checks
id: scope
+ if: steps.proof.outputs.source-run == ''
env:
EVENT_NAME: ${{ github.event_name }}
- BASE_CHANGED: ${{ github.event.changes.base != null }}
+ BASE_CHANGED: ${{ github.event.action == 'edited' }}
run: node .github/scripts/select-ci-checks.mjs
workflow-quality:
@@ -60,6 +74,7 @@ jobs:
static-checks:
name: typecheck and formatting
+ if: needs.classify-changes.outputs.source-run == ''
needs: classify-changes
runs-on: ubuntu-latest
timeout-minutes: 20
@@ -90,7 +105,7 @@ jobs:
GH_TOKEN: ${{ github.token }}
run: node --experimental-strip-types sdk/typescript/scripts/check-devcontainer-cooldown.mts
- name: Test CI selection and result gating
- run: node --test .github/scripts/test-ci-selection.mjs
+ run: node --test .github/scripts/test-ci-selection.mjs .github/scripts/test-verify-pr-source.mjs
- name: Typecheck
run: pnpm --dir sdk/typescript run types
- name: Check formatting
@@ -454,7 +469,7 @@ jobs:
run: node --experimental-strip-types --test evals/workflow-routing/test_*.mts
ci:
- name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.base == null && 'metadata / ' || '' }}ci
+ name: ci
needs:
[
classify-changes,
@@ -473,18 +488,29 @@ jobs:
windows-test,
windows-verify,
]
- if: &source-aggregate always() && (github.event_name != 'pull_request' || github.event.action != 'edited' || github.event.changes.base != null)
+ if: &source-aggregate always()
runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ actions: read
+ pull-requests: read
steps:
- *checkout-repository
- name: Require selected checks
env:
CI_RESULTS: ${{ toJSON(needs) }}
run: node .github/scripts/check-ci-results.mjs
+ - name: Confirm pull request target
+ if: *metadata-edit
+ env:
+ GH_TOKEN: ${{ github.token }}
+ VERIFIED_SOURCE_RUN: ${{ needs.classify-changes.outputs.source-run }}
+ CLASSIFIER_ATTEMPT: ${{ needs.classify-changes.outputs.edit-attempt }}
+ run: node .github/scripts/verify-pr-source.mjs confirm-target
# Retain required names until the repository ruleset has migrated to `ci`.
required-test:
- name: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' && github.event.changes.base == null && 'metadata / ' || '' }}${{ matrix.os }} / node-22
+ name: ${{ matrix.os }} / node-22
needs: [classify-changes, ci]
if: *source-aggregate
runs-on: ubuntu-latest
@@ -496,6 +522,14 @@ jobs:
- name: Require CI gate
if: needs.ci.result != 'success'
run: exit 1
+ - name: Require the edit classifier from this attempt
+ if: >-
+ github.event_name == 'pull_request' && github.event.action == 'edited' &&
+ github.event.changes.base == null &&
+ needs['classify-changes'].outputs['edit-attempt'] != github.run_attempt
+ run: |
+ echo 'Re-run all jobs to qualify this pull request edit.'
+ exit 1
windows-test:
if: needs.classify-changes.outputs.source-required == 'true'
diff --git a/docs/ci.md b/docs/ci.md
index 49283610c..ba5b37b66 100644
--- a/docs/ci.md
+++ b/docs/ci.md
@@ -53,7 +53,14 @@ implementation or eval changes with product code also selects full qualification
Every push to `main`, nightly run, manual `node-ci` dispatch, and pull-request
retarget runs the complete version matrices. Release automation still requires
successful CI for the exact main commit before publication. Title and body edits
-neither cancel source runs nor satisfy their required check names.
+leave source CI running. On an edit, CI checks the source result for the same
+pull request, base, head and test merge. It waits for a running source check and
+reports a verified result, including static checks, through the required checks.
+Only the original source run and an uninterrupted sequence of successful edits
+can carry a green result. A cancelled or retried run, a changed target, missing
+evidence or conflicting results require full qualification. Use **Re-run all
+jobs** to retry an edit. A partial retry cannot refresh a previous attempt's
+required checks.
## Required gate
@@ -71,7 +78,8 @@ this order.
documentation pull requests, including a failing selected-check example.
2. Change the repository's required status checks to `ci` and `Validate PR Title`,
preserving their GitHub Actions integration and all unrelated protection rules.
-3. Remove the compatibility matrix `required-test` in a follow-up.
+3. Remove the compatibility matrix `required-test` and its three OS check
+ names from source verification in a follow-up.
Do not remove the old contexts before changing the rules. The workflow change
itself does not change repository protection settings.
@@ -81,7 +89,7 @@ itself does not change repository protection settings.
The workflow-selection and gate tests run without installing dependencies:
```bash
-node --test .github/scripts/test-ci-selection.mjs
+node --test .github/scripts/test-ci-selection.mjs .github/scripts/test-verify-pr-source.mjs
```
The [SDK testing guide](../sdk/typescript/TESTING.md) describes local behavioral
diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.ts
index 6ea8ea03c..96e5f1fc9 100644
--- a/sdk/typescript/tests-ts/release-automation.test.ts
+++ b/sdk/typescript/tests-ts/release-automation.test.ts
@@ -3829,7 +3829,7 @@ describe("GitHub release workflow safeguards", () => {
needs?: string | string[];
uses?: string;
outputs?: Record<string, string>;
- "timeout-minutes"?: number;
+ "timeout-minutes"?: number | string;
steps: Array<{
if?: string;
name?: string;
@@ -3848,8 +3848,10 @@ describe("GitHub release workflow safeguards", () => {
"${{ github.event_name == 'pull_request' }}",
);
const classifier = workflow.jobs["classify-changes"]!;
- expect(classifier["timeout-minutes"]).toBe(10);
- expect(classifier.if).toContain("github.event.changes.base != null");
+ expect(classifier["timeout-minutes"]).toEqual(
+ expect.stringContaining("40 || 10"),
+ );
+ expect(classifier.if).toBeUndefined();
const checkout = classifier.steps.find(
({ name }) => name === "Checkout repository for change classification",
);
@@ -3859,6 +3861,9 @@ describe("GitHub release workflow safeguards", () => {
});
expect(checkout).not.toHaveProperty("if");
+ expect(workflow.jobs["static-checks"]?.if).toBe(
+ "needs.classify-changes.outputs.source-run == ''",
+ );
const aggregates = ["ci", "required-test"];
const checks = Object.entries(workflow.jobs).filter(
([name]) => name !== "classify-changes" && !aggregates.includes(name),
@@ -3886,8 +3891,13 @@ describe("GitHub release workflow safeguards", () => {
.href
)) as { failedChecks(needs: unknown): string[] };
const classifierOutputs = classifier.outputs!;
+ expect(classifierOutputs["source-run"]).toBe(
+ "${{ steps.proof.outputs.source-run }}",
+ );
const flags = Object.keys(classifierOutputs).filter(
- (key) => !key.endsWith("-matrix"),
+ (key) =>
+ !["source-run", "edit-attempt"].includes(key) &&
+ !key.endsWith("-matrix"),
);
for (const enabled of flags) {
expect(classifierOutputs[enabled]).toBe(
@@ -3897,7 +3907,8 @@ describe("GitHub release workflow safeguards", () => {
flags.map((key) => [key, String(key === enabled)]),
);
const scheduled = checks.filter(
- ([, job]) =>
+ ([name, job]) =>
+ name === "static-checks" ||
!job.if ||
job.if === `needs.classify-changes.outputs.${enabled} == 'true'`,
);
diff --git a/sdk/typescript/tests-ts/workflow-quality.test.ts b/sdk/typescript/tests-ts/workflow-quality.test.ts
index 8187830be..f60fa77b3 100644
--- a/sdk/typescript/tests-ts/workflow-quality.test.ts
+++ b/sdk/typescript/tests-ts/workflow-quality.test.ts
@@ -80,13 +80,20 @@ test.each([
(action, changes, sourceEvent) => {
const context = eventContext(action, changes);
const classifier = ci.jobs["classify-changes"]!;
- expect(expression(classifier.if!, context)).toBe(sourceEvent);
+ expect(classifier.if).toBeUndefined();
+ const proof = classifier.steps.find(
+ ({ name }) => name === "Verify pull request source",
+ )!;
+ expect(expression(proof.if!, context)).toBe(!sourceEvent);
+ const confirmation = ci.jobs["ci"]!.steps.at(-1)!;
+ expect(confirmation.run).toBe(
+ "node .github/scripts/verify-pr-source.mjs confirm-target",
+ );
+ expect(expression(confirmation.if!, context)).toBe(!sourceEvent);
for (const [id, matrix, name] of aggregates) {
const aggregate = ci.jobs[id]!;
- expect(expression(aggregate.if!, context)).toBe(sourceEvent);
- expect(interpolate(aggregate.name, { ...context, matrix })).toBe(
- sourceEvent ? name : `metadata / ${name}`,
- );
+ expect(expression(aggregate.if!, context)).toBe(true);
+ expect(interpolate(aggregate.name, { ...context, matrix })).toBe(name);
}
const sourceGroup = interpolate(
ci.concurrency.group,
@@ -121,9 +128,7 @@ test("all source jobs depend on classification and titles cannot block source ch
}
const classifier = ci.jobs["classify-changes"]!;
expect(JSON.stringify(classifier)).not.toContain("PR_TITLE");
- expect(
- expression(classifier.if!, eventContext("opened", {}, "Invalid title")),
- ).toBe(true);
+ expect(classifier.if).toBeUndefined();
});
const musl = Bun.YAML.parse(
@@ -403,4 +408,24 @@ test("legacy required check names propagate the final CI gate result", () => {
result !== "success",
);
}
+ const retry = forwarder.steps.find(
+ (step) => step.name === "Require the edit classifier from this attempt",
+ )!;
+ expect(retry.run).toContain("exit 1");
+ for (const [action, changes, classifier, refuse] of [
+ ["synchronize", {}, "", false],
+ ["edited", { base: {} }, "", false],
+ ["edited", {}, "", true],
+ ["edited", {}, "1", true],
+ ["edited", {}, "2", false],
+ ] as const) {
+ expect(
+ expression(retry.if!, {
+ needs: {
+ "classify-changes": { outputs: { "edit-attempt": classifier } },
+ },
+ github: { ...eventContext(action, changes).github, run_attempt: "2" },
+ }),
+ ).toBe(refuse);
+ }
});