Skip to content

Commit 6b17322

Browse files
committed
ci: admit the borrowed-push gate skip and seed-only credential guard
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jQztfi9hnsaBeBVcCU
1 parent 52c37af commit 6b17322

1 file changed

Lines changed: 91 additions & 10 deletions

File tree

‎scripts/check-shard-attestation.mjs‎

Lines changed: 91 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
* `--emit` writes `<job>-<shard>-of-<total>.json` ("I ran and I passed"),
4747
* `actions/upload-artifact` publishes it as `shard-attest-<job>-<n>-of-<N>`.
4848
*
49+
* (One guard is admitted on that pair since #31519, SEED_ONLY_CREDENTIAL_IF
50+
* below: it names no status function, so the implicit success() still holds,
51+
* and it withholds the pair only on a seed-only leg of a push run that
52+
* borrowed the merge queue's verdict.)
53+
*
4954
* The gate downloads every matching artifact of ITS OWN RUN and requires the
5055
* attested set to equal the DECLARED roster. A shard that was never scheduled
5156
* publishes nothing, so it cannot be counted — which is exactly the property
@@ -128,7 +133,9 @@
128133
* - The gates keep `if: always()` and their `name:`. Both are contracts:
129134
* branch protection requires the bare `Test Core` / `Dogfood Regression
130135
* Gate` contexts, and a gate that skips publishes no context at all, which
131-
* is the #3622 repo-wide merge deadlock.
136+
* is the #3622 repo-wide merge deadlock. The one admitted variant is
137+
* BORROWED_PUSH_GATE_IF (#31519), which skips only on a push run that
138+
* borrowed the queue's verdict: a push gates no merge.
132139
*
133140
* ## Why a declared negative is still a veto
134141
*
@@ -235,6 +242,31 @@ const ARTIFACT_PREFIX = 'shard-attest-';
235242
/** The gate jobs that carry a branch-protection-required context. */
236243
const REQUIRED_GATE_JOBS = ['test-gate', 'dogfood-gate'];
237244

245+
/**
246+
* A push run that BORROWED the merge queue's verdict (#31519, ci.yml's
247+
* `queue-verdict` job, scripts/ci/scheduled-full-run.mjs HALF 4) runs its
248+
* shards as seed-only legs: no test, so no credential. Two spellings, and only
249+
* these, are admitted for it:
250+
*
251+
* - a gate's job-level `if:` may be BORROWED_PUSH_GATE_IF instead of
252+
* `always()`. The probe runs on `push` alone, so on every other event the
253+
* output is empty, the conjunct is true, and the gate is `always()` as
254+
* before. On a covered push it skips, and a push run gates no merge, so no
255+
* required context goes missing (#3622 is about pull requests and the
256+
* queue).
257+
* - the attestation pair may carry SEED_ONLY_CREDENTIAL_IF, the same on both
258+
* steps. It names no status function, so GitHub still wraps it in the
259+
* implicit `success()` that makes the credential mean "every earlier step
260+
* succeeded"; it only withholds the pair on a seed-only leg.
261+
*
262+
* Either spelling needs `queue-verdict` in the job's `needs:`, or the output
263+
* reads empty and the guard is decoration. `!= 'true'` on purpose: an empty
264+
* output (a skipped or dead probe) reads as "run everything".
265+
*/
266+
export const QUEUE_VERDICT_JOB = 'queue-verdict';
267+
export const SEED_ONLY_CREDENTIAL_IF = `needs.${QUEUE_VERDICT_JOB}.outputs.covered != 'true'`;
268+
export const BORROWED_PUSH_GATE_IF = `always() && ${SEED_ONLY_CREDENTIAL_IF}`;
269+
238270
const SCRIPT_BASENAME = 'check-shard-attestation.mjs';
239271

240272
/** Repository root, resolved from this file rather than from the cwd. */
@@ -1080,10 +1112,15 @@ export async function scanWorkflow(root) {
10801112
const text = runTextOf(job);
10811113
const legs = [...text.matchAll(LEG_TOKEN)].map((m) => ({ job: m[1], total: Number(m[2]) }));
10821114
gates.set(id, legs);
1083-
if (job.if !== 'always()') {
1084-
problems.push(`job '${id}' is an aggregate gate but its job-level if: is ${JSON.stringify(job.if)}, not always() — a gate that skips publishes no required context (#3622).`);
1085-
}
10861115
const needs = Array.isArray(job.needs) ? job.needs : job.needs ? [job.needs] : [];
1116+
if (job.if !== 'always()' && job.if !== BORROWED_PUSH_GATE_IF) {
1117+
problems.push(
1118+
`job '${id}' is an aggregate gate but its job-level if: is ${JSON.stringify(job.if)}, not always() ` +
1119+
`(or ${JSON.stringify(BORROWED_PUSH_GATE_IF)}, #31519) — a gate that skips publishes no required context (#3622).`,
1120+
);
1121+
} else if (job.if === BORROWED_PUSH_GATE_IF && !needs.includes(QUEUE_VERDICT_JOB)) {
1122+
problems.push(`gate '${id}' reads needs.${QUEUE_VERDICT_JOB} in its if: without listing '${QUEUE_VERDICT_JOB}' in needs:, so the output is always empty (#31519).`);
1123+
}
10871124
if (!needs.includes('filter')) {
10881125
problems.push(`gate '${id}' does not list 'filter' in needs:, so it cannot apply the #4928 skipped-only-when-filter-succeeded guard.`);
10891126
}
@@ -1233,8 +1270,15 @@ export async function scanWorkflow(root) {
12331270
);
12341271
continue;
12351272
}
1236-
if (emit.if !== undefined || upload.if !== undefined) {
1237-
problems.push(`job '${leg.job}' guards its attestation steps with an if: — the credential must mean "every earlier step succeeded", which only an unguarded step says (#6082).`);
1273+
const targetNeeds = Array.isArray(target.needs) ? target.needs : target.needs ? [target.needs] : [];
1274+
const seedOnlyGuard = emit.if === SEED_ONLY_CREDENTIAL_IF && upload.if === SEED_ONLY_CREDENTIAL_IF;
1275+
if (!seedOnlyGuard && (emit.if !== undefined || upload.if !== undefined)) {
1276+
problems.push(
1277+
`job '${leg.job}' guards its attestation steps with an if: — the credential must mean "every earlier step succeeded", which only an unguarded step says (#6082). ` +
1278+
`The one guard admitted is ${JSON.stringify(SEED_ONLY_CREDENTIAL_IF)} on BOTH steps (#31519).`,
1279+
);
1280+
} else if (seedOnlyGuard && !targetNeeds.includes(QUEUE_VERDICT_JOB)) {
1281+
problems.push(`job '${leg.job}' guards its attestation pair on needs.${QUEUE_VERDICT_JOB} without listing '${QUEUE_VERDICT_JOB}' in needs: (#31519).`);
12381282
}
12391283
const declaredName = String(upload?.with?.name ?? '');
12401284
if (!declaredName.startsWith(`${ARTIFACT_PREFIX}${leg.job}-`) || !declaredName.endsWith(`-of-${leg.total}`)) {
@@ -1695,11 +1739,12 @@ const SELF_TEST_BATTERIES = Object.freeze({
16951739
'#6589: a shard job is not a gate because a step says `--verify`': 23,
16961740
'#26084 a planned roster: only the shards the plan started are counted': 16,
16971741
'#26084 the static guard holds the planned matrix and the gate to one expression': 10,
1742+
'#31519 a borrowed push: the gate skip and the seed-only credential guard': 8,
16981743
});
16991744

17001745
// DELETING an entry silences that battery's floor exactly as effectively as
17011746
// zeroing it, so the roster's own size is pinned too.
1702-
const SELF_TEST_BATTERY_FLOOR = 24;
1747+
const SELF_TEST_BATTERY_FLOOR = 25;
17031748

17041749
// The key an assertion is filed under when no battery is open. It is not a
17051750
// declared battery, so it reds by the same set difference rather than silently
@@ -2710,11 +2755,47 @@ async function selfTest() {
27102755
(await fixture('unmatchable download pattern', (s) => s.replace(' pattern: shard-attest-test-*', ' pattern: shard-attest-nothing-*'))).problems.some((p) => p.includes('none of which matches')),
27112756
'a gate whose download pattern cannot match its legs ⇒ red',
27122757
);
2758+
const EMIT_GUARD = ` - name: Attest this shard ran and passed\n if: ${SEED_ONLY_CREDENTIAL_IF}\n run: |\n node scripts/check-shard-attestation.mjs --emit \\\n --job test`;
2759+
const UPLOAD_GUARD = ` - name: Publish this shard's attestation\n if: ${SEED_ONLY_CREDENTIAL_IF}\n uses: actions/upload-artifact@`;
27132760
assert(
2714-
(await fixture('if: on the credential step', (s) => s.replace(' - name: Attest this shard ran and passed\n run: |\n node scripts/check-shard-attestation.mjs --emit \\\n --job test', ' - name: Attest this shard ran and passed\n if: always()\n run: |\n node scripts/check-shard-attestation.mjs --emit \\\n --job test'))).problems.some((p) => p.includes('guards its attestation steps with an if:')),
2761+
(await fixture('if: on the credential step', (s) => s.replace(EMIT_GUARD, EMIT_GUARD.replace(SEED_ONLY_CREDENTIAL_IF, 'always()')))).problems.some((p) => p.includes('guards its attestation steps with an if:')),
27152762
'an `if:` on the credential step ⇒ red (the credential would stop meaning "every earlier step passed")',
27162763
);
27172764

2765+
// ── #31519: the borrowed push's two admitted spellings, and only those ──
2766+
battery('#31519 a borrowed push: the gate skip and the seed-only credential guard');
2767+
assert(good.includes(EMIT_GUARD) && good.includes(UPLOAD_GUARD), "#31519: ci.yml's test pair carries the seed-only guard on both steps (the anchors below)");
2768+
assert(
2769+
(await fixture('a seed-only guard on one step only', (s) => s.replace(UPLOAD_GUARD, UPLOAD_GUARD.replace(` if: ${SEED_ONLY_CREDENTIAL_IF}\n`, '')))).problems.some((p) => p.includes('on BOTH steps')),
2770+
'#31519: the seed-only guard on the credential step but not its upload ⇒ red',
2771+
);
2772+
assert(
2773+
(await fixture('a widened credential guard', (s) => s.replace(EMIT_GUARD, EMIT_GUARD.replace(SEED_ONLY_CREDENTIAL_IF, `${SEED_ONLY_CREDENTIAL_IF} || failure()`)))).problems.some((p) => p.includes('guards its attestation steps with an if:')),
2774+
'#31519: a guard that adds a status function to the credential ⇒ red',
2775+
);
2776+
assert(
2777+
(await fixture('a credential guard on the wrong spelling', (s) => s.replace(EMIT_GUARD, EMIT_GUARD.replace("!= 'true'", "== 'false'")).replace(UPLOAD_GUARD, UPLOAD_GUARD.replace("!= 'true'", "== 'false'")))).problems.some((p) => p.includes('guards its attestation steps with an if:')),
2778+
"#31519: `== 'false'` (an empty output would withhold the credential) ⇒ red",
2779+
);
2780+
assert(
2781+
(await fixture('a seed-only guard without the probe in needs', (s) => s.replace(' needs: [filter, test-plan, queue-verdict]\n', ' needs: [filter, test-plan]\n'))).problems.some((p) => p.includes("guards its attestation pair on needs.queue-verdict without listing")),
2782+
'#31519: a credential guard on an output the job cannot read ⇒ red',
2783+
);
2784+
const GATE_IF = ` if: ${BORROWED_PUSH_GATE_IF}\n`;
2785+
assert(good.split(GATE_IF).length - 1 >= 2, "#31519: ci.yml's test-gate and dogfood-gate carry the borrowed-push if: (the anchors below)");
2786+
assert(
2787+
(await fixture('a gate skipped on any push', (s) => s.replace(GATE_IF, " if: always() && github.event_name != 'push'\n"))).problems.some((p) => p.includes('is an aggregate gate but its job-level if:')),
2788+
'#31519: a gate skipped on every push, not only a covered one ⇒ red',
2789+
);
2790+
assert(
2791+
(await fixture('a gate under !cancelled() and the probe', (s) => s.replace(GATE_IF, ` if: \${{ !cancelled() && ${SEED_ONLY_CREDENTIAL_IF} }}\n`))).problems.some((p) => p.includes('is an aggregate gate but its job-level if:')),
2792+
'#31519: the borrowed conjunct does not license dropping always() ⇒ red',
2793+
);
2794+
assert(
2795+
(await fixture('a borrowed gate without the probe in needs', (s) => s.replace(' needs: [test, filter, test-plan, queue-verdict]\n', ' needs: [test, filter, test-plan]\n'))).problems.some((p) => p.includes("reads needs.queue-verdict in its if: without listing")),
2796+
'#31519: a gate reading an output it cannot see ⇒ red',
2797+
);
2798+
27182799
// ── #26084: the planned matrix and the gate read one expression ─────────
27192800
battery('#26084 the static guard holds the planned matrix and the gate to one expression');
27202801
const GATE_PLAN = ` OS_TEST_PLAN: \${{ needs.test-plan.outputs.shards || '${ROSTER}' }}\n`;
@@ -2733,11 +2814,11 @@ async function selfTest() {
27332814
'#26084: a gate that is not handed the plan result ⇒ red',
27342815
);
27352816
assert(
2736-
await planProblem('the gate loses the plan job from needs', (s) => s.replace(' needs: [test, filter, test-plan]\n', ' needs: [test, filter]\n'), "plan job 'test-plan'", '#26084'),
2817+
await planProblem('the gate loses the plan job from needs', (s) => s.replace(' needs: [test, filter, test-plan, queue-verdict]\n', ' needs: [test, filter, queue-verdict]\n'), "plan job 'test-plan'", '#26084'),
27372818
'#26084: a gate that cannot read the plan job ⇒ red',
27382819
);
27392820
assert(
2740-
await planProblem('the test job loses the plan job from needs', (s) => s.replace(' needs: [filter, test-plan]\n', ' needs: filter\n'), "does not list 'test-plan'", '#26084'),
2821+
await planProblem('the test job loses the plan job from needs', (s) => s.replace(' needs: [filter, test-plan, queue-verdict]\n', ' needs: [filter, queue-verdict]\n'), "does not list 'test-plan'", '#26084'),
27412822
'#26084: a matrix built from a job it does not need ⇒ red',
27422823
);
27432824
assert(

0 commit comments

Comments
 (0)