An open source design system that's fully customizable and agent ready
TypeScript
ci: a dispatch that runs a pull request's owed audits at its exact head (#10694)
Cindy Zhang1b3097554d30
diff --git a/.github/actions/ci-admission/count.mjs b/.github/actions/ci-admission/count.mjsindex ad10d1395b..5b034cfb52 100644--- a/.github/actions/ci-admission/count.mjs+++ b/.github/actions/ci-admission/count.mjs@@ -47,13 +47,18 @@ const ESTIMATE = {'.github/workflows/ci.yml': run => (run.event === 'workflow_dispatch' ? 39 : 17),'.github/workflows/deploy.yml': run => (run.event === 'push' ? 4 : 14),'.github/workflows/review-signal.yml': () => 2,+ '.github/workflows/audits-at-head.yml': () => 10,};export const estimate = run => (ESTIMATE[run.path] ?? (() => 1))(run);// Jobs always counted for small, unadmitted workflows: they peaked at twenty// at once in a day's runs and rose by fourteen within two minutes in// ninety-nine looks of a hundred (spec:AST-030 DEC-16).export const SMALL_MOST = 18;-const ADMITTED = ['.github/workflows/ci.yml', '.github/workflows/deploy.yml'];+const ADMITTED = [+ '.github/workflows/ci.yml',+ '.github/workflows/deploy.yml',+ '.github/workflows/audits-at-head.yml',+];const admitted = run => ADMITTED.includes(run.path);const LIVE = ['in_progress', 'queued', 'waiting', 'pending'];// A run's jobs appear within seconds of its admission; until then it counts atdiff --git a/.github/scripts/audits-at-head.test.mjs b/.github/scripts/audits-at-head.test.mjsnew file mode 100644index 0000000000..2c12f0f2fe--- /dev/null+++ b/.github/scripts/audits-at-head.test.mjs@@ -0,0 +1,187 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Contract: the audits-at-head dispatch runs every audit a pull request+ * owes at its exact head, and its contract specs on request, as untrusted+ * code under the CI ceiling, and writes the record merge-guard reads.+ */++import fs from 'node:fs';+import path from 'node:path';++import {describe, expect, it} from 'vitest';+import yaml from 'yaml';++const root = path.resolve(import.meta.dirname, '../..');+const text = fs.readFileSync(+ path.join(root, '.github/workflows/audits-at-head.yml'),+ 'utf8',+);+const workflow = yaml.parse(text);+const counter = fs.readFileSync(+ path.join(root, '.github/actions/ci-admission/count.mjs'),+ 'utf8',+);+const job = name => workflow.jobs[name];+const step = (jobName, name) => {+ const found = job(jobName).steps.find(candidate => candidate.name === name);+ if (!found) throw new Error(`${jobName} has no step "${name}"`);+ return found;+};++describe('the audits-at-head dispatch', () => {+ it('is titled for its pull request and exact head, which merge-guard filters on', () => {+ expect(workflow['run-name']).toBe(+ 'audits-at-head #${{ inputs.pr }} ${{ inputs.head }}',+ );+ expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch']);+ const inputs = workflow.on.workflow_dispatch.inputs;+ expect(inputs.pr.required).toBe(true);+ expect(inputs.head.required).toBe(true);+ expect(inputs['include-contracts']).toMatchObject({+ type: 'boolean',+ default: false,+ });+ });++ it('runs from main for an open pull request at exactly that head', () => {+ const require = step(+ 'gate',+ 'Require a dispatch from main for one exact head',+ );+ expect(require.run).toContain('"$GITHUB_REF" != refs/heads/main');+ expect(require.run).toContain('^[0-9a-f]{40}$');+ const read = step('gate', 'Read the pull request at this head');+ expect(read.run).toContain(+ '[ "$state" != open ] || [ "$head" != "$HEAD_SHA" ]',+ );+ const list = step('gate', 'List the changed files');+ expect(list.run).toContain('.previous_filename // empty');+ expect(list.run).toContain(+ 'diff too large to scope (>3,000 files); split the PR',+ );+ });++ it('treats the head as untrusted code: read-only, no secret, no cache, no credentials', () => {+ expect(workflow.permissions).toEqual({});+ for (const [name, definition] of Object.entries(workflow.jobs)) {+ for (const [scope, level] of Object.entries(+ definition.permissions ?? {},+ )) {+ expect(level, `${name} ${scope}`).toBe('read');+ }+ for (const candidate of definition.steps) {+ expect(candidate.uses ?? '', name).not.toMatch(/actions\/cache/);+ if (String(candidate.uses ?? '').startsWith('actions/checkout')) {+ expect(candidate.with?.['persist-credentials'], name).toBe(false);+ }+ }+ }+ expect(text).not.toMatch(/\$\{\{\s*secrets\./);+ for (const name of ['build-storybook', 'audits', 'contracts']) {+ const checkout = job(name).steps.find(candidate =>+ String(candidate.uses ?? '').startsWith('actions/checkout'),+ );+ expect(checkout.with.ref, name).toBe('${{ inputs.head }}');+ }+ });++ it('waits under the CI ceiling, and the counter counts its live jobs', () => {+ const wait = step('room', 'Wait for room under the CI ceiling');+ expect(wait.uses).toBe('./.ci-admission/.github/actions/ci-admission');+ expect(wait.with.phase).toBe('whole');+ // The most jobs it holds at once: six audit legs and three contract legs.+ const held =+ job('audits').strategy.matrix.leg.length ++ job('contracts').strategy.matrix.leg.length ++ 1;+ expect(wait.with.peak).toBeGreaterThanOrEqual(held);+ expect(counter).toContain(+ `'.github/workflows/audits-at-head.yml': () => ${wait.with.peak},`,+ );+ expect(counter).toMatch(+ /const ADMITTED = \[[^\]]*'\.github\/workflows\/audits-at-head\.yml'/,+ );+ for (const name of ['plan', 'build-storybook']) {+ expect(job(name).needs, name).toContain('room');+ }+ });++ it("plans every owed audit with main's planner, in the head merged into main", () => {+ const steps = job('plan').steps.map(candidate => candidate.name);+ // main's planner code is kept before the head's tree is merged in.+ expect(steps.indexOf("Keep main's planner")).toBeLessThan(+ steps.indexOf('Merge the head into main'),+ );+ expect(step('plan', 'Check out main').with.ref).toBeUndefined();+ const merge = step('plan', 'Merge the head into main');+ expect(merge.run).toContain(+ 'git fetch --quiet --no-tags origin "refs/pull/$PR/head"',+ );+ expect(merge.run).toContain(+ 'test "$(git rev-parse FETCH_HEAD)" = "$HEAD_SHA"',+ );+ expect(merge.run).toContain('merge --quiet --no-ff --no-edit "$HEAD_SHA"');+ const plan = step('plan', 'Plan every owed audit');+ expect(plan.run).toContain(+ 'node "$RUNNER_TEMP/planner/.github/scripts/a11y-dependent-audits.mjs"',+ );+ expect(plan.run).toContain('--attempt 2');+ expect(plan.env.ASTRYX_HEAD_SHA).toBe('${{ inputs.head }}');+ expect(job('audits').strategy.matrix.leg).toEqual([1, 2, 3, 4, 5, 6]);+ });++ it("selects the contract specs with main's runner, as a labelled pull request does", () => {+ const count = step('contracts', "Count this leg's contract specs");+ // main's runner code, with the merge's routing lines and axe config.+ expect(count.run).toContain(+ 'git show "$MAIN_SHA:.github/scripts/a11y-pr-contracts.mjs"',+ );+ expect(count.env.MAIN_SHA).toBe('${{ github.sha }}');+ for (const name of [+ "Count this leg's contract specs",+ "Run this leg's contract specs",+ ]) {+ expect(step('contracts', name).env.WORKFLOW_SHA, name).toBe(+ '${{ steps.merge.outputs.sha }}',+ );+ }+ const merge = step('contracts', 'Build the head merged into main');+ expect(merge.run).toContain(+ 'git merge-tree --write-tree "$MAIN_SHA" "$HEAD_SHA"',+ );+ expect(merge.run).toContain(+ 'commit-tree "$tree" -p "$MAIN_SHA" -p "$HEAD_SHA"',+ );+ expect(count.run).toContain(+ 'GITHUB_EVENT_NAME=pull_request node "$runner" --count-legs',+ );+ expect(count.env.BASE_SHA).toBe('${{ needs.gate.outputs.base }}');+ expect(count.env.PR_TITLE).toBe('${{ needs.gate.outputs.title }}');+ expect(job('contracts').if).toContain('inputs.include-contracts');+ });++ it('writes the record merge-guard reads, and fails unless every leg passed', () => {+ const record = job('record');+ expect(record.needs).toEqual(['gate', 'plan', 'audits', 'contracts']);+ const write = step('record', 'Write the record');+ for (const field of [+ 'head: process.env.HEAD_SHA',+ 'pr: Number(process.env.PR)',+ 'source: "audits-at-head"',+ 'complete: audited && plan.complete && plan.head === process.env.HEAD_SHA',+ 'record.contracts = {',+ ]) {+ expect(write.run).toContain(field);+ }+ const upload = step('record', 'Upload the record');+ expect(upload.if).toBe('always()');+ expect(upload.with.name).toBe(+ 'a11y-dependent-audits-record-${{ github.run_attempt }}',+ );+ expect(upload.with['if-no-files-found']).toBe('error');+ const gate = step('record', 'Require every audit and contract leg to pass');+ expect(gate.run).toContain('[ "$AUDITS" != success ]');+ expect(gate.run).toContain('[ "$CONTRACTS" != success ]');+ });+});diff --git a/.github/workflows/audits-at-head.yml b/.github/workflows/audits-at-head.ymlnew file mode 100644index 0000000000..70b72ffd08--- /dev/null+++ b/.github/workflows/audits-at-head.yml@@ -0,0 +1,555 @@+# Copyright (c) Meta Platforms, Inc. and affiliates.++# Runs every accessibility audit a pull request owes at its exact head, and+# with `include-contracts` its scoped accessibility contract specs, without+# moving the head. merge-guard accepts this run's record for that head: the+# newest successful run titled for the pull request and head, whose record+# names both.+#+# The head may come from a fork, so it is untrusted code. Every job reads+# only: no write permission, no secret, no saved cache, no persisted+# credentials. The planner, the record and the decisions come from main.+name: Audits at head+run-name: 'audits-at-head #${{ inputs.pr }} ${{ inputs.head }}'++on:+ workflow_dispatch:+ inputs:+ pr:+ description: 'Pull request number'+ type: string+ required: true+ head:+ description: "The pull request's exact full head SHA"+ type: string+ required: true+ include-contracts:+ description: "Also run the pull request's scoped accessibility contract specs at the head"+ type: boolean+ default: false++permissions: {}++# One run per pull request at a time; a second dispatch waits.+concurrency:+ group: audits-at-head-${{ inputs.pr }}+ cancel-in-progress: false++jobs:+ # The pull request must be open at exactly this head. Its changed files+ # come from GitHub's list, which stops at 3,000 files.+ gate:+ runs-on: ubuntu-slim+ timeout-minutes: 5+ permissions:+ contents: read+ pull-requests: read+ outputs:+ base: ${{ steps.pr.outputs.base }}+ title: ${{ steps.pr.outputs.title }}+ steps:+ - name: Require a dispatch from main for one exact head+ env:+ PR: ${{ inputs.pr }}+ HEAD_SHA: ${{ inputs.head }}+ run: |+ if [ "$GITHUB_REF" != refs/heads/main ]; then+ echo "::error::Dispatch this workflow from main, not $GITHUB_REF."+ exit 1+ fi+ [[ "$PR" =~ ^[0-9]+$ ]] || { echo "::error::pr must be a pull request number."; exit 1; }+ [[ "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::head must be a full 40-character SHA."; exit 1; }++ - name: Read the pull request at this head+ id: pr+ env:+ GH_TOKEN: ${{ github.token }}+ PR: ${{ inputs.pr }}+ HEAD_SHA: ${{ inputs.head }}+ run: |+ gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" > "$RUNNER_TEMP/pr.json"+ state=$(node -p "require('$RUNNER_TEMP/pr.json').state")+ head=$(node -p "require('$RUNNER_TEMP/pr.json').head.sha")+ if [ "$state" != open ] || [ "$head" != "$HEAD_SHA" ]; then+ echo "::error::Pull request $PR is $state at $head, not open at $HEAD_SHA. Dispatch again for its current head."+ exit 1+ fi+ echo "base=$(node -p "require('$RUNNER_TEMP/pr.json').base.sha")" >> "$GITHUB_OUTPUT"+ {+ echo 'title<<ASTRYX_TITLE_END'+ node -p "require('$RUNNER_TEMP/pr.json').title"+ echo 'ASTRYX_TITLE_END'+ } >> "$GITHUB_OUTPUT"++ # A rename lists both its old and its new path.+ - name: List the changed files+ env:+ GH_TOKEN: ${{ github.token }}+ PR: ${{ inputs.pr }}+ run: |+ gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$PR/files?per_page=100" \+ --jq '.[] | .filename, (.previous_filename // empty)' | sort -u > "$RUNNER_TEMP/changed-files.txt"+ count=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq .changed_files)+ if [ "$count" -ge 3000 ]; then+ echo "::error::diff too large to scope (>3,000 files); split the PR"+ exit 1+ fi+ echo "$(wc -l < "$RUNNER_TEMP/changed-files.txt") changed paths."++ - name: Upload the changed files+ uses: actions/upload-artifact@v7+ with:+ name: audits-at-head-changed-files+ path: ${{ runner.temp }}/changed-files.txt+ if-no-files-found: error+ retention-days: 7++ # The run waits under the same CI ceiling as pull-request and main runs.+ # The admission counter counts this workflow's live jobs.+ room:+ needs: [gate]+ runs-on: ubuntu-latest+ timeout-minutes: 70+ permissions:+ actions: read+ contents: read+ steps:+ - name: Check out the admission action+ uses: actions/checkout@v7+ with:+ sparse-checkout: .github/actions/ci-admission+ path: .ci-admission+ persist-credentials: false++ - name: Wait for room under the CI ceiling+ id: room+ uses: ./.ci-admission/.github/actions/ci-admission+ continue-on-error: true+ timeout-minutes: 65+ with:+ phase: whole+ peak: 10+ main: false+ max-wait-minutes: 60+ max-looks: 12++ # A dispatch starts after its longest wait; only a failed wait stops it.+ - name: Stop when the wait failed+ if: steps.room.outcome != 'success'+ run: |+ echo "::error::The wait for room under the CI ceiling failed. Dispatch again later."+ exit 1++ # main's planner, run as a later run at a head: every owed audit, in up to+ # six legs, so one run can complete the record.+ plan:+ needs: [gate, room]+ runs-on: ubuntu-slim+ timeout-minutes: 5+ permissions:+ contents: read+ outputs:+ count: ${{ steps.plan.outputs.count || '0' }}+ shares: ${{ steps.plan.outputs.shares || '[]' }}+ steps:+ - name: Check out main+ uses: actions/checkout@v7+ with:+ fetch-depth: 0+ persist-credentials: false++ # The planner's code comes from main, so the head cannot change what it+ # owes or what the record says.+ - name: Keep main's planner+ run: |+ mkdir -p "$RUNNER_TEMP/planner/.github" "$RUNNER_TEMP/planner/scripts"+ cp -R .github/scripts "$RUNNER_TEMP/planner/.github/"+ cp -R scripts/lib "$RUNNER_TEMP/planner/scripts/"++ # The planner reads the tree a pull request's own run plans from: the+ # head merged into main, with the audit specs and imports the head adds.+ - name: Merge the head into main+ env:+ PR: ${{ inputs.pr }}+ HEAD_SHA: ${{ inputs.head }}+ run: |+ git fetch --quiet --no-tags origin "refs/pull/$PR/head"+ test "$(git rev-parse FETCH_HEAD)" = "$HEAD_SHA"+ if ! git -c user.name=audits-at-head -c [email protected] merge --quiet --no-ff --no-edit "$HEAD_SHA"; then+ echo "::error::The head conflicts with main, so its owed audits are unknown. Update the branch."+ exit 1+ fi++ - name: Download the changed files+ uses: actions/download-artifact@v8+ with:+ name: audits-at-head-changed-files+ path: ${{ runner.temp }}/changed++ - name: Plan every owed audit+ id: plan+ env:+ ASTRYX_HEAD_SHA: ${{ inputs.head }}+ run: node "$RUNNER_TEMP/planner/.github/scripts/a11y-dependent-audits.mjs" --changed "$RUNNER_TEMP/changed/changed-files.txt" --attempt 2 --out "$RUNNER_TEMP/plan.json"++ - name: Upload the plan+ uses: actions/upload-artifact@v7+ with:+ name: audits-at-head-plan+ path: ${{ runner.temp }}/plan.json+ if-no-files-found: error+ retention-days: 7++ # Untrusted head code: read-only, no cache.+ build-storybook:+ needs: [gate, room, plan]+ if: needs.plan.outputs.count != '0' || inputs.include-contracts+ runs-on: ubuntu-24.04-arm+ timeout-minutes: 30+ permissions:+ contents: read+ steps:+ - name: Check out the head+ uses: actions/checkout@v7+ with:+ ref: ${{ inputs.head }}+ fetch-depth: 50+ persist-credentials: false++ - name: Require the exact head+ env:+ HEAD_SHA: ${{ inputs.head }}+ run: test "$(git rev-parse HEAD)" = "$HEAD_SHA"++ - name: Setup Node and pnpm+ uses: ./.github/actions/setup++ - name: Build packages and Storybook+ run: node .github/scripts/build-packages-and-storybook.mjs++ - name: Stamp Storybook source revision+ run: git rev-parse HEAD > apps/storybook/dist/astryx-build-sha.txt++ # Contract specs a component token selects read the changed components+ # from this analysis, as a pull request's labelled run does.+ - name: Analyze components+ if: inputs.include-contracts+ env:+ BASE_SHA: ${{ needs.gate.outputs.base }}+ run: |+ git fetch --quiet --no-tags --depth=50 origin "$BASE_SHA"+ node .github/scripts/analyze-pr.js --base "$BASE_SHA" --head HEAD --output analysis.json++ - name: Upload Storybook+ uses: actions/upload-artifact@v7+ with:+ name: audits-at-head-storybook+ path: apps/storybook/dist/+ retention-days: 7++ - name: Upload the analysis+ if: inputs.include-contracts+ uses: actions/upload-artifact@v7+ with:+ name: audits-at-head-analysis+ path: analysis.json+ if-no-files-found: error+ retention-days: 7++ # Each leg runs its share of the plan at the head, as a pull request's+ # dependent-audit legs do. A leg without a share only says so.+ audits:+ name: Audits at head (${{ matrix.leg }}/${{ strategy.job-total }})+ needs: [plan, build-storybook]+ if: always() && needs.plan.result == 'success'+ runs-on: ${{ needs.plan.outputs.count >= matrix.leg && 'ubuntu-latest' || 'ubuntu-slim' }}+ timeout-minutes: 15+ strategy:+ fail-fast: false+ matrix:+ leg: [1, 2, 3, 4, 5, 6]+ permissions:+ contents: read+ steps:+ - name: Decide this leg+ id: leg+ env:+ COUNT: ${{ needs.plan.outputs.count }}+ LEG: ${{ matrix.leg }}+ run: |+ if [ "$LEG" -le "$COUNT" ]; then+ echo 'runs=true' >> "$GITHUB_OUTPUT"+ else+ echo 'runs=false' >> "$GITHUB_OUTPUT"+ echo "This leg runs no audit ($COUNT leg(s) planned)."+ fi++ - name: Require the head's Storybook build+ if: steps.leg.outputs.runs == 'true' && needs.build-storybook.result != 'success'+ run: |+ echo "The audits read the head's Storybook build, which did not succeed."+ exit 1++ - name: Check out the head+ if: steps.leg.outputs.runs == 'true'+ uses: actions/checkout@v7+ with:+ ref: ${{ inputs.head }}+ persist-credentials: false++ - name: Setup Node and pnpm+ if: steps.leg.outputs.runs == 'true'+ uses: ./.github/actions/setup+ with:+ install: 'false'++ - name: Download Storybook+ if: steps.leg.outputs.runs == 'true'+ uses: actions/download-artifact@v8+ with:+ name: audits-at-head-storybook+ path: apps/storybook/dist++ - name: Install Playwright+ if: steps.leg.outputs.runs == 'true'+ run: pnpm install --frozen-lockfile && npx playwright install chromium++ # A planned spec file that the head does not have is left out.+ - name: Run this leg's audits+ id: run+ if: steps.leg.outputs.runs == 'true'+ env:+ SHARES: ${{ needs.plan.outputs.shares }}+ LEG: ${{ matrix.leg }}+ run: |+ node -e 'for (const f of JSON.parse(process.env.SHARES)[Number(process.env.LEG) - 1] ?? []) console.log(f)' > "$RUNNER_TEMP/audits.txt"+ FILES=()+ while IFS= read -r file; do+ [ -f "$file" ] && FILES+=("$file")+ done < "$RUNNER_TEMP/audits.txt"+ if [ "${#FILES[@]}" -eq 0 ]; then+ echo "The head has none of this leg's audit spec files."+ exit 0+ fi+ printf 'Audits in this leg:\n'; printf ' %s\n' "${FILES[@]}"+ pnpm exec playwright test "${FILES[@]}" --config playwright.config.ts --project chromium --reporter list,github --output audits-at-head-output++ - name: Upload audit evidence+ if: always() && (steps.run.outcome == 'success' || steps.run.outcome == 'failure')+ uses: actions/upload-artifact@v7+ with:+ name: audits-at-head-evidence-${{ matrix.leg }}+ path: |+ audits-at-head-output/+ test-results/+ *-audit-evidence/+ if-no-files-found: ignore+ retention-days: 7++ # The pull request's scoped accessibility contract specs at the head, split+ # into three legs by recorded time, with main's runner and routing lines,+ # as a labelled pull-request run selects them.+ contracts:+ name: Contracts at head (${{ matrix.leg }}/${{ strategy.job-total }})+ needs: [gate, build-storybook]+ if: always() && inputs.include-contracts && needs.gate.result == 'success'+ runs-on: ubuntu-24.04-arm+ timeout-minutes: 15+ strategy:+ fail-fast: false+ matrix:+ leg: [1, 2, 3]+ permissions:+ contents: read+ steps:+ - name: Require the head's Storybook build+ if: needs.build-storybook.result != 'success'+ run: |+ echo "The contract specs read the head's Storybook build, which did not succeed."+ exit 1++ - name: Check out the head+ uses: actions/checkout@v7+ with:+ ref: ${{ inputs.head }}+ fetch-depth: 0+ persist-credentials: false++ # The specs run at the head, but their routing lines, the recorded times+ # and the axe config come from the head merged into main, as in a+ # labelled pull-request run's merge commit. The merge is built as an+ # object only; the checkout stays at the head.+ - name: Build the head merged into main+ id: merge+ env:+ MAIN_SHA: ${{ github.sha }}+ HEAD_SHA: ${{ inputs.head }}+ run: |+ git fetch --quiet --no-tags origin "$MAIN_SHA"+ tree=$(git merge-tree --write-tree "$MAIN_SHA" "$HEAD_SHA") || {+ echo "::error::The head conflicts with main, so its contract routing is unknown. Update the branch."+ exit 1+ }+ merge=$(git -c user.name=audits-at-head -c [email protected] commit-tree "$tree" -p "$MAIN_SHA" -p "$HEAD_SHA" -m "audits-at-head merge")+ echo "sha=$merge" >> "$GITHUB_OUTPUT"++ # Listing the specs needs the workspace's dependencies.+ - name: Setup Node and pnpm+ uses: ./.github/actions/setup++ - name: Download Storybook+ uses: actions/download-artifact@v8+ with:+ name: audits-at-head-storybook+ path: apps/storybook/dist++ - name: Download the analysis+ uses: actions/download-artifact@v8+ with:+ name: audits-at-head-analysis++ - name: Count this leg's contract specs+ id: legs+ env:+ ASTRYX_HEAD_SHA: ${{ inputs.head }}+ BASE_SHA: ${{ needs.gate.outputs.base }}+ PR_TITLE: ${{ needs.gate.outputs.title }}+ MAIN_SHA: ${{ github.sha }}+ WORKFLOW_SHA: ${{ steps.merge.outputs.sha }}+ run: |+ # main's runner; the merge's routing lines, times and axe config.+ runner="$RUNNER_TEMP/a11y/.github/scripts/a11y-pr-contracts.mjs"+ mkdir -p "$RUNNER_TEMP/a11y/.github/scripts" "$RUNNER_TEMP/a11y/scripts/lib"+ git show "$MAIN_SHA:.github/scripts/a11y-pr-contracts.mjs" > "$runner"+ git show "$MAIN_SHA:scripts/lib/duration-split.mjs" > "$RUNNER_TEMP/a11y/scripts/lib/duration-split.mjs"+ # The runner selects for a pull request when the event says so.+ GITHUB_EVENT_NAME=pull_request node "$runner" --count-legs ${{ strategy.job-total }} --leg ${{ matrix.leg }} --share-out "$RUNNER_TEMP/contract-share.json"+ mkdir -p contract-share+ cp "$RUNNER_TEMP/contract-share.json" "contract-share/leg-${{ matrix.leg }}.json"++ - name: Install Chromium+ if: steps.legs.outputs.runs == 'true'+ run: npx playwright install chromium++ - name: Run this leg's contract specs+ id: run+ if: steps.legs.outputs.runs == 'true'+ env:+ ASTRYX_HEAD_SHA: ${{ inputs.head }}+ BASE_SHA: ${{ needs.gate.outputs.base }}+ PR_TITLE: ${{ needs.gate.outputs.title }}+ WORKFLOW_SHA: ${{ steps.merge.outputs.sha }}+ run: |+ runner="$RUNNER_TEMP/a11y/.github/scripts/a11y-pr-contracts.mjs"+ GITHUB_EVENT_NAME=pull_request node "$runner" --share "$RUNNER_TEMP/contract-share.json" --leg ${{ steps.legs.outputs.leg }} --of ${{ steps.legs.outputs.count }}++ - name: Upload this leg's share+ uses: actions/upload-artifact@v7+ with:+ name: audits-at-head-contract-share-${{ matrix.leg }}+ path: contract-share/+ if-no-files-found: error+ retention-days: 7++ - name: Upload contract evidence+ if: always() && (steps.run.outcome == 'success' || steps.run.outcome == 'failure')+ uses: actions/upload-artifact@v7+ with:+ name: audits-at-head-contract-evidence-${{ matrix.leg }}+ path: |+ pr-a11y-evidence/+ pr-a11y-output/+ test-results/+ *-audit-evidence/+ if-no-files-found: ignore+ retention-days: 7++ # The record merge-guard reads, written by main's code from the plan and the+ # jobs' results. The run fails unless every audit, and every contract leg+ # when included, passed.+ record:+ needs: [gate, plan, audits, contracts]+ if: always() && needs.plan.result == 'success'+ runs-on: ubuntu-slim+ timeout-minutes: 5+ permissions:+ contents: read+ steps:+ - name: Download the plan+ uses: actions/download-artifact@v8+ with:+ name: audits-at-head-plan+ path: ${{ runner.temp }}++ - name: Download the contract shares+ if: inputs.include-contracts+ uses: actions/download-artifact@v8+ with:+ pattern: audits-at-head-contract-share-*+ merge-multiple: true+ path: ${{ runner.temp }}/contract-share++ - name: Write the record+ env:+ PR: ${{ inputs.pr }}+ HEAD_SHA: ${{ inputs.head }}+ RUN_ATTEMPT: ${{ github.run_attempt }}+ AUDITS: ${{ needs.audits.result }}+ CONTRACTS: ${{ needs.contracts.result }}+ INCLUDE_CONTRACTS: ${{ inputs.include-contracts }}+ run: |+ node --input-type=module -e '+ import fs from "node:fs";+ import path from "node:path";+ const temp = process.env.RUNNER_TEMP;+ const plan = JSON.parse(fs.readFileSync(path.join(temp, "plan.json"), "utf8"));+ const audited = process.env.AUDITS === "success";+ const record = {+ head: process.env.HEAD_SHA,+ attempt: Number(process.env.RUN_ATTEMPT),+ owed: plan.owed,+ ran: audited ? plan.ran : [],+ deferred: plan.deferred,+ complete: audited && plan.complete && plan.head === process.env.HEAD_SHA,+ pr: Number(process.env.PR),+ source: "audits-at-head",+ };+ if (process.env.INCLUDE_CONTRACTS === "true") {+ const dir = path.join(temp, "contract-share");+ const selected = fs.existsSync(dir)+ ? fs.readdirSync(dir).flatMap(file => JSON.parse(fs.readFileSync(path.join(dir, file), "utf8")).run.map(spec => spec.file))+ : [];+ const passed = process.env.CONTRACTS === "success";+ record.contracts = {+ selected: [...new Set(selected)].sort(),+ ran: passed ? [...new Set(selected)].sort() : [],+ complete: passed && fs.existsSync(dir) && fs.readdirSync(dir).length === 3,+ };+ }+ fs.writeFileSync(path.join(temp, "a11y-dependent-audits.json"), JSON.stringify(record, null, 2) + "\n");+ console.log(JSON.stringify(record, null, 2));+ '++ - name: Upload the record+ if: always()+ uses: actions/upload-artifact@v7+ with:+ name: a11y-dependent-audits-record-${{ github.run_attempt }}+ path: ${{ runner.temp }}/a11y-dependent-audits.json+ if-no-files-found: error+ retention-days: 30++ - name: Require every audit and contract leg to pass+ env:+ AUDITS: ${{ needs.audits.result }}+ CONTRACTS: ${{ needs.contracts.result }}+ INCLUDE_CONTRACTS: ${{ inputs.include-contracts }}+ run: |+ if [ "$AUDITS" != success ]; then+ echo "::error::The audits at this head did not all pass ($AUDITS)."+ exit 1+ fi+ if [ "$INCLUDE_CONTRACTS" = true ] && [ "$CONTRACTS" != success ]; then+ echo "::error::The contract specs at this head did not all pass ($CONTRACTS)."+ exit 1+ fidiff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.mdindex e09c7b7a08..13ebd90b3a 100644--- a/docs/specs/AST-030/spec.md+++ b/docs/specs/AST-030/spec.md@@ -249,7 +249,7 @@ they are separately named.scope and spec-location mapping the labelled run uses. Then, in the timeleft and for at most one minute of it, it runs the `scoped` and`release-only` spec files of the component folders that render a touched- component through their source value imports, nearest first. It runs no unchanged `audit` or `always` spec. For a shared primitive named in `.github/a11y-shared-primitives.json`, FR12's touched-component rule also runs a dependent-audits leg on every pull-request CI run that includes a change to it: at most three legs, each at most 10 minutes, covering the audits of components that use it. The list starts with Button and IconButton. Layer joins when a Layer change breaks release-check or a dependent audit at release; other additions are a CI & Release and chief-of-staff call. A change to a component's source also runs that component's own audit specs in the same leg, on every pull-request CI run that includes the change, within the same three legs of ten minutes. Audits beyond that budget are listed by name as not yet run, and they run on a later run at the same head, which may use more legs; merge-guard merges only on a run at the exact head that ran every owed audit. When GitHub cannot list a pull request's changed files, every audit is owed and no run at that head is complete, so merge-guard does not merge it; the pull request must be split. The contract job runs in parallel with the unit-test jobs and+ component through their source value imports, nearest first. It runs no unchanged `audit` or `always` spec. For a shared primitive named in `.github/a11y-shared-primitives.json`, FR12's touched-component rule also runs a dependent-audits leg on every pull-request CI run that includes a change to it: at most three legs, each at most 10 minutes, covering the audits of components that use it. The list starts with Button and IconButton. Layer joins when a Layer change breaks release-check or a dependent audit at release; other additions are a CI & Release and chief-of-staff call. A change to a component's source also runs that component's own audit specs in the same leg, on every pull-request CI run that includes the change, within the same three legs of ten minutes. Audits beyond that budget are listed by name as not yet run, and they run on a later run at the same head, which may use more legs; merge-guard merges only on a run at the exact head that ran every owed audit. When GitHub cannot list a pull request's changed files, every audit is owed and no run at that head is complete, so merge-guard does not merge it; the pull request must be split. A main-only dispatch may run every owed audit at a pull request's exact head, as untrusted code under the same limits as the pull request's own run; merge-guard accepts its record for that head as it accepts the pull request run's. With contracts requested, the same dispatch also runs, at that head, the scoped accessibility contract specs a labelled pull-request run selects; merge-guard accepts its result as that head's opt-in accessibility evidence only when every selected spec ran and passed. The contract job runs in parallel with the unit-test jobs andMUST NOT become the pull request's critical path: it starts after theStorybook build and MUST finish before the slowest unit-test job, so thetime until the required `test` join reports does not grow. It stops after@@ -663,6 +663,7 @@ The nightly perf lane is the one scheduled measurement outside them (FR18).| FR12 | `a11y-dependent-audits.test.mjs` planning cases and the CI workflow contract | a Button change; an IconButton change; a test, story or doc change in a primitive's folder; a change to no primitive; the plan's legs and their recorded times | a Button change that leaves a dependent component's audit out, plans more than three legs or a leg over ten minutes, or a dependent audit failure the `test` join passes || FR12 | `a11y-dependent-audits.test.mjs` own-audit and deferral cases; the dependent-audit record | a component source change; an over-budget set on a first run; a later run at the same head | a component source change that leaves its own audits out; an over-budget set whose deferred audits are not listed by name; a head that merges on a run that left an owed audit unrun || FR12 | `a11y-dependent-audits.test.mjs` undecided-scope cases; `test-scope-action.test.mjs` truncated-diff case | a diff over GitHub's file-list limit on a first run and on a later run | such a diff whose record is complete, that omits the split message, or that merge-guard merges |+| FR12 | `audits-at-head.test.mjs` record contract; merge-guard's exact-head record check | a dispatch record at the exact head that ran every owed audit; one at another head; one missing an owed audit; with contracts, a complete passing result, and one with a selected spec missing or failing | merge-guard refuses the first or the complete contracts, or accepts any of the others || FR13 | classifier, workflow contract, component-analysis and RTL-scope tests | component change; shared module; Changeset beside code; infrastructure path; incomplete list; no build; an interaction-harness or lint-plugin path beside code, alone and with another shared path, and a script or other shared path beside one | 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; run over the request budget; maintainer dispatch; fork PR, code-only: an owner's exact-head approval plus the owner command clears the code half | `review-required` succeeds while spec approval is missing, another workflow publishes a review context, a fork review starts the spec checks, a non-command comment starts a runner, an over-budget run decides, or a fork's approved code-only PR stays pending after the owner command |