Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci: a shared primitive's change runs its dependents' accessibility audits (#10536)

Cindy Zhang8776a6d6450a
diff --git a/.github/a11y-shared-primitives.json b/.github/a11y-shared-primitives.json
new file mode 100644
index 0000000000..8edcfb6d76
--- /dev/null
+++ b/.github/a11y-shared-primitives.json
@@ -0,0 +1,4 @@
+{
+ "$comment": "Shared primitives whose source change runs the audit specs of the components that use them (spec:AST-030 FR12). Layer joins when a Layer change breaks the release check or a dependent audit at release; other additions are a CI & Release and chief-of-staff call.",
+ "primitives": ["core/Button", "core/IconButton"]
+}
diff --git a/.github/scripts/a11y-dependent-audits.mjs b/.github/scripts/a11y-dependent-audits.mjs
new file mode 100644
index 0000000000..f573371c25
--- /dev/null
+++ b/.github/scripts/a11y-dependent-audits.mjs
@@ -0,0 +1,200 @@
+#!/usr/bin/env node
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file The dependent audits a shared primitive's change runs (spec:AST-030
+ * FR12).
+ * @input The changed files, the shared primitives that
+ * `.github/a11y-shared-primitives.json` lists, the repository's source
+ * import graph, the `audit` specs, and their recorded times.
+ * @output The `audit` specs of the components that use a changed primitive,
+ * split into at most three legs of about ten minutes each by recorded time.
+ * @position The plan job writes the legs; each leg runs its share. An `audit`
+ * spec otherwise runs only in its own component-audit pull request and in the
+ * release check, so a change to a shared component such as Button could break
+ * a dependent's audit with no pull-request signal.
+ */
+
+import {execFileSync} from 'node:child_process';
+import fs from 'node:fs';
+import path from 'node:path';
+import {fileURLToPath} from 'node:url';
+
+import {
+ componentFolderOf,
+ fileSeconds,
+ importerGraph,
+ isRenderedSource,
+ parseRouting,
+ planLegs,
+ renderingFolders,
+} from './a11y-pr-contracts.mjs';
+import {isA11ySpecFile} from './lib/a11y-spec-files.mjs';
+
+export const PRIMITIVES_FILE = '.github/a11y-shared-primitives.json';
+export const MAX_LEGS = 3;
+const DURATIONS_FILE = '.github/a11y-contract-durations.json';
+
+/**
+ * The shared primitives, as `<package>/<Folder>`.
+ * @param {string} root
+ * @returns {string[]}
+ */
+export function readPrimitives(root) {
+ const {primitives} = JSON.parse(
+ fs.readFileSync(path.join(root, PRIMITIVES_FILE), 'utf8'),
+ );
+ if (!Array.isArray(primitives) || primitives.length === 0) {
+ throw new Error(`${PRIMITIVES_FILE} lists no primitives`);
+ }
+ for (const primitive of primitives) {
+ if (!/^[a-z][a-z0-9-]*\/[A-Z][A-Za-z0-9]*$/.test(primitive)) {
+ throw new Error(
+ `${PRIMITIVES_FILE}: not a component folder: ${primitive}`,
+ );
+ }
+ }
+ return primitives;
+}
+
+/**
+ * The primitives whose own rendered source a change touches: a test, story,
+ * doc or note in the folder renders nothing.
+ * @param {string[]} primitives
+ * @param {string[]} changed
+ */
+export function changedPrimitives(primitives, changed) {
+ const touched = new Set(
+ changed.filter(isRenderedSource).map(componentFolderOf).filter(Boolean),
+ );
+ return primitives.filter(primitive => touched.has(primitive));
+}
+
+/**
+ * The `audit` specs of the given component folders.
+ * @param {{file: string, mode: string}[]} specs
+ * @param {Set<string>} folders
+ */
+export function dependentAudits(specs, folders) {
+ return specs
+ .filter(
+ ({file, mode}) =>
+ mode === 'audit' && folders.has(componentFolderOf(file)),
+ )
+ .map(({file}) => file)
+ .sort();
+}
+
+/** Every browser accessibility spec file in the tree, with its routing mode. */
+export function listAuditSpecs(root) {
+ return execFileSync('git', ['ls-files', '--', 'packages'], {
+ cwd: root,
+ encoding: 'utf8',
+ })
+ .split('\n')
+ .filter(isA11ySpecFile)
+ .map(file => ({
+ file,
+ mode: parseRouting(fs.readFileSync(path.join(root, file), 'utf8')).mode,
+ }));
+}
+
+/**
+ * The legs for a change: the audits of the changed primitives and of the
+ * component folders that render them.
+ * @param {object} options
+ * @param {string[]} options.changed
+ * @param {string[]} options.primitives
+ * @param {{file: string, mode: string}[]} options.specs
+ * @param {Map<string, Set<string>>} options.importers
+ * @param {Record<string, number>} options.seconds
+ * @param {number} [options.maxLegs]
+ */
+export function planDependentAudits({
+ changed,
+ primitives,
+ specs,
+ importers,
+ seconds,
+ maxLegs = MAX_LEGS,
+}) {
+ const touched = changedPrimitives(primitives, changed);
+ if (touched.length === 0) {
+ return {primitives: [], files: [], count: 0, shares: [], longestMs: 0};
+ }
+ const folders = new Set([
+ ...touched,
+ ...renderingFolders(importers, touched).map(({folder}) => folder),
+ ]);
+ const files = dependentAudits(specs, folders);
+ if (files.length === 0) {
+ return {primitives: touched, files, count: 0, shares: [], longestMs: 0};
+ }
+ const legs = planLegs(files, seconds, maxLegs);
+ return {primitives: touched, files, ...legs};
+}
+
+function main() {
+ const argv = process.argv.slice(2);
+ const value = name => {
+ const at = argv.indexOf(name);
+ return at === -1 ? undefined : argv[at + 1];
+ };
+ const root = process.cwd();
+ const changedFile = value('--changed');
+ const out = value('--out');
+ if (!changedFile || !out) {
+ console.error(
+ 'usage: a11y-dependent-audits.mjs --changed <file> --out <file>',
+ );
+ process.exit(2);
+ }
+ // Without the changed files the primitives a change touches are unknown,
+ // and a missed audit would read as passed.
+ if (!fs.existsSync(changedFile)) {
+ console.error(`::error::The changed-file list ${changedFile} is missing.`);
+ process.exit(1);
+ }
+ const changed = fs
+ .readFileSync(changedFile, 'utf8')
+ .split('\n')
+ .filter(Boolean);
+ const plan = planDependentAudits({
+ changed,
+ primitives: readPrimitives(root),
+ specs: listAuditSpecs(root),
+ importers: importerGraph(root),
+ seconds: fileSeconds(
+ JSON.parse(fs.readFileSync(path.join(root, DURATIONS_FILE), 'utf8')),
+ ),
+ });
+ fs.writeFileSync(out, `${JSON.stringify(plan)}\n`);
+ if (plan.primitives.length === 0) {
+ console.log(
+ 'This change touches no shared primitive; no dependent audit runs.',
+ );
+ } else {
+ const minutes = (plan.longestMs / 60000).toFixed(1);
+ console.log(
+ `Shared primitives changed: ${plan.primitives.join(', ')}. ${plan.files.length} dependent audit spec files in ${plan.count} leg(s), the longest leg's recorded time ${minutes} min.`,
+ );
+ for (const file of plan.files) console.log(` ${file}`);
+ if (plan.longestMs > 10 * 60 * 1000) {
+ console.log(
+ `::warning title=Dependent audits over ten minutes::${plan.count} legs still leave ${minutes} min of recorded time in one leg.`,
+ );
+ }
+ }
+ if (process.env.GITHUB_OUTPUT) {
+ fs.appendFileSync(
+ process.env.GITHUB_OUTPUT,
+ `count=${plan.count}\nshares=${JSON.stringify(plan.shares)}\n`,
+ );
+ }
+}
+
+if (
+ process.argv[1] &&
+ fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)
+)
+ main();
diff --git a/.github/scripts/a11y-dependent-audits.test.mjs b/.github/scripts/a11y-dependent-audits.test.mjs
new file mode 100644
index 0000000000..55797cfa4e
--- /dev/null
+++ b/.github/scripts/a11y-dependent-audits.test.mjs
@@ -0,0 +1,204 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Contract: a change to a shared primitive runs the audits of the
+ * components that use it (spec:AST-030 FR12, DEC-25).
+ *
+ * An `audit` spec runs only in its own component-audit pull request and in the
+ * release check. A change to shared Button's disabled state once passed every
+ * pull-request check and then failed the release check in ChatSendButton's
+ * audit. The dependent-audits legs close that gap for the primitives the list
+ * names, within at most three legs of about ten minutes each.
+ */
+
+import fs from 'node:fs';
+import path from 'node:path';
+
+import {describe, expect, it} from 'vitest';
+import yaml from 'yaml';
+
+import {
+ changedPrimitives,
+ dependentAudits,
+ listAuditSpecs,
+ MAX_LEGS,
+ planDependentAudits,
+ PRIMITIVES_FILE,
+ readPrimitives,
+} from './a11y-dependent-audits.mjs';
+import {
+ fileSeconds,
+ importerGraph,
+ LEG_BUDGET_MS,
+} from './a11y-pr-contracts.mjs';
+
+const root = path.resolve(import.meta.dirname, '../..');
+const ci = yaml.parse(
+ fs.readFileSync(path.join(root, '.github/workflows/ci.yml'), 'utf8'),
+);
+const seconds = fileSeconds(
+ JSON.parse(
+ fs.readFileSync(
+ path.join(root, '.github/a11y-contract-durations.json'),
+ 'utf8',
+ ),
+ ),
+);
+const specs = listAuditSpecs(root);
+const importers = importerGraph(root);
+const plan = changed =>
+ planDependentAudits({
+ changed,
+ primitives: readPrimitives(root),
+ specs,
+ importers,
+ seconds,
+ });
+
+describe('the shared primitives', () => {
+ it('start with Button and IconButton, in one versioned file', () => {
+ expect(PRIMITIVES_FILE).toBe('.github/a11y-shared-primitives.json');
+ expect(readPrimitives(root)).toEqual(['core/Button', 'core/IconButton']);
+ });
+
+ it("count only a primitive's own source, never a test, story, doc or note", () => {
+ const primitives = ['core/Button', 'core/IconButton'];
+ expect(
+ changedPrimitives(primitives, ['packages/core/src/Button/Button.tsx']),
+ ).toEqual(['core/Button']);
+ expect(
+ changedPrimitives(primitives, [
+ 'packages/core/src/Button/__tests__/Button.a11y.chromium.spec.ts',
+ 'packages/core/src/Button/Button.test.tsx',
+ 'packages/core/src/Button/Button.stories.tsx',
+ 'packages/core/src/Button/Button.doc.mjs',
+ 'packages/core/src/Button/README.md',
+ 'packages/core/src/ButtonGroup/ButtonGroup.tsx',
+ ]),
+ ).toEqual([]);
+ });
+});
+
+describe("a Button change runs its dependents' audits", () => {
+ it("includes ChatSendButton's audit, which the release check caught", () => {
+ const {primitives, files} = plan(['packages/core/src/Button/Button.tsx']);
+ expect(primitives).toEqual(['core/Button']);
+ expect(files).toContain(
+ 'packages/core/src/Chat/__tests__/ChatSendButton.a11y.chromium.spec.ts',
+ );
+ // Only audits: the contract job already runs the other modes.
+ const modeOf = new Map(specs.map(({file, mode}) => [file, mode]));
+ for (const file of files) expect(modeOf.get(file), file).toBe('audit');
+ });
+
+ it("plans an IconButton change's own audit and its users' audits", () => {
+ const {primitives, files} = plan([
+ 'packages/core/src/IconButton/IconButton.tsx',
+ ]);
+ expect(primitives).toEqual(['core/IconButton']);
+ expect(files).toEqual(
+ expect.arrayContaining([
+ 'packages/core/src/DateInput/__tests__/DateInputAudit.a11y.chromium.spec.ts',
+ 'packages/core/src/IconButton/__tests__/IconButtonAudit.a11y.chromium.spec.ts',
+ ]),
+ );
+ });
+
+ it('fits at most three legs of ten minutes at the recorded times', () => {
+ const {count, shares, longestMs, files} = plan([
+ 'packages/core/src/Button/Button.tsx',
+ ]);
+ expect(count).toBeGreaterThan(0);
+ expect(count).toBeLessThanOrEqual(MAX_LEGS);
+ expect(longestMs).toBeLessThanOrEqual(LEG_BUDGET_MS);
+ expect(shares.flat().sort()).toEqual([...files].sort());
+ });
+
+ it('plans nothing for a change that touches no primitive', () => {
+ for (const changed of [
+ ['packages/core/src/Chat/ChatSendButton.tsx'],
+ ['packages/core/src/Button/Button.test.tsx'],
+ [],
+ ]) {
+ expect(plan(changed)).toMatchObject({count: 0, files: [], shares: []});
+ }
+ });
+
+ it("selects only audit specs of the primitive's and its users' folders", () => {
+ const sample = [
+ {
+ file: 'packages/core/src/Chat/__tests__/A.a11y.chromium.spec.ts',
+ mode: 'audit',
+ },
+ {
+ file: 'packages/core/src/Chat/__tests__/B.a11y.chromium.spec.ts',
+ mode: 'scoped',
+ },
+ {
+ file: 'packages/core/src/Tabs/__tests__/C.a11y.chromium.spec.ts',
+ mode: 'audit',
+ },
+ ];
+ expect(dependentAudits(sample, new Set(['core/Chat']))).toEqual([
+ 'packages/core/src/Chat/__tests__/A.a11y.chromium.spec.ts',
+ ]);
+ });
+});
+
+describe('the dependent-audits jobs', () => {
+ const planJob = ci.jobs['a11y-dependent-audits-plan'];
+ const legs = ci.jobs['pr-a11y-dependent-audits'];
+ const step = (job, name) => job.steps.find(s => s.name === name);
+
+ it('plan once on a slim runner, from the changed files at the merge commit', () => {
+ expect(planJob['runs-on']).toBe('ubuntu-slim');
+ expect(planJob.needs).toContain('build-storybook');
+ const run = step(planJob, 'Plan the dependent audits');
+ expect(run.run).toBe(
+ 'node .github/scripts/a11y-dependent-audits.mjs --changed "$CHANGED_FILES" --out "$RUNNER_TEMP/dependent-audits.json"',
+ );
+ expect(step(planJob, 'Require the changed-file list').run).toContain(
+ 'exit 1',
+ );
+ });
+
+ it('run up to three legs, on a full runner only when a leg has a share', () => {
+ expect(legs.strategy.matrix.leg).toEqual([1, 2, 3]);
+ expect(legs.strategy['fail-fast']).toBe(false);
+ expect(legs['runs-on']).toBe(
+ "${{ needs.a11y-dependent-audits-plan.outputs.count >= matrix.leg && 'ubuntu-latest' || 'ubuntu-slim' }}",
+ );
+ expect(step(legs, 'Require the dependent-audit plan').if).toBe(
+ "needs.a11y-dependent-audits-plan.result != 'success'",
+ );
+ const run = step(legs, "Run this leg's dependent audits");
+ expect(run.run).toContain(
+ 'pnpm exec playwright test "${FILES[@]}" --config playwright.config.ts --project chromium',
+ );
+ // The head must carry the contract lane's environment.
+ expect(
+ step(legs, "Require this lane's environment in the branch").run,
+ ).toContain('check --lane a11y-contracts');
+ // Specs run at the head that built the Storybook.
+ expect(
+ step(legs, 'Check out the head that built the Storybook').with.ref,
+ ).toBe('${{ github.event.pull_request.head.sha || github.sha }}');
+ });
+
+ it('block the merge through the test join', () => {
+ expect(ci.jobs.test.needs).toContain('pr-a11y-dependent-audits');
+ expect(
+ ci.jobs.test.steps.find(
+ s => s.name === 'Require expected test-owner outcomes',
+ ).env.PR_A11Y_DEPENDENT_AUDITS_RESULT,
+ ).toBe('${{ needs.pr-a11y-dependent-audits.result }}');
+ expect(
+ fs.readFileSync(
+ path.join(root, '.github/scripts/ci-test-join.mjs'),
+ 'utf8',
+ ),
+ ).toContain(
+ "['pr-a11y-dependent-audits', process.env.PR_A11Y_DEPENDENT_AUDITS_RESULT]",
+ );
+ });
+});
diff --git a/.github/scripts/a11y-pr-contracts.mjs b/.github/scripts/a11y-pr-contracts.mjs
index 89f131b526..d65fdf6fca 100644
--- a/.github/scripts/a11y-pr-contracts.mjs
+++ b/.github/scripts/a11y-pr-contracts.mjs
@@ -422,11 +422,24 @@ const RESOLVE_SUFFIXES = [
'/index.js',
];
-const componentFolderOf = file => {
+/**
+ * The component folder that holds a file, as `<package>/<Folder>`.
+ * @param {string} file
+ */
+export const componentFolderOf = file => {
const match = /^packages\/([^/]+)\/src\/([A-Z][^/]*)\//.exec(file);
return match ? `${match[1]}/${match[2]}` : null;
};
+/**
+ * Whether a file is source the import graph follows: code that can put
+ * something on a page, never a test, story, doc or type declaration.
+ * @param {string} file
+ */
+export function isRenderedSource(file) {
+ return SOURCE.test(file) && !NOT_RENDERED.test(file);
+}
+
function sourceFiles(root, dir) {
const out = [];
const full = path.join(root, dir);
@@ -436,7 +449,7 @@ function sourceFiles(root, dir) {
if (entry.isDirectory()) {
if (entry.name !== 'node_modules' && entry.name !== 'dist')
out.push(...sourceFiles(root, file));
- } else if (SOURCE.test(entry.name) && !NOT_RENDERED.test(file)) {
+ } else if (isRenderedSource(file)) {
out.push(file);
}
}
diff --git a/.github/scripts/ci-admission.test.mjs b/.github/scripts/ci-admission.test.mjs
index ffe59fb7ad..0e38431ddb 100644
--- a/.github/scripts/ci-admission.test.mjs
+++ b/.github/scripts/ci-admission.test.mjs
@@ -210,7 +210,9 @@ describe('where runs wait', () => {
guarded.push(id);
}
expect(guarded.sort()).toEqual([
+ 'a11y-dependent-audits-plan',
'docsite-build',
+ 'pr-a11y-dependent-audits',
'pr-component-a11y-contracts',
'pr-interaction',
'pr-interaction-webkit',
diff --git a/.github/scripts/ci-test-join.mjs b/.github/scripts/ci-test-join.mjs
index af1d26bbeb..d17ce0186a 100644
--- a/.github/scripts/ci-test-join.mjs
+++ b/.github/scripts/ci-test-join.mjs
@@ -24,6 +24,7 @@ const requiredSuccess = [
'pr-component-a11y-contracts',
process.env.PR_COMPONENT_A11Y_CONTRACTS_RESULT,
],
+ ['pr-a11y-dependent-audits', process.env.PR_A11Y_DEPENDENT_AUDITS_RESULT],
];
function fail(message) {
diff --git a/.github/scripts/ci-test-join.test.mjs b/.github/scripts/ci-test-join.test.mjs
index d3cf62eef5..48b05cb388 100644
--- a/.github/scripts/ci-test-join.test.mjs
+++ b/.github/scripts/ci-test-join.test.mjs
@@ -22,6 +22,7 @@ const broad = {
PR_INTERACTION_RESULT: 'success',
PR_INTERACTION_WEBKIT_RESULT: 'success',
PR_COMPONENT_A11Y_CONTRACTS_RESULT: 'success',
+ PR_A11Y_DEPENDENT_AUDITS_RESULT: 'success',
};
// An override of `null` removes the variable, as a missing `needs` result would.
@@ -67,6 +68,10 @@ describe('pull-request test join', () => {
['PR_COMPONENT_A11Y_CONTRACTS_RESULT', 'skipped'],
['PR_COMPONENT_A11Y_CONTRACTS_RESULT', 'cancelled'],
['PR_COMPONENT_A11Y_CONTRACTS_RESULT', null],
+ ['PR_A11Y_DEPENDENT_AUDITS_RESULT', 'failure'],
+ ['PR_A11Y_DEPENDENT_AUDITS_RESULT', 'skipped'],
+ ['PR_A11Y_DEPENDENT_AUDITS_RESULT', 'cancelled'],
+ ['PR_A11Y_DEPENDENT_AUDITS_RESULT', null],
]) {
expect(run({[name]: value}), name).toMatchObject({status: 1});
}
diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjs
index 4e42c2a9fb..60086b6a36 100644
--- a/.github/scripts/ci-test-routing.test.mjs
+++ b/.github/scripts/ci-test-routing.test.mjs
@@ -517,6 +517,7 @@ describe('ci.yml RTL package sharding', () => {
);
expect(readers.map(([name]) => name).sort()).toEqual(
[
+ 'a11y-dependent-audits-plan',
'pr-a11y-guards',
'pr-a11y-specs',
'pr-component-a11y-contracts',
diff --git a/.github/scripts/ci-tooling-routing.test.mjs b/.github/scripts/ci-tooling-routing.test.mjs
index aac0e08b92..34427f2e2c 100644
--- a/.github/scripts/ci-tooling-routing.test.mjs
+++ b/.github/scripts/ci-tooling-routing.test.mjs
@@ -463,6 +463,7 @@ describe('Node-tooling CI routing', () => {
'pr-interaction',
'pr-interaction-webkit',
'pr-component-a11y-contracts',
+ 'pr-a11y-dependent-audits',
]);
expect(ci.jobs.build.needs).toEqual([
'room',
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 06d9db5541..b7165314ab 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -59,7 +59,8 @@ permissions: {}
# nothing in its scope changed; anything undecidable runs everything.
#
# Visual, accessibility and RTL owners (pr-a11y*, visual-scout, pr-visual,
-# pr-rtl*) do not run on pull request updates: they run for release-check,
+# pr-rtl*) do not run on pull request updates (a shared primitive's dependent
+# audits are the one exception, below): they run for release-check,
# which the Main heavy lanes workflow (main-heavy-lanes.yml) dispatches for
# main's tip every three hours and before each weekday cut, and the release
# gate dispatches before a cut. A pull request
@@ -1330,6 +1331,7 @@ jobs:
pr-interaction,
pr-interaction-webkit,
pr-component-a11y-contracts,
+ pr-a11y-dependent-audits,
]
if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (github.event_name != 'workflow_dispatch' && always() && !cancelled()) }}
runs-on: ubuntu-slim
@@ -1412,6 +1414,7 @@ jobs:
PR_INTERACTION_RESULT: ${{ needs.pr-interaction.result }}
PR_INTERACTION_WEBKIT_RESULT: ${{ needs.pr-interaction-webkit.result }}
PR_COMPONENT_A11Y_CONTRACTS_RESULT: ${{ needs.pr-component-a11y-contracts.result }}
+ PR_A11Y_DEPENDENT_AUDITS_RESULT: ${{ needs.pr-a11y-dependent-audits.result }}
run: node .github/scripts/ci-test-join.mjs
# Build the packages and Storybook, and analyze components (parallel with
@@ -4431,6 +4434,197 @@ jobs:
if-no-files-found: ignore
retention-days: 7
+ # Dependent audits (spec:AST-030 FR12): a change to a shared primitive that
+ # .github/a11y-shared-primitives.json lists runs the `audit` specs of the
+ # components that use it, which otherwise run only in their own
+ # component-audit pull request and in the release check. The plan job reads
+ # the changed files and the import graph at the merge commit and splits the
+ # audits into at most three legs of about ten minutes each by recorded time.
+ # It waits for the Storybook build, which the legs need anyway.
+ a11y-dependent-audits-plan:
+ needs: [room, admission, heavy-ci, build-storybook]
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft && (github.event.pull_request.head.repo.full_name == github.repository || contains(github.event.pull_request.labels.*.name, 'ci:run'))) && (!cancelled() && needs.heavy-ci.outputs.deferred != 'true' && (github.event_name != 'workflow_dispatch' && always() && !cancelled() && needs.room.outputs.full != 'true' && needs.admission.outputs.full != 'true')) }}
+ runs-on: ubuntu-slim
+ timeout-minutes: 5
+ permissions:
+ contents: read
+ pull-requests: read
+ outputs:
+ count: ${{ steps.plan.outputs.count || '0' }}
+ shares: ${{ steps.plan.outputs.shares || '[]' }}
+ steps:
+ - name: Check out the scope action
+ uses: actions/checkout@v7
+ with:
+ sparse-checkout: .github/actions/test-scope
+ path: .test-scope
+ persist-credentials: false
+
+ - name: Decide this job's scope
+ id: scope
+ uses: ./.test-scope/.github/actions/test-scope
+ with:
+ paths: '^packages/[^/]+/src/'
+ outside-pull-request: skip
+ component-audit: 'true'
+
+ - name: Skip the dependent audits outside their scope
+ if: steps.scope.outputs.applies != 'true'
+ run: echo "No package source changed; no dependent audit to run."
+
+ # The planner, the primitive list, the import graph and the recorded
+ # times all come from the merge commit.
+ - name: Check out the planner
+ if: steps.scope.outputs.applies == 'true'
+ uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+
+ # Without the list a changed primitive would go unseen and its
+ # dependents' audits would not run.
+ - name: Require the changed-file list
+ if: steps.scope.outputs.applies == 'true' && steps.scope.outputs.changed_files_path == ''
+ run: |
+ echo "::error::The scope step could not list the changed files, so the dependent audits to run are unknown. Re-run the job."
+ exit 1
+
+ - name: Plan the dependent audits
+ id: plan
+ if: steps.scope.outputs.applies == 'true'
+ env:
+ CHANGED_FILES: ${{ steps.scope.outputs.changed_files_path }}
+ run: node .github/scripts/a11y-dependent-audits.mjs --changed "$CHANGED_FILES" --out "$RUNNER_TEMP/dependent-audits.json"
+
+ # Each leg runs its share of the plan at the head that built the Storybook.
+ # A leg without a share runs on a slim runner and only says so. The `test`
+ # join reads the legs' result, so a failing audit blocks the merge.
+ pr-a11y-dependent-audits:
+ name: Dependent audits (${{ matrix.leg }}/${{ strategy.job-total }})
+ needs:
+ [room, admission, heavy-ci, a11y-dependent-audits-plan, build-storybook]
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft && (github.event.pull_request.head.repo.full_name == github.repository || contains(github.event.pull_request.labels.*.name, 'ci:run'))) && (!cancelled() && needs.heavy-ci.outputs.deferred != 'true' && (github.event_name != 'workflow_dispatch' && always() && !cancelled() && needs.room.outputs.full != 'true' && needs.admission.outputs.full != 'true')) }}
+ # An empty count (the plan skipped) compares as 0.
+ runs-on: ${{ needs.a11y-dependent-audits-plan.outputs.count >= matrix.leg && 'ubuntu-latest' || 'ubuntu-slim' }}
+ timeout-minutes: 15
+ strategy:
+ fail-fast: false
+ matrix:
+ leg: [1, 2, 3]
+ permissions:
+ contents: read
+ steps:
+ - name: Require the dependent-audit plan
+ if: needs.a11y-dependent-audits-plan.result != 'success'
+ run: |
+ echo "The dependent-audit plan did not succeed (${{ needs.a11y-dependent-audits-plan.result }}), so the audits to run are unknown."
+ exit 1
+
+ - name: Decide this leg
+ id: leg
+ env:
+ COUNT: ${{ needs.a11y-dependent-audits-plan.outputs.count || '0' }}
+ 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 dependent audit ($COUNT leg(s) planned)."
+ fi
+
+ - name: Require this pull request's Storybook build
+ if: steps.leg.outputs.runs == 'true' && needs.build-storybook.result != 'success'
+ run: |
+ echo "The audits read this pull request's Storybook build, which did not succeed."
+ exit 1
+
+ # The workflow's own commit: this lane's environment marker and its check
+ # (in .github, a parent of the scripts, so the checkout's cone holds the
+ # marker). The head checkout below replaces the workspace, so they move
+ # out first.
+ - name: Check out the scope action
+ if: steps.leg.outputs.runs == 'true'
+ uses: actions/checkout@v7
+ with:
+ sparse-checkout: |
+ .github/actions/test-scope
+ .github/scripts
+ path: .test-scope
+ persist-credentials: false
+
+ - name: Keep this lane's environment marker from the workflow's commit
+ if: steps.leg.outputs.runs == 'true'
+ run: |
+ mkdir -p "$RUNNER_TEMP/lane-environment/.github/scripts"
+ cp .test-scope/.github/scripts/lane-environment.mjs "$RUNNER_TEMP/lane-environment/.github/scripts/"
+ cp .test-scope/.github/lane-environments.json "$RUNNER_TEMP/lane-environment/.github/"
+
+ - name: Check out the head that built the Storybook
+ if: steps.leg.outputs.runs == 'true'
+ uses: actions/checkout@v7
+ with:
+ ref: ${{ github.event.pull_request.head.sha || github.sha }}
+ persist-credentials: false
+
+ # The audits run the same specs and config as the contract job, in its
+ # environment. A head older than that environment stops here.
+ - name: Require this lane's environment in the branch
+ if: steps.leg.outputs.runs == 'true'
+ run: >-
+ node "$RUNNER_TEMP/lane-environment/.github/scripts/lane-environment.mjs" check --lane a11y-contracts
+ --workflow "$RUNNER_TEMP/lane-environment/.github/lane-environments.json"
+ --head .github/lane-environments.json
+
+ - name: Setup Node and pnpm
+ if: steps.leg.outputs.runs == 'true'
+ uses: ./.github/actions/setup
+ with:
+ install: 'false'
+
+ - name: Download Storybook artifact
+ if: steps.leg.outputs.runs == 'true'
+ uses: actions/download-artifact@v8
+ with:
+ name: storybook-${{ needs.build-storybook.outputs.short_hash }}
+ path: apps/storybook/dist
+
+ - name: Install Playwright
+ if: steps.leg.outputs.runs == 'true'
+ run: pnpm install --frozen-lockfile && npx playwright install chromium
+
+ # One worker per leg: the recorded times assume one browser per core. A
+ # planned spec file that the head does not have is left out.
+ - name: Run this leg's dependent audits
+ id: audits
+ if: steps.leg.outputs.runs == 'true'
+ env:
+ SHARES: ${{ needs.a11y-dependent-audits-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/dependent-audits.txt"
+ FILES=()
+ while IFS= read -r file; do
+ [ -f "$file" ] && FILES+=("$file")
+ done < "$RUNNER_TEMP/dependent-audits.txt"
+ if [ "${#FILES[@]}" -eq 0 ]; then
+ echo "The head has none of this leg's audit spec files."
+ exit 0
+ fi
+ printf 'Dependent audits in this leg:\n'; printf ' %s\n' "${FILES[@]}"
+ pnpm exec playwright test "${FILES[@]}" --config playwright.config.ts --project chromium --reporter list,github --output pr-a11y-dependent-output
+
+ - name: Upload dependent-audit evidence
+ if: always() && (steps.audits.outcome == 'success' || steps.audits.outcome == 'failure')
+ uses: actions/upload-artifact@v7
+ with:
+ name: a11y-dependent-audits-${{ matrix.leg }}
+ path: |
+ pr-a11y-dependent-output/
+ test-results/
+ *-audit-evidence/
+ if-no-files-found: ignore
+ retention-days: 7
+
# Release-time projection only: the existing owners above do all measurement.
# A skipped owner or main drift must never look like passing release evidence.
release-check:
diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.md
index 741c522f6a..a0e661b3ad 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 time
left 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. 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. The contract job runs in parallel with the unit-test jobs and
MUST NOT become the pull request's critical path: it starts after the
Storybook build and MUST finish before the slowest unit-test job, so the
time until the required `test` join reports does not grow. It stops after
@@ -654,6 +654,7 @@ The nightly perf lane is the one scheduled measurement outside them (FR18).
| 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 |
| FR12 | `touched-components.test.mjs` changed-spec routing; `a11y-pr-contracts.test.mjs` `changedOnly` cases; `a11y-changed-stories.test.mjs` and the touched job's story-audit contract | a pull request that adds a browser accessibility spec; one that changes an `always` spec; one that changes a `release-only` or an `audit` spec; one that changes more spec files than the limit; a component change with no spec change; a pull request that adds an `a11y/` story no component owns; one that adds a story to an untouched component's story file beside a touched component | a pull request that adds a browser accessibility spec that fails is not caught on that pull request, a spec of a component that is neither changed, touched nor rendering a touched component runs in the contract job, or an unchanged `audit` spec does, a not-run file reads as passed or fails the join, a failing contract leaves the `test` join green, or a new violation in a changed story no component owns passes the touched check |
| FR12 | `a11y-pr-contracts.test.mjs` ownership cases; the CI workflow contract; contract-job and unit-test-job timings on 17 component pull requests | a pull request that touches one component with an owned `release-only` contract, passing and failing; a contract file that cannot finish within the budget; a wide change; a reverse dependent of the touched component; measured: setup up to about 1.5 minutes plus the 8-minute stop, against the slowest unit-test job finishing 9.9 to 25 minutes after the Storybook build; a wide change touching Spinner (its own specs run); the folders that render a touched component, nearest first, type-only imports left out, within a one-minute share, and one that does not fit (reported as not run) | a touched component's owned `release-only` contract does not run on its pull request, a failing contract leaves the `test` join green, a skipped file is split, does not show as "not run" in the check's summary or fails the join, the contract job finishes after the slowest unit-test job, or a touched component's own spec does not run on a wide change, or a rendering folder's spec runs before an owned one |
+| 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 |
| 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 |
@@ -1154,6 +1155,8 @@ fix-forward lands).
**Reference:** `spec:AST-030/DEC-23`
**Decider:** chief of staff with the release owner, `2026-11-05`
+**Superseded in part by:** `spec:AST-030/DEC-25` (a shared primitive's change
+runs the `audit` specs of the components that use it)
A wide refactor that changed Spinner's behavior (its role and its shared
announcement, across eight components) merged without Spinner's own motion
@@ -1170,7 +1173,8 @@ or the critical path; each file that does not fit is reported as not run with
the label that runs it. The one-minute share holds the added runner time to about 360 minutes a day: the owned contracts are the proven catch, and the
rendering folders' share widens only if it catches failures the owned
contracts miss. The default touched-components check keeps its wide-change skip, and
-unchanged `audit` and `always` specs still do not run on a pull request.
+unchanged `audit` and `always` specs still do not run on a pull request, except
+the dependent audits of a shared primitive (DEC-25).
Rejected: dropping the five-component limit for every audit (the visual,
accessibility and RTL audits of a wide change do not fit the default check's
@@ -1189,6 +1193,31 @@ rule widens the scope of no other pull request.
Rejected: any pull request on the prefix (a prefix alone is spoofable).
+### DEC-25 — A shared primitive's change runs its dependents' audits
+
+**Reference:** `spec:AST-030/DEC-25`
+**Decider:** the chief of staff with CI & Release, `2026-11-07`
+
+A change to shared Button's disabled state passed every pull-request check and
+then failed the release check in a Chat component's `audit` spec, which no
+pull request runs. A change to a shared primitive that
+`.github/a11y-shared-primitives.json` lists now runs the `audit` specs of the
+components that use it, on every pull-request CI run that includes the
+change, in at most three legs of about ten minutes each (FR12). The list starts
+with Button and IconButton. A Button change runs about 20 audit spec files in
+two legs of about five minutes each, about 11 runner-minutes a run. The legs
+start after the Storybook build and end before the slowest unit-test job, so
+the time until the required `test` join reports does not grow. Pull-request runs are
+every run a merge rests on: the merge queue has not run since 2026-03-04, and
+a merge rests on the pull request's own run at its exact head. Layer,
+which nearly every audited component uses, joins only when a Layer change
+breaks the release check or a dependent audit at release.
+
+Rejected: running the audits only when the pull request is marked ready and on
+a re-run (a push after ready merges without them); every audit spec on every
+Layer change (about 37 minutes of recorded time on a change that lands about
+four times a day).
+
## Open questions
None.