An open source design system that's fully customizable and agent ready
TypeScript
ci(heavy-caps): engineering owners are exempt; other authors get 15 oldest PRs and 100 heavy runs a day (#9077)
Cindy Zhang5171ac16b999
diff --git a/.github/actions/heavy-caps/action.yml b/.github/actions/heavy-caps/action.ymlindex 8a82e37978..6a789ab704 100644--- a/.github/actions/heavy-caps/action.yml+++ b/.github/actions/heavy-caps/action.yml@@ -5,11 +5,12 @@# "Heavy suite runs" step right after it; a held job fails here with the# reason, so it never passes a required join untested.#-# - One author's suites run for their three oldest open non-draft pull-# requests, and for at most twelve heavy runs a UTC day.+# - One author's suites run for their fifteen oldest open non-draft pull+# requests, and for at most a hundred heavy runs a UTC day.# - The shared agent login counts each branch prefix as an author, with that# login also held to its five oldest pull requests and forty runs a day.-# - A re-run (the pre-merge restart) and a bot are exempt; a lookup that fails+# - An engineering owner (.github/ENGOWNERS, read from the base commit), a+# re-run (the pre-merge restart) and a bot are exempt; a lookup that fails# runs the suite.## Each limit is one entry in `limits`, checked in order.@@ -43,14 +44,21 @@ runs:)).search.nodes);+ // An author's oldest open non-draft pull requests that run heavy suites.+ const OLDEST = 15;+ // An author's heavy runs a UTC day.+ const DAILY = 100;const limits = [// Pull request numbers rise with creation, and the search returns// the oldest, so it holds every older one that could queue this.async function oldestPullRequests() {const nodes = await openPullRequests();const older = list => list.filter(p => p.number < pr.number).length;- if (older(nodes.filter(p => mine(p.headRefName))) >= 3 || (shared && older(nodes) >= 5)) {- return 'Queued behind your 3 oldest PRs: runs on a push once it is among them, or at the pre-merge re-run.';+ if (older(nodes.filter(p => mine(p.headRefName))) >= OLDEST) {+ return `Queued behind your ${OLDEST} oldest PRs: runs on a push once it is among them, or at the pre-merge re-run.`;+ }+ if (shared && older(nodes) >= 5) {+ return "Queued behind the shared login's 5 oldest PRs: runs on a push once it is among them, or at the pre-merge re-run.";}},// A heavy run is a run on one of those pull requests whose heavy job@@ -61,7 +69,7 @@ runs:const key = (repo, branch) => `${repo}:${branch}`;const oldest = new Map([[key(pr.head.repo.full_name, pr.head.ref), pr.head.ref],- ...[...nodes.filter(p => mine(p.headRefName)).slice(0, 3), ...(shared ? nodes.slice(0, 5) : [])].map(p => [+ ...[...nodes.filter(p => mine(p.headRefName)).slice(0, OLDEST), ...(shared ? nodes.slice(0, 5) : [])].map(p => [key(p.headRepository?.nameWithOwner, p.headRefName),p.headRefName,]),@@ -84,13 +92,25 @@ runs:if (mine(run.head_branch)) laneHeavy += 1;}}- if (laneHeavy >= 12 || (shared && loginHeavy >= 40)) {+ if (laneHeavy >= DAILY || (shared && loginHeavy >= 40)) {return 'Daily heavy-run cap reached, runs tomorrow or at pre-merge.';}},];try {+ // Engineering owners are exempt. The roster is read from the base+ // commit, so a pull request cannot add its own author, and parsed+ // like the spec-owner gate's: `#` comments out the rest of a line.+ const {data: roster} = await github.rest.repos.getContent({+ ...context.repo, path: '.github/ENGOWNERS', ref: pr.base.sha,+ });+ const owners = Buffer.from(roster.content, 'base64').toString('utf8')+ .split('\n').map(line => line.replace(/#.*/, ''))+ .flatMap(line => line.match(/@[\w-]+/g) ?? [])+ .map(handle => handle.slice(1).toLowerCase());+ if (owners.includes(login.toLowerCase())) return;+for (const limit of limits) {const held = await limit();if (held) {diff --git a/.github/scripts/heavy-caps-action.test.mjs b/.github/scripts/heavy-caps-action.test.mjsindex 9b53cb47de..e81d2ace97 100644--- a/.github/scripts/heavy-caps-action.test.mjs+++ b/.github/scripts/heavy-caps-action.test.mjs@@ -28,8 +28,12 @@ const isCaps = step =>step.uses?.startsWith('./') &&step.uses.endsWith('/.github/actions/heavy-caps');const QUEUED =- 'Queued behind your 3 oldest PRs: runs on a push once it is among them, or at the pre-merge re-run.';+ 'Queued behind your 15 oldest PRs: runs on a push once it is among them, or at the pre-merge re-run.';+const BACKSTOP =+ "Queued behind the shared login's 5 oldest PRs: runs on a push once it is among them, or at the pre-merge re-run.";const CAPPED = 'Daily heavy-run cap reached, runs tomorrow or at pre-merge.';+const ENGOWNERS =+ '# Engineering owners\n# @commented-out\n\n@owner-one @Owner-Two # was @trailing-comment\n';function pullRequestContext(pr = {}) {return {@@ -38,8 +42,9 @@ function pullRequestContext(pr = {}) {runId: 1,payload: {pull_request: {- number: 7,+ number: 20,head: {ref: 'fix/a', repo: {full_name: 'author/r'}},+ base: {sha: 'base-sha'},user: {login: 'author'},...pr,},@@ -53,6 +58,7 @@ async function check({open = [],runs = [],attempt = '1',+ engowners = ENGOWNERS,} = {}) {const messages = {failed: [], warning: []};const core = {@@ -66,6 +72,15 @@ async function check({return {search: {nodes: open}};},rest: {+ repos: {+ // The roster is read from the base commit only.+ getContent: async ({path: file, ref}) => {+ if (file !== '.github/ENGOWNERS' || ref !== 'base-sha')+ throw new Error(`unexpected read ${file}@${ref}`);+ if (engowners instanceof Error) throw engowners;+ return {data: {content: Buffer.from(engowners).toString('base64')}};+ },+ },actions: {// Today's ci.yml runs on a branch name, from any repository.listWorkflowRuns: async ({branch}) => ({@@ -114,7 +129,10 @@ const pulls = (...refs) =>headRefName,headRepository: headRefName.startsWith('fix/') ? fork : here,}));-const me = {number: 7, headRefName: 'fix/a', headRepository: fork};+const me = {number: 20, headRefName: 'fix/a', headRepository: fork};+// The author's fifteen older pull requests.+const older15 = () =>+ pulls(...Array.from({length: 15}, (_, i) => `fix/older-${i}`));let nextRun = 100;const runsOn = (count, head_branch = 'fix/a', run = {}) =>Array.from({length: count}, () => ({@@ -127,8 +145,8 @@ const runsOn = (count, head_branch = 'fix/a', run = {}) =>}));describe('per-author caps on heavy suites (spec:AST-030 FR16)', () => {- it("fails a heavy job behind the author's 3 oldest PRs", async () => {- const open = [...pulls('fix/b', 'fix/c', 'fix/d'), me];+ it("fails a heavy job behind the author's 15 oldest PRs", async () => {+ const open = [...older15(), me];expect((await check({open})).failed).toEqual([QUEUED]);expect((await check({open: open.slice(1)})).failed).toEqual([]);// The search holds at most the author's 100 oldest; a newer pull request@@ -140,23 +158,23 @@ describe('per-author caps on heavy suites (spec:AST-030 FR16)', () => {).toEqual([QUEUED]);});- it("fails a heavy job past the author's 12 heavy runs today", async () => {- expect((await check({open: [me], runs: runsOn(12)})).failed).toEqual([+ it("fails a heavy job past the author's 100 heavy runs today", async () => {+ expect((await check({open: [me], runs: runsOn(100)})).failed).toEqual([CAPPED,]);// The cap counts the author's heavy runs across all of their oldest pull// requests, not only the one deciding.const spread = await check({open: [...pulls('fix/b', 'fix/c'), me],- runs: [...runsOn(6, 'fix/b'), ...runsOn(3, 'fix/c'), ...runsOn(3)],+ runs: [...runsOn(50, 'fix/b'), ...runsOn(25, 'fix/c'), ...runsOn(25)],});expect(spread.failed).toEqual([CAPPED]);// When the deciding pull request is the author's oldest, the count still- // reaches their third-oldest.+ // reaches their fifteenth-oldest.const first = await check({context: pullRequestContext({number: 1}),- open: [{...me, number: 1}, ...pulls('fix/x', 'fix/b', 'fix/c').slice(1)],- runs: [...runsOn(4), ...runsOn(4, 'fix/b'), ...runsOn(4, 'fix/c')],+ open: [{...me, number: 1}, ...older15().slice(1)],+ runs: [...runsOn(50), ...runsOn(50, 'fix/older-14')],});expect(first.failed).toEqual([CAPPED]);// Cancelled runs, runs whose heavy suites never ran (a queued PR) and runs@@ -164,7 +182,7 @@ describe('per-author caps on heavy suites (spec:AST-030 FR16)', () => {const light = await check({open: [me],runs: [- ...runsOn(11),+ ...runsOn(99),...runsOn(5, 'fix/a', {conclusion: 'cancelled'}),...runsOn(5, 'fix/a', {heavy: false}),...runsOn(5, 'fix/old-merged'),@@ -176,7 +194,7 @@ describe('per-author caps on heavy suites (spec:AST-030 FR16)', () => {const elsewhere = await check({open: [me],runs: [- ...runsOn(11),+ ...runsOn(99),...runsOn(5, 'fix/a', {head_repository: {full_name: 'other/r'}}),],});@@ -188,7 +206,7 @@ describe('per-author caps on heavy suites (spec:AST-030 FR16)', () => {user: {login: 'cixzhang'},head: {ref: 'lane4/x', repo: {full_name: 'o/r'}},});- const mine = {number: 7, headRefName: 'lane4/x', headRepository: here};+ const mine = {number: 20, headRefName: 'lane4/x', headRepository: here};const others = await check({context,open: [...pulls('lane1/a', 'lane2/b', 'lane3/c', 'lane0/d'), mine],@@ -202,7 +220,8 @@ describe('per-author caps on heavy suites (spec:AST-030 FR16)', () => {mine,],});- expect(backstop.failed).toEqual([QUEUED]);+ // The backstop names itself, so a lane with room knows why it waits.+ expect(backstop.failed).toEqual([BACKSTOP]);// The login's forty-run count reaches its fifth-oldest pull request.const fifth = await check({context: pullRequestContext({@@ -241,17 +260,66 @@ describe('per-author caps on heavy suites (spec:AST-030 FR16)', () => {).toEqual([]);});+ it('exempts engineering owners, read from the base commit', async () => {+ const crowded = {+ open: [...older15(), me],+ runs: runsOn(20),+ };+ for (const login of ['owner-one', 'owner-two', 'OWNER-ONE']) {+ expect(+ (+ await check({+ context: pullRequestContext({user: {login}}),+ ...crowded,+ })+ ).failed,+ ).toEqual([]);+ }+ // A commented-out handle, or anyone else, is not an owner.+ for (const login of ['commented-out', 'trailing-comment', 'author']) {+ expect(+ (+ await check({+ context: pullRequestContext({user: {login}}),+ ...crowded,+ })+ ).failed,+ ).toEqual([QUEUED]);+ }+ // The shared agent login is exempt when it is listed.+ const lane = await check({+ context: pullRequestContext({+ user: {login: 'cixzhang'},+ head: {ref: 'lane4/x', repo: {full_name: 'o/r'}},+ }),+ engowners: '@cixzhang\n',+ open: [+ ...pulls('lane4/a', 'lane4/b', 'lane4/c', 'lane1/d', 'ci/e'),+ {number: 7, headRefName: 'lane4/x', headRepository: here},+ ],+ runs: runsOn(45, 'lane4/a'),+ });+ expect(lane.failed).toEqual([]);+ // When the roster cannot be read, the suite runs.+ const unread = await check({+ ...crowded,+ engowners: new Error('not found'),+ });+ expect(unread.failed).toEqual([]);+ expect(unread.warning[0]).toContain('running the heavy suite');+ });+it('exempts bots and does not count the run deciding', async () => {const bot = await check({context: pullRequestContext({user: {login: 'dependabot[bot]'}}),- open: [...pulls('fix/b', 'fix/c', 'fix/d'), me],+ open: [...older15(), me],});expect(bot.failed).toEqual([]);const self = await check({context: {...pullRequestContext(), runId: 900},open: [me],runs: [- ...runsOn(11),+ ...runsOn(99),{id: 900,head_branch: 'fix/a',@@ -340,8 +408,10 @@ describe('per-author caps on heavy suites (spec:AST-030 FR16)', () => {for (const [id, job] of heavyJobs) {const caps = job.steps.findIndex(isCaps);expect(job.steps[caps - 1].uses, id).toMatch(/^actions\/checkout@/);+ // The engineering-owner roster is read with contents: read.expect(job.permissions, id).toMatchObject({actions: 'read',+ contents: 'read','pull-requests': 'read',});expect(job.steps[caps + 1], id).toMatchObject({diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex c699ee6e56..8cd402248a 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -932,9 +932,10 @@ Storybook story for anything you added or altered.since pushing a branch here needs write access. Maintainers who work from afork either push their branches here or apply `ci:run` themselves.- **Heavy browser suites are shared per author.** They run for an author's- three oldest open pull requests, up to twelve such runs a day. A pull request- past either limit shows a failing check that says why, and runs in full at- its pre-merge re-run.+ fifteen oldest open pull requests, up to a hundred such runs a day. A pull+ request past either limit shows a failing check that says why, and runs in+ full at its pre-merge re-run. Engineering owners listed in `.github/ENGOWNERS`+ are not limited.## Code Stylediff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.mdindex 48c0ea0867..cbc1951dff 100644--- a/docs/specs/AST-030/spec.md+++ b/docs/specs/AST-030/spec.md@@ -284,15 +284,19 @@ they are separately named.- **FR16 — One author's pull requests share the heavy suites.** On a pullrequest, the heavy browser suites (the interaction proofs and the Buildpackage's browser and fixture-contrast contracts) run only when the pull- request is among its author's three oldest open non-draft pull requests and- the author has had at most twelve heavy runs that UTC day. A heavy run is a+ request is among its author's fifteen oldest open non-draft pull requests and+ the author has had at most one hundred heavy runs that UTC day. A heavy run is aCI run on one of those pull requests in which a heavy suite ran; a cancelledrun does not count, and neither does a run whose heavy suites were held.Pull requests from the shared agent login count per branch prefix, and thatlogin as a whole is also held to its five oldest pull requests and forty- heavy runs a day; bot accounts are exempt. A held suite's check fails with- "Queued behind your 3 oldest PRs: runs on a push once it is among them, or at- the pre-merge re-run." or "Daily heavy-run cap reached, runs tomorrow or at+ heavy runs a day. Engineering owners listed in `.github/ENGOWNERS`, as the+ pull request's base commit lists them, are exempt from all of these limits,+ the shared login's included, and so are bot accounts. A held+ suite's check fails with "Queued behind your 15 oldest PRs: runs on a push+ once it is among them, or at the pre-merge re-run.", "Queued behind the+ shared login's 5 oldest PRs: runs on a push once it is among them, or at the+ pre-merge re-run." or "Daily heavy-run cap reached, runs tomorrow or atpre-merge.", so no pull request passes the required checks without its heavysuites. A re-run, which is the pre-merge restart, is exempt from both limits,and when the limits cannot be looked up the suite runs. Merge-queue entries,@@ -346,21 +350,21 @@ read change (FR14).## Verification-| Contract | Verification | Representative states | Mutation or failure expectation |-| -------- | ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| FR1–FR2 | classifier unit tests expose the surface set | knowledge; docsite; admitted tool; Core/Lab/Charts/Rich Text/Vega source; shared config; unknown | an unclassified path receives a specialized lane or a category has no check owner |-| FR3–FR4 | workflow contract tests execute an isolated trusted-base classifier | valid base; missing merge base; missing matcher/registry; classifier self-change; merge group | PR-controlled policy grants a lane, or missing trust data skips checks |-| FR5 | mixed-surface and incomplete-owner routing tests | spec+component; tooling+component; named surface without admitted lane; docsite+shared | one surface hides another owner or a named-but-incomplete surface skips broad CI |-| FR6–FR8 | Node-tooling dependency, CI workflow, and trusted post-CI workflow tests | both admitted score-ledger paths; Sandbox projection imports; test/build joins; preview/visual publisher | UI/browser/build work or preview publication runs for the singleton tool set, an operational consumer is untested, a visual status stays pending, or a required context disappears |-| FR9 | mutation-sensitive classifier and workflow fixtures | unknown path; rename from unknown; truncated list; package-specific public paths | weakening a fail-closed rule leaves the suite green |-| FR10 | surface-admission and routing contract tests | existing surface; proposed surface with and without the full admission contract | a new surface adds lanes without its approved paths, commands, ownership, projections, and routing tests |-| FR11 | surface owner, internal-job, and required-join contract tests | Build package browser behavior; CLI; theme-family broad fallback; mixed Core+CLI | a second owner is routed for one surface, an internal job masquerades as a lane, an owned failure misses its join, or an unrelated owner runs |-| FR12 | Storybook visual-plan, canonical workflow, and repository-owner guard tests | PR scope; full-plan maintenance; report-only publication; deployment/a11y/RTL/vibe artifacts | another workflow captures or compares pixels, a renamed or aliased owner escapes the guard, or legitimate non-visual artifacts are rejected |-| FR13 | classifier, workflow contract, component-analysis and RTL-scope tests | component change; shared module; Changeset beside code; infrastructure path; incomplete list; no build | an infrastructure path is scoped, a file-system guard test is skipped, a reverse dependent leaves visual/RTL or enters PR accessibility, or a full-suite event is narrowed |-| FR14 | `workflow-paths.test.mjs` over every workflow | path allowlist; required-context workflow | a `paths-ignore`, a match-all or exclusion glob, or a path filter on a workflow that reports a required context fails |-| FR15 | workflow contract and reconciler tests | ENGOWNER spec PR; owner command; other comment; fork review; non-spec PR | `review-required` succeeds while spec approval is missing, another workflow publishes a review context, a fork review starts the spec checks, or a non-command comment starts a runner |-| FR16 | `heavy-caps-action.test.mjs` cap cases and heavy-job contract | fourth-oldest PR; thirteenth heavy run of the day, beside cancelled, light and other-branch runs; agent lane and its five-PR and forty-run backstops; bot; the deciding run; re-run; failed lookup | a heavy suite that runs ahead of the author's three oldest PRs, or past the daily cap, a capped job that passes, or a re-run that is held fails |-| FR17 | `ci-pr-gate.test.mjs` over every `pull_request` workflow and the shared conditions | branch here, fork with and without `ci:run`, another label, draft with the label, ready, push, merge group, dispatch | a job that can start on a pull request without the condition, a label trigger, a required job that skips for a pull request that may not run CI, or a draft or unlabelled fork that runs fails |+| Contract | Verification | Representative states | Mutation or failure expectation |+| -------- | ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| FR1–FR2 | classifier unit tests expose the surface set | knowledge; docsite; admitted tool; Core/Lab/Charts/Rich Text/Vega source; shared config; unknown | an unclassified path receives a specialized lane or a category has no check owner |+| FR3–FR4 | workflow contract tests execute an isolated trusted-base classifier | valid base; missing merge base; missing matcher/registry; classifier self-change; merge group | PR-controlled policy grants a lane, or missing trust data skips checks |+| FR5 | mixed-surface and incomplete-owner routing tests | spec+component; tooling+component; named surface without admitted lane; docsite+shared | one surface hides another owner or a named-but-incomplete surface skips broad CI |+| FR6–FR8 | Node-tooling dependency, CI workflow, and trusted post-CI workflow tests | both admitted score-ledger paths; Sandbox projection imports; test/build joins; preview/visual publisher | UI/browser/build work or preview publication runs for the singleton tool set, an operational consumer is untested, a visual status stays pending, or a required context disappears |+| FR9 | mutation-sensitive classifier and workflow fixtures | unknown path; rename from unknown; truncated list; package-specific public paths | weakening a fail-closed rule leaves the suite green |+| FR10 | surface-admission and routing contract tests | existing surface; proposed surface with and without the full admission contract | a new surface adds lanes without its approved paths, commands, ownership, projections, and routing tests |+| FR11 | surface owner, internal-job, and required-join contract tests | Build package browser behavior; CLI; theme-family broad fallback; mixed Core+CLI | a second owner is routed for one surface, an internal job masquerades as a lane, an owned failure misses its join, or an unrelated owner runs |+| FR12 | Storybook visual-plan, canonical workflow, and repository-owner guard tests | PR scope; full-plan maintenance; report-only publication; deployment/a11y/RTL/vibe artifacts | another workflow captures or compares pixels, a renamed or aliased owner escapes the guard, or legitimate non-visual artifacts are rejected |+| FR13 | classifier, workflow contract, component-analysis and RTL-scope tests | component change; shared module; Changeset beside code; infrastructure path; incomplete list; no build | an infrastructure path is scoped, a file-system guard test is skipped, a reverse dependent leaves visual/RTL or enters PR accessibility, or a full-suite event is narrowed |+| FR14 | `workflow-paths.test.mjs` over every workflow | path allowlist; required-context workflow | a `paths-ignore`, a match-all or exclusion glob, or a path filter on a workflow that reports a required context fails |+| FR15 | workflow contract and reconciler tests | ENGOWNER spec PR; owner command; other comment; fork review; non-spec PR | `review-required` succeeds while spec approval is missing, another workflow publishes a review context, a fork review starts the spec checks, or a non-command comment starts a runner |+| FR16 | `heavy-caps-action.test.mjs` cap cases and heavy-job contract | sixteenth-oldest PR; 101st heavy run of the day, beside cancelled, light and other-branch runs; agent lane and its five-PR and forty-run backstops; an engineering owner, including the shared login past those backstops, a commented-out or trailing-comment handle and an unreadable roster; bot; the deciding run; re-run; failed lookup | a heavy suite that runs ahead of the author's fifteen oldest PRs, or past the daily cap, a capped job that passes, an engineering owner or a re-run that is held, or a roster read from the pull request's head fails |+| FR17 | `ci-pr-gate.test.mjs` over every `pull_request` workflow and the shared conditions | branch here, fork with and without `ci:run`, another label, draft with the label, ready, push, merge group, dispatch | a job that can start on a pull request without the condition, a label trigger, a required job that skips for a pull request that may not run CI, or a draft or unlabelled fork that runs fails |## Decision log