Skip to content

Commit 88aaa75

Browse files
authored
Merge pull request #7805 from lidge-jun/codex/promote-main-2.93.0
[WRONG BRANCH] release: promote frozen tip 2606f6f to main as 2.93.0
2 parents 9f0d40a + 6a87fea commit 88aaa75

694 files changed

Lines changed: 34441 additions & 2733 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/actions/setup-project-bun/action.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ description: >-
88
# (#6713 run 37631558263: Linux 1/4, macOS 2/2, Windows 9/9). It moved from 1.4.0 to
99
# 1.4.3 for oven-sh/bun#44581: 1.4.0's Bun.spawnSync could lose a child's exit after
1010
# finalizers ran inside an earlier call and spin past its own timeout (#4956).
11-
# Rejoin only after the upstream runner crash is fixed and a green lane=all
12-
# dispatch proves the unified version; then delete testRunnerBun and this role input.
11+
# Both roles now default to the package's 1.4.4 security transition, retaining role validation.
12+
# Promotion requires a green full cross-platform lane=all run on the exact candidate head.
1313
inputs:
1414
role:
1515
description: Bun role to install (runtime or test-runner).

‎.github/scripts/enforce-pr-target.test.cjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ describe("enforce-pr-target workflow", () => {
9494

9595
it("writes exactly one consolidated comment via a single upsert helper", () => {
9696
assert.match(workflow, /GATE_MARKER,/);
97-
assert.match(workflow, /comment\.body\?\.includes\(GATE_MARKER\)/);
97+
// The gate comment is the bot comment that starts with GATE_MARKER; a
98+
// marker echoed inside another comment does not classify it.
99+
assert.match(workflow, /comments\.find\(isGateComment\)/);
98100
assert.match(workflow, /upsertGateComment/);
99101
assert.match(workflow, /buildGateCommentBody/);
100102
// No legacy two-comment write path remains.

‎.github/scripts/pr-hygiene.cjs‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,109 @@ const HYGIENE_GATE_LABELS = [
292292
"attribution-approved",
293293
];
294294

295+
/**
296+
* Exception approvals vouch for one revision of the change. Each counts only
297+
* while the head the hygiene workflow last recorded is still the head being
298+
* evaluated and nothing has rewritten the branch since. Sponsorship
299+
* (`maintainer-sponsored`) is about which surfaces change, not about one
300+
* revision, so it is not head-bound.
301+
*/
302+
const HEAD_BOUND_APPROVAL_LABELS = [
303+
"test-exception-approved",
304+
"suppression-approved",
305+
"generated-change-approved",
306+
"dependency-change-approved",
307+
"attribution-approved",
308+
];
309+
310+
/** Issue events after which the head can point at an earlier commit again. */
311+
const HEAD_REWRITE_EVENTS = ["head_ref_force_pushed", "head_ref_restored"];
312+
313+
const APPROVAL_RECORD_TOKEN = "pr-hygiene-approvals";
314+
const APPROVAL_RECORD_LINE = /^<!-- pr-hygiene-approvals (\{.*\}) -->$/;
315+
const FULL_SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
316+
317+
function isRewriteCount(value) {
318+
return Number.isSafeInteger(value) && value >= 0;
319+
}
320+
321+
/**
322+
* Read the head binding the hygiene workflow wrote as the last line of its
323+
* own section. The token must occur exactly once in `source` and sit on that
324+
* last line, so echoed text (a changed path can contain newlines) can only
325+
* make the record unreadable, never stand in for it.
326+
* @returns {{ head: string, headRewrites: number | null } | null}
327+
*/
328+
function parseApprovalRecord(source) {
329+
if (typeof source !== "string") return null;
330+
if (source.split(APPROVAL_RECORD_TOKEN).length !== 2) return null;
331+
const lines = source.split("\n").map((line) => line.trim()).filter(Boolean);
332+
const match = lines.at(-1)?.match(APPROVAL_RECORD_LINE);
333+
if (!match) return null;
334+
let value;
335+
try {
336+
value = JSON.parse(match[1]);
337+
} catch {
338+
return null;
339+
}
340+
if (value === null || typeof value !== "object" || Array.isArray(value)) return null;
341+
if (Object.keys(value).sort().join(",") !== "head,headRewrites") return null;
342+
if (typeof value.head !== "string" || !FULL_SHA.test(value.head)) return null;
343+
if (value.headRewrites !== null && !isRewriteCount(value.headRewrites)) return null;
344+
return { head: value.head, headRewrites: value.headRewrites };
345+
}
346+
347+
/** `headRewrites` is null when the history read failed: nothing is confirmed. */
348+
function formatApprovalRecord({ head, headRewrites }) {
349+
const value = { head, headRewrites: isRewriteCount(headRewrites) ? headRewrites : null };
350+
return "<!-- " + APPROVAL_RECORD_TOKEN + " " + JSON.stringify(value) + " -->";
351+
}
352+
353+
function countHeadRewrites(events) {
354+
return (events ?? []).filter((entry) => HEAD_REWRITE_EVENTS.includes(entry?.event)).length;
355+
}
356+
357+
function presentHeadBoundApprovals(labels) {
358+
return HEAD_BOUND_APPROVAL_LABELS.filter((label) => labels.includes(label));
359+
}
360+
361+
/** True when a current rewrite count could still confirm an approval. */
362+
function needsHeadRewriteCount({ labels = [], headSha, record = null, eventAction }) {
363+
return (
364+
eventAction !== "synchronize" &&
365+
record !== null &&
366+
record.head === headSha &&
367+
isRewriteCount(record.headRewrites) &&
368+
presentHeadBoundApprovals(labels).length > 0
369+
);
370+
}
371+
372+
/**
373+
* Split the head-bound approvals on the pull request into the ones that still
374+
* describe the evaluated head and the ones that do not. They are kept only
375+
* when the last recorded evaluation saw this same head and the rewrite count,
376+
* read before that evaluation's snapshot and again after this one's, has not
377+
* changed. Without a rewrite, fast-forward pushes cannot bring the recorded
378+
* head back, so the head has not moved since that evaluation, which removed
379+
* every approval it could not confirm. A synchronize event, a missing record,
380+
* or an unknown count confirms nothing.
381+
* @returns {{ kept: string[], stale: string[] }}
382+
*/
383+
function reconcileHeadBoundApprovals({
384+
labels = [],
385+
headSha,
386+
record = null,
387+
eventAction,
388+
headRewriteCount = null,
389+
}) {
390+
const present = presentHeadBoundApprovals(labels);
391+
const current =
392+
needsHeadRewriteCount({ labels, headSha, record, eventAction }) &&
393+
isRewriteCount(headRewriteCount) &&
394+
headRewriteCount === record.headRewrites;
395+
return current ? { kept: present, stale: [] } : { kept: [], stale: present };
396+
}
397+
295398
/**
296399
* Combine patch-hygiene and sponsored-surface failures into one list so the
297400
* hygiene workflow and the PR quality gate cannot disagree about Ready.
@@ -340,13 +443,20 @@ module.exports = {
340443
addedLines,
341444
assessHygiene,
342445
collectDeterministicHygieneFailures,
446+
countHeadRewrites,
447+
formatApprovalRecord,
448+
HEAD_BOUND_APPROVAL_LABELS,
449+
HEAD_REWRITE_EVENTS,
343450
HYGIENE_FAILURE_HINTS,
344451
HYGIENE_GATE_LABELS,
345452
hasEmptyCatch,
346453
hasDeletions,
347454
isBehaviorPath,
348455
isGeneratedPath,
349456
isTestPath,
457+
needsHeadRewriteCount,
458+
parseApprovalRecord,
459+
reconcileHeadBoundApprovals,
350460
resultLines,
351461
resultLinesByHunk,
352462
};

‎.github/scripts/pr-hygiene.test.cjs‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ const {
66
addedLines,
77
assessHygiene,
88
collectDeterministicHygieneFailures,
9+
countHeadRewrites,
10+
formatApprovalRecord,
11+
HEAD_BOUND_APPROVAL_LABELS,
912
HYGIENE_FAILURE_HINTS,
1013
HYGIENE_GATE_LABELS,
1114
hasEmptyCatch,
15+
needsHeadRewriteCount,
16+
parseApprovalRecord,
17+
reconcileHeadBoundApprovals,
1218
resultLines,
1319
resultLinesByHunk,
1420
} = require("./pr-hygiene.cjs");
@@ -391,3 +397,100 @@ describe("pr-hygiene workflow trust boundary", () => {
391397
);
392398
});
393399
});
400+
401+
describe("head-bound approvals", () => {
402+
const HEAD = "c".repeat(40);
403+
const OTHER = "d".repeat(40);
404+
const record = (head, headRewrites) =>
405+
"<!-- pr-hygiene-approvals " + JSON.stringify({ head, headRewrites }) + " -->";
406+
407+
it("covers exactly the exception approvals, not sponsorship", () => {
408+
assert.deepEqual(
409+
[...HEAD_BOUND_APPROVAL_LABELS].sort(),
410+
HYGIENE_GATE_LABELS.filter(
411+
(label) => label !== "intake: hygiene-blocked" && label !== "maintainer-sponsored",
412+
).sort(),
413+
);
414+
});
415+
416+
it("round-trips a record, including an unknown rewrite count", () => {
417+
const line = formatApprovalRecord({ head: HEAD, headRewrites: 2 });
418+
assert.equal(line, record(HEAD, 2));
419+
assert.deepEqual(parseApprovalRecord("status\n\n" + line), { head: HEAD, headRewrites: 2 });
420+
assert.deepEqual(parseApprovalRecord(formatApprovalRecord({ head: HEAD, headRewrites: undefined })), {
421+
head: HEAD,
422+
headRewrites: null,
423+
});
424+
assert.deepEqual(parseApprovalRecord(record("e".repeat(64), 0)), { head: "e".repeat(64), headRewrites: 0 });
425+
});
426+
427+
it("rejects anything but one well-formed record on the last line", () => {
428+
for (const source of [
429+
null,
430+
"",
431+
record(HEAD, 0) + "\nlater line",
432+
record(HEAD, 0) + "\n" + record(HEAD, 0),
433+
"mentions pr-hygiene-approvals elsewhere\n" + record(HEAD, 0),
434+
"<!-- pr-hygiene-approvals {not json} -->",
435+
"<!-- pr-hygiene-approvals " + JSON.stringify({ head: HEAD, headRewrites: 0, approvals: [] }) + " -->",
436+
"<!-- pr-hygiene-approvals " + JSON.stringify({ head: HEAD }) + " -->",
437+
"<!-- pr-hygiene-approvals [1] -->",
438+
record("abc", 0),
439+
record(HEAD.toUpperCase(), 0),
440+
record(HEAD, -1),
441+
record(HEAD, 1.5),
442+
record(HEAD, "1"),
443+
]) {
444+
assert.equal(parseApprovalRecord(source), null, String(source));
445+
}
446+
});
447+
448+
it("counts only head rewrite events", () => {
449+
assert.equal(
450+
countHeadRewrites([
451+
{ event: "head_ref_force_pushed" },
452+
{ event: "labeled" },
453+
{ event: "head_ref_restored" },
454+
null,
455+
]),
456+
2,
457+
);
458+
assert.equal(countHeadRewrites(undefined), 0);
459+
});
460+
461+
it("keeps approvals only under an unchanged head and rewrite count", () => {
462+
const labels = ["test-exception-approved", "maintainer-sponsored"];
463+
const base = { labels, headSha: HEAD, record: { head: HEAD, headRewrites: 1 }, eventAction: "edited" };
464+
const kept = { kept: ["test-exception-approved"], stale: [] };
465+
const stale = { kept: [], stale: ["test-exception-approved"] };
466+
assert.deepEqual(reconcileHeadBoundApprovals({ ...base, headRewriteCount: 1 }), kept);
467+
assert.deepEqual(reconcileHeadBoundApprovals({ ...base, headRewriteCount: 2 }), stale);
468+
assert.deepEqual(reconcileHeadBoundApprovals({ ...base, headRewriteCount: null }), stale);
469+
assert.deepEqual(reconcileHeadBoundApprovals({ ...base, headRewriteCount: 1, eventAction: "synchronize" }), stale);
470+
assert.deepEqual(reconcileHeadBoundApprovals({ ...base, headRewriteCount: 1, headSha: OTHER }), stale);
471+
assert.deepEqual(reconcileHeadBoundApprovals({ ...base, headRewriteCount: 1, record: null }), stale);
472+
assert.deepEqual(
473+
reconcileHeadBoundApprovals({ ...base, headRewriteCount: 1, record: { head: HEAD, headRewrites: null } }),
474+
stale,
475+
);
476+
assert.deepEqual(
477+
reconcileHeadBoundApprovals({ ...base, labels: ["maintainer-sponsored"], headRewriteCount: 1 }),
478+
{ kept: [], stale: [] },
479+
);
480+
});
481+
482+
it("asks for a rewrite count only when one could confirm an approval", () => {
483+
const base = {
484+
labels: ["suppression-approved"],
485+
headSha: HEAD,
486+
record: { head: HEAD, headRewrites: 0 },
487+
eventAction: "labeled",
488+
};
489+
assert.equal(needsHeadRewriteCount(base), true);
490+
assert.equal(needsHeadRewriteCount({ ...base, labels: [] }), false);
491+
assert.equal(needsHeadRewriteCount({ ...base, eventAction: "synchronize" }), false);
492+
assert.equal(needsHeadRewriteCount({ ...base, headSha: OTHER }), false);
493+
assert.equal(needsHeadRewriteCount({ ...base, record: null }), false);
494+
assert.equal(needsHeadRewriteCount({ ...base, record: { head: HEAD, headRewrites: null } }), false);
495+
});
496+
});

0 commit comments

Comments
 (0)