From 815a5a7ac36dac212df6782619b0ebdb06471415 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 1 Nov 2026 19:12:08 -0800 Subject: [PATCH 1/6] ci: a spec-only change runs the tests that read a record it changes --- .github/scripts/ci-test-routing.test.mjs | 23 +++- .github/scripts/fs-guard-tests.mjs | 99 ++++++++++++++- .github/scripts/fs-guard-tests.test.mjs | 148 ++++++++++++++++++++++- .github/workflows/ci.yml | 66 ++++++++++ 4 files changed, 327 insertions(+), 9 deletions(-) diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjs index 9a3e13e2b2178..7ff10e4c5919f 100644 --- a/.github/scripts/ci-test-routing.test.mjs +++ b/.github/scripts/ci-test-routing.test.mjs @@ -93,6 +93,11 @@ const rootScripts = JSON.parse(read('package.json')).scripts; * A run block with each `pnpm ` replaced by the script's body, * recursively; arguments after the script name stay after its body. */ +// The spec-only lane's run of the tests that read a changed record +// (fs-guard-tests.test.mjs holds its contract); not a lane's suite. +const specReaderRun = step => + / tests that read a changed record$/.test(step.name ?? ''); + function expandScripts(run) { return run.replace(/\bpnpm ([a-z][\w:-]*)(?=\s|$)/g, (whole, name) => Object.hasOwn(rootScripts, name) ? expandScripts(rootScripts[name]) : whole, @@ -147,8 +152,10 @@ describe.each(Object.entries(WORKFLOWS))( it('runs FR23 only after the parallel UI suite has exited', () => { const benchmark = 'packages/core/src/Markdown/Markdown.fr23.perf.test.ts'; const job = workflow.jobs['test-ui']; - const suites = job.steps.filter(step => - expandScripts(step.run ?? '').includes('--project ui'), + const suites = job.steps.filter( + step => + !specReaderRun(step) && + expandScripts(step.run ?? '').includes('--project ui'), ); // The two package scripts every lane calls: the parallel suite without // FR23, and FR23 alone with no file parallelism. @@ -242,8 +249,10 @@ describe.each(Object.entries(WORKFLOWS))( ); expect(Object.keys(job.strategy.matrix)).toEqual(['shard']); expect(job.strategy['fail-fast']).toBe(false); - const suites = job.steps.filter(step => - /--project \w+/.test(expandScripts(step.run ?? '')), + const suites = job.steps.filter( + step => + !specReaderRun(step) && + /--project \w+/.test(expandScripts(step.run ?? '')), ); // The one step that is not sharded is the isolated FR23 benchmark. const unsharded = suites.filter( @@ -330,8 +339,10 @@ describe.each(Object.entries(WORKFLOWS))( `${lane} has no scope step`, ).toBe(true); const steps = workflow.jobs[lane].steps; - const suite = steps.find(step => - expandScripts(step.run ?? '').includes('--project'), + const suite = steps.find( + step => + !specReaderRun(step) && + expandScripts(step.run ?? '').includes('--project'), ); expect(suite.if, `${lane} suite is unconditional`).toContain( "docsite_only != 'true'", diff --git a/.github/scripts/fs-guard-tests.mjs b/.github/scripts/fs-guard-tests.mjs index f9a19c09db637..f39b3924354c5 100644 --- a/.github/scripts/fs-guard-tests.mjs +++ b/.github/scripts/fs-guard-tests.mjs @@ -17,7 +17,12 @@ // subpath) or a relative path into its `dist/`. A project that loads a // package from its build sees its source change only through those. // -// Usage: node .github/scripts/fs-guard-tests.mjs [--changed ] +// - With `--spec-readers --changed `: instead, the tests that read a +// changed spec record (`docs/specs/`). A spec-only pull request runs no other +// Vitest test, so these are the ones its change can break +// (spec:AST-030 FR2). +// +// Usage: node .github/scripts/fs-guard-tests.mjs [--spec-readers] [--changed ] // (newline-separated paths) import {execFileSync} from 'node:child_process'; @@ -181,6 +186,94 @@ export function scopedExtraTests(files, read, changedFiles = []) { return files.filter(file => guards.has(file)); } +const SPEC_ROOT = 'docs/specs/'; +/** A path literal into the spec tree, relative (`../…/docs/specs/…`) or from the root. */ +const SPEC_LITERAL = /(['"`])((?:\.\.?\/)*docs\/specs(?:\/[^'"`\n]*)?)\1/g; +/** `path.join(root, 'docs', 'specs', …)` and the like: the whole tree. */ +const SPEC_SEGMENTS = /(['"])docs\1\s*,\s*(['"])specs\2/; + +/** The source without block comments and whole-line `//` comments, where prose names records. */ +function code(source) { + return source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, ''); +} + +/** + * The spec-tree paths a file names in its code, as repository paths: an + * exact record, a directory, or a prefix where a template computes the rest + * (`docs/specs/${id}/spec.md` names the whole tree). + */ +function specPathsIn(file, source) { + const body = code(source); + const paths = new Set(); + for (const [, , literal] of body.matchAll(SPEC_LITERAL)) { + const fixed = literal.split('${')[0]; + const joined = fixed.startsWith('.') + ? path.posix.normalize(path.posix.join(path.posix.dirname(file), fixed)) + : fixed; + if (joined === 'docs/specs' || joined.startsWith(SPEC_ROOT)) + paths.add(joined.length < SPEC_ROOT.length ? SPEC_ROOT : joined); + } + if (SPEC_SEGMENTS.test(body)) paths.add(SPEC_ROOT); + return paths; +} + +/** + * The tests that read a spec record: the import closure (relative imports + * followed, as for the guards above) reads files and names a spec-tree path in + * its code. With `changedFiles`, only those whose named paths cover a changed + * record: the record itself, a directory above it, or a computed prefix. + * + * @param {string[]} files tracked repository paths + * @param {(file: string) => string} read + * @param {string[] | null} changedFiles the change's paths, or null for every reader + */ +export function specReaderTests(files, read, changedFiles = null) { + const tracked = new Set(files); + const memo = new Map(); + const visit = (file, visiting) => { + if (memo.has(file)) return memo.get(file); + const result = {reads: false, paths: new Set()}; + if (visiting.has(file)) return result; + visiting.add(file); + let source = ''; + try { + source = read(file); + } catch { + source = ''; + } + result.reads = READS_FILES.test(source); + for (const named of specPathsIn(file, source)) result.paths.add(named); + for (const [, raw] of source.matchAll(SPECIFIER)) { + if (!raw.startsWith('.')) continue; + const target = resolve(file, raw, tracked); + if (target == null) continue; + const inner = visit(target, visiting); + result.reads ||= inner.reads; + for (const named of inner.paths) result.paths.add(named); + } + visiting.delete(file); + memo.set(file, result); + return result; + }; + const changedSpecs = + changedFiles == null + ? null + : changedFiles.filter(file => file.startsWith(SPEC_ROOT)); + return files.filter(file => { + if (!TEST_FILE.test(file)) return false; + const {reads, paths} = visit(file, new Set()); + if (!reads || paths.size === 0) return false; + if (changedSpecs == null) return true; + return changedSpecs.some(changed => + [...paths].some( + named => + changed === named || + changed.startsWith(named.endsWith('/') ? named : `${named}/`), + ), + ); + }); +} + if (process.argv[1] === fileURLToPath(import.meta.url)) { const files = execFileSync('git', ['ls-files', '-z'], { encoding: 'utf8', @@ -200,6 +293,8 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { .split('\0') .filter(Boolean); const read = file => fs.readFileSync(file, 'utf8'); - const tests = scopedExtraTests(files, read, changedFiles); + const tests = process.argv.includes('--spec-readers') + ? specReaderTests(files, read, changedFlag === -1 ? null : changedFiles) + : scopedExtraTests(files, read, changedFiles); process.stdout.write(tests.length > 0 ? `${tests.join('\n')}\n` : ''); } diff --git a/.github/scripts/fs-guard-tests.test.mjs b/.github/scripts/fs-guard-tests.test.mjs index 9d16d86adb5c6..010485c532cc9 100644 --- a/.github/scripts/fs-guard-tests.test.mjs +++ b/.github/scripts/fs-guard-tests.test.mjs @@ -6,7 +6,12 @@ import {execFileSync} from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; -import {fsGuardTests, scopedExtraTests} from './fs-guard-tests.mjs'; +import { + fsGuardTests, + scopedExtraTests, + specReaderTests, +} from './fs-guard-tests.mjs'; +import yaml from 'yaml'; const sources = { 'packages/core/src/Button/Button.test.tsx': @@ -170,3 +175,144 @@ describe('scopedExtraTests on this repository (contract)', () => { } }); }); + +describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)', () => { + const sources = { + // Reads one record by a path relative to itself. + 'packages/core/src/motion/roles.test.ts': + "import {readFileSync} from 'node:fs';\nconst spec = readFileSync(resolve(import.meta.dirname, '../../../../docs/specs/AST-094-x/spec.md'), 'utf8');", + // Reads the component tree through a helper it imports. + 'scripts/components.test.mjs': "import {records} from './lib/records.mjs';", + 'scripts/lib/records.mjs': + "import fs from 'node:fs';\nexport const records = () => fs.readdirSync('docs/specs/components');", + // A computed record path names the whole tree. + 'scripts/any.test.mjs': + "import fs from 'node:fs';\nconst read = id => fs.readFileSync(`docs/specs/${id}/spec.md`, 'utf8');", + // So does path.join(root, 'docs', 'specs', …). + 'scripts/joined.test.mjs': + "import fs from 'node:fs';\nconst dir = path.join(root, 'docs', 'specs');", + // Names a record only in prose. + 'packages/core/src/Button/Button.a11y.test.tsx': + "import fs from 'node:fs';\n/**\n * The contract (`docs/specs/AST-021/spec.md` FR5).\n */\n// see docs/specs/AST-021/spec.md\nexport {};", + // Names a record as data but reads no files. + 'scripts/classify.test.mjs': + "const path = 'docs/specs/AST-094-x/spec.md';\nexpect(classify(path)).toBe(true);", + }; + const files = Object.keys(sources); + const read = file => sources[file]; + + it('lists every test whose imports read files and name a spec path in code', () => { + expect(specReaderTests(files, read)).toEqual([ + 'packages/core/src/motion/roles.test.ts', + 'scripts/components.test.mjs', + 'scripts/any.test.mjs', + 'scripts/joined.test.mjs', + ]); + }); + + it('narrows to the readers of a changed record: the record, a directory above it, or the whole tree', () => { + expect( + specReaderTests(files, read, ['docs/specs/AST-094-x/spec.md']), + ).toEqual([ + 'packages/core/src/motion/roles.test.ts', + 'scripts/any.test.mjs', + 'scripts/joined.test.mjs', + ]); + expect( + specReaderTests(files, read, [ + 'docs/specs/components/Button/Button.spec.md', + ]), + ).toEqual([ + 'scripts/components.test.mjs', + 'scripts/any.test.mjs', + 'scripts/joined.test.mjs', + ]); + // A record no test names at all still runs the whole-tree readers. + expect( + specReaderTests(files, read, ['docs/specs/AST-001/spec.md']), + ).toEqual(['scripts/any.test.mjs', 'scripts/joined.test.mjs']); + }); + + it('lists none for a change outside the spec tree', () => { + expect(specReaderTests(files, read, ['packages/core/src/x.ts'])).toEqual( + [], + ); + }); +}); + +describe('spec readers on this repository (contract)', () => { + const root = path.resolve(import.meta.dirname, '../..'); + const files = execFileSync('git', ['ls-files', '-z'], { + cwd: root, + encoding: 'utf8', + maxBuffer: 64 * 1024 * 1024, + }) + .split('\0') + .filter(Boolean); + const read = file => fs.readFileSync(path.join(root, file), 'utf8'); + + it('a spec-only change to AST-094 runs the motion roles test that reads its FR4 table', () => { + expect( + specReaderTests(files, read, [ + 'docs/specs/AST-094-touch-presentations/spec.md', + ]), + ).toContain('packages/core/src/motion/roles.test.ts'); + }); + + it('a change to AST-084 runs the icon-set checks that read it', () => { + expect( + specReaderTests(files, read, ['docs/specs/AST-084-icon-sets/spec.md']), + ).toContain('packages/cli/foundation/discovery/icon-set-checks.test.mjs'); + }); + + const ci = yaml.parse(read('.github/workflows/ci.yml')); + it.each([ + ['test-ui', 'test:ui'], + ['test-node', 'test:node'], + ])( + '%s runs the readers of a changed record on a spec-only change, on one leg', + (id, script) => { + const steps = ci.jobs[id].steps; + const index = name => steps.findIndex(step => step.name === name); + const SPEC_LEG = + "matrix.shard == 1 && steps.scope.outputs.spec_only == 'true'"; + const checkout = + steps[ + index('Check out the change for the tests that read its records') + ]; + expect(checkout).toMatchObject({ + if: SPEC_LEG, + uses: 'actions/checkout@v7', + with: {'fetch-depth': 2}, + }); + const list = steps[index('List the tests that read a changed record')]; + expect(list.if).toBe(SPEC_LEG); + expect(list.run).toContain( + 'node .github/scripts/fs-guard-tests.mjs --spec-readers --changed HEAD^1', + ); + const setup = + steps[index('List the tests that read a changed record') + 1]; + expect(setup).toEqual({ + uses: './.github/actions/setup', + if: "steps.spec-readers.outputs.any == 'true'", + }); + const runner = steps.find( + step => + step.name?.startsWith('Run the ') && + step.name.endsWith(' tests that read a changed record'), + ); + expect(runner.if).toBe("steps.spec-readers.outputs.any == 'true'"); + expect(runner.run).toContain( + `pnpm ${script} --passWithNoTests "\${READERS[@]}"`, + ); + // Before the steps a spec-only change skips. + expect(steps.indexOf(runner)).toBeLessThan( + steps.findIndex( + step => + step.uses === 'actions/checkout@v7' && + String(step.if).includes("spec_only != 'true'"), + ), + ); + }, + ); +}); diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 941242d4960ab..019e4536b979a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -730,6 +730,39 @@ jobs: if: steps.scope.outputs.docsite_only == 'true' || steps.scope.outputs.spec_only == 'true' || steps.scope.outputs.tooling_only == 'true' run: echo "Specialized PR lane — skipping unrelated test suite" + # A spec-only change runs no other test here, so it runs the tests that + # read a record it changes: a record such a test reads can break it, and + # the break would otherwise show first on main (spec:AST-030 FR2). One + # leg runs them all; the lister needs only git and Node. + - name: Check out the change for the tests that read its records + if: matrix.shard == 1 && steps.scope.outputs.spec_only == 'true' + uses: actions/checkout@v7 + with: + fetch-depth: 2 + + - name: List the tests that read a changed record + id: spec-readers + if: matrix.shard == 1 && steps.scope.outputs.spec_only == 'true' + run: | + node .github/scripts/fs-guard-tests.mjs --spec-readers --changed HEAD^1 > "$RUNNER_TEMP/spec-readers.txt" + echo "Tests that read a changed record:" + cat "$RUNNER_TEMP/spec-readers.txt" + if [ -s "$RUNNER_TEMP/spec-readers.txt" ]; then + echo 'any=true' >> "$GITHUB_OUTPUT" + else + echo 'any=false' >> "$GITHUB_OUTPUT" + fi + + - uses: ./.github/actions/setup + if: steps.spec-readers.outputs.any == 'true' + + # The list holds both projects' tests; this project runs its own. + - name: Run the UI tests that read a changed record + if: steps.spec-readers.outputs.any == 'true' + run: | + mapfile -t READERS < "$RUNNER_TEMP/spec-readers.txt" + pnpm test:ui --passWithNoTests "${READERS[@]}" + # Two commits: a pull request's merge commit and its base parent, the # diff a scoped run follows. - uses: actions/checkout@v7 @@ -844,6 +877,39 @@ jobs: if: steps.scope.outputs.docsite_only == 'true' || steps.scope.outputs.spec_only == 'true' run: echo "Specialized PR lane — skipping unrelated test suite" + # A spec-only change runs no other test here, so it runs the tests that + # read a record it changes: a record such a test reads can break it, and + # the break would otherwise show first on main (spec:AST-030 FR2). One + # leg runs them all; the lister needs only git and Node. + - name: Check out the change for the tests that read its records + if: matrix.shard == 1 && steps.scope.outputs.spec_only == 'true' + uses: actions/checkout@v7 + with: + fetch-depth: 2 + + - name: List the tests that read a changed record + id: spec-readers + if: matrix.shard == 1 && steps.scope.outputs.spec_only == 'true' + run: | + node .github/scripts/fs-guard-tests.mjs --spec-readers --changed HEAD^1 > "$RUNNER_TEMP/spec-readers.txt" + echo "Tests that read a changed record:" + cat "$RUNNER_TEMP/spec-readers.txt" + if [ -s "$RUNNER_TEMP/spec-readers.txt" ]; then + echo 'any=true' >> "$GITHUB_OUTPUT" + else + echo 'any=false' >> "$GITHUB_OUTPUT" + fi + + - uses: ./.github/actions/setup + if: steps.spec-readers.outputs.any == 'true' + + # The list holds both projects' tests; this project runs its own. + - name: Run the Node tests that read a changed record + if: steps.spec-readers.outputs.any == 'true' + run: | + mapfile -t READERS < "$RUNNER_TEMP/spec-readers.txt" + pnpm test:node --passWithNoTests "${READERS[@]}" + - uses: actions/checkout@v7 if: steps.scope.outputs.docsite_only != 'true' && steps.scope.outputs.spec_only != 'true' with: From d9ff4fc346c3cfb4f50f9d6d31cb6f5c5bbf92d6 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 1 Nov 2026 19:13:09 -0800 Subject: [PATCH 2/6] spec(AST-030): the knowledge surface's owners include the tests that read a changed record (FR2) --- docs/specs/AST-030/spec.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.md index c47399ac7e0a4..a9792a48d5e85 100644 --- a/docs/specs/AST-030/spec.md +++ b/docs/specs/AST-030/spec.md @@ -94,15 +94,15 @@ they are separately named. surface with a concrete check owner and dependency boundary. The initial taxonomy and current owners are: - | Surface | Positive path ownership | Current check owners | - | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | - | `knowledge` | canonical system, family, design, theme, component, and module records | knowledge validation and spec-owner approval of the current spec content | - | `docsite` | the docsite application | docsite generation and tests | - | `node-tooling` | admitted operational Node tooling whose consumers are covered by Node contract tests | Node Vitest, repository guardrails, and ESLint | - | `runtime:` | public source and package contract for Core, Lab, Charts, Rich Text, Vega, CLI, and Build | the package's unit/type checks plus current broad build and downstream consumer checks; Build's owner includes production CSS-layer browser behavior | - | `theme-build` | shipped theme packages and theme compilation outputs | theme tests, theme package builds, theme-family browser behavior, and stable visual evidence where applicable | - | `storybook-visual` | Storybook stories/configuration and visual, accessibility, or RTL audit infrastructure | Storybook build, preview/visual-report publication, and the applicable browser, visual, accessibility, and RTL checks | - | `shared-or-unknown` | shared configuration, dependency graphs, workflows, classifiers, generated ownership, ambiguous paths, and every unclassified path | all applicable pull-request CI checks | + | Surface | Positive path ownership | Current check owners | + | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | + | `knowledge` | canonical system, family, design, theme, component, and module records | knowledge validation, spec-owner approval of the current spec content, and the Vitest tests that read a changed record, directly or through a module they import | + | `docsite` | the docsite application | docsite generation and tests | + | `node-tooling` | admitted operational Node tooling whose consumers are covered by Node contract tests | Node Vitest, repository guardrails, and ESLint | + | `runtime:` | public source and package contract for Core, Lab, Charts, Rich Text, Vega, CLI, and Build | the package's unit/type checks plus current broad build and downstream consumer checks; Build's owner includes production CSS-layer browser behavior | + | `theme-build` | shipped theme packages and theme compilation outputs | theme tests, theme package builds, theme-family browser behavior, and stable visual evidence where applicable | + | `storybook-visual` | Storybook stories/configuration and visual, accessibility, or RTL audit infrastructure | Storybook build, preview/visual-report publication, and the applicable browser, visual, accessibility, and RTL checks | + | `shared-or-unknown` | shared configuration, dependency graphs, workflows, classifiers, generated ownership, ambiguous paths, and every unclassified path | all applicable pull-request CI checks | A category does not earn a specialized lane merely by existing in this table. Until every selected surface has an admitted, complete specialized owner route, @@ -516,7 +516,7 @@ The nightly perf lane is the one scheduled measurement outside them (FR18). | 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 | +| FR1–FR2 | classifier unit tests expose the surface set; `fs-guard-tests.test.mjs` spec-reader cases | knowledge; docsite; admitted tool; Core/Lab/Charts/Rich Text/Vega source; shared config; unknown; a spec-only change to a record a test reads | an unclassified path receives a specialized lane a category has no check owner, or a spec-only change skips a test that reads its record | | 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 | From 3b8771f38fbf85bc4329dbe612951934e2277b09 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 1 Nov 2026 19:13:33 -0800 Subject: [PATCH 3/6] =?UTF-8?q?spec(AST-030):=20punctuation=20in=20the=20F?= =?UTF-8?q?R1=E2=80=93FR2=20Verification=20row?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/specs/AST-030/spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.md index a9792a48d5e85..76ac7575bbb34 100644 --- a/docs/specs/AST-030/spec.md +++ b/docs/specs/AST-030/spec.md @@ -516,7 +516,7 @@ The nightly perf lane is the one scheduled measurement outside them (FR18). | Contract | Verification | Representative states | Mutation or failure expectation | | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| FR1–FR2 | classifier unit tests expose the surface set; `fs-guard-tests.test.mjs` spec-reader cases | knowledge; docsite; admitted tool; Core/Lab/Charts/Rich Text/Vega source; shared config; unknown; a spec-only change to a record a test reads | an unclassified path receives a specialized lane a category has no check owner, or a spec-only change skips a test that reads its record | +| FR1–FR2 | classifier unit tests expose the surface set; `fs-guard-tests.test.mjs` spec-reader cases | knowledge; docsite; admitted tool; Core/Lab/Charts/Rich Text/Vega source; shared config; unknown; a spec-only change to a record a test reads | an unclassified path receives a specialized lane, a category has no check owner, or a spec-only change skips a test that reads its record | | 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 | From 0287643f0f4a0484a2514a17af6dfa7537dad4e9 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 1 Nov 2026 19:52:27 -0800 Subject: [PATCH 4/6] ci: spec readers cover family, design and theme spec records, count a renamed record under both names, and run per Vitest project --- .github/scripts/fs-guard-tests.mjs | 130 +++++++++++++++++++----- .github/scripts/fs-guard-tests.test.mjs | 89 +++++++++++++++- .github/workflows/ci.yml | 16 +-- 3 files changed, 196 insertions(+), 39 deletions(-) diff --git a/.github/scripts/fs-guard-tests.mjs b/.github/scripts/fs-guard-tests.mjs index f39b3924354c5..8651eb9c17d47 100644 --- a/.github/scripts/fs-guard-tests.mjs +++ b/.github/scripts/fs-guard-tests.mjs @@ -18,11 +18,12 @@ // package from its build sees its source change only through those. // // - With `--spec-readers --changed `: instead, the tests that read a -// changed spec record (`docs/specs/`). A spec-only pull request runs no other +// changed record (spec, component, family, design or theme spec record; +// a renamed one under both names). A spec-only pull request runs no other // Vitest test, so these are the ones its change can break -// (spec:AST-030 FR2). +// (spec:AST-030 FR2). `--project ui|node` keeps one Vitest project's. // -// Usage: node .github/scripts/fs-guard-tests.mjs [--spec-readers] [--changed ] +// Usage: node .github/scripts/fs-guard-tests.mjs [--spec-readers [--project ui|node]] [--changed ] // (newline-separated paths) import {execFileSync} from 'node:child_process'; @@ -186,11 +187,25 @@ export function scopedExtraTests(files, read, changedFiles = []) { return files.filter(file => guards.has(file)); } -const SPEC_ROOT = 'docs/specs/'; -/** A path literal into the spec tree, relative (`../…/docs/specs/…`) or from the root. */ -const SPEC_LITERAL = /(['"`])((?:\.\.?\/)*docs\/specs(?:\/[^'"`\n]*)?)\1/g; -/** `path.join(root, 'docs', 'specs', …)` and the like: the whole tree. */ -const SPEC_SEGMENTS = /(['"])docs\1\s*,\s*(['"])specs\2/; +/** + * The roots of the records a spec-only change may touch (change-scope.cjs's + * spec records): spec and component records, family and design contracts, + * and theme package specs. + */ +const RECORD_ROOTS = [ + 'docs/specs/', + 'docs/families/', + 'docs/design/', + 'packages/themes/', +]; +/** A path literal into a record root, relative (`../…/docs/specs/…`) or from the root. */ +const RECORD_LITERAL = + /(['"`])((?:\.\.?\/)*(?:docs\/(?:specs|families|design)|packages\/themes)(?:\/[^'"`\n]*)?)\1/g; +/** `path.join(root, 'docs', 'specs', …)` and the like: the whole root. */ +const RECORD_SEGMENTS = + /(['"])(docs|packages)\1\s*,\s*(['"])(specs|families|design|themes)\3/g; +const RECORD_PATH = + /^(?:docs\/(?:specs|families|design)\/|packages\/themes\/[^/]+\/[^/]+\.spec\.md$)/; /** The source without block comments and whole-line `//` comments, where prose names records. */ function code(source) { @@ -198,30 +213,66 @@ function code(source) { } /** - * The spec-tree paths a file names in its code, as repository paths: an - * exact record, a directory, or a prefix where a template computes the rest - * (`docs/specs/${id}/spec.md` names the whole tree). + * The record paths a file names in its code, as repository paths: an exact + * record, a directory, or a prefix where a template computes the rest + * (`docs/specs/${id}/spec.md` names the whole spec tree). */ -function specPathsIn(file, source) { +function recordPathsIn(file, source) { const body = code(source); const paths = new Set(); - for (const [, , literal] of body.matchAll(SPEC_LITERAL)) { + // Theme packages hold sources as well as their spec, and many tests read + // those sources; a file reads theme specs only if it also names a + // `.spec.md`. + const namesSpecFile = /\.spec\.md['"`]/.test(body); + const counts = root => root !== 'packages/themes/' || namesSpecFile; + for (const [, , literal] of body.matchAll(RECORD_LITERAL)) { const fixed = literal.split('${')[0]; const joined = fixed.startsWith('.') ? path.posix.normalize(path.posix.join(path.posix.dirname(file), fixed)) : fixed; - if (joined === 'docs/specs' || joined.startsWith(SPEC_ROOT)) - paths.add(joined.length < SPEC_ROOT.length ? SPEC_ROOT : joined); + const root = RECORD_ROOTS.find( + prefix => joined === prefix.slice(0, -1) || joined.startsWith(prefix), + ); + if (root && counts(root)) + paths.add(joined.length < root.length ? root : joined); + } + for (const [, , first, , second] of body.matchAll(RECORD_SEGMENTS)) { + const root = `${first}/${second}/`; + if (RECORD_ROOTS.includes(root) && counts(root)) paths.add(root); } - if (SPEC_SEGMENTS.test(body)) paths.add(SPEC_ROOT); return paths; } /** - * The tests that read a spec record: the import closure (relative imports - * followed, as for the guards above) reads files and names a spec-tree path in - * its code. With `changedFiles`, only those whose named paths cover a changed - * record: the record itself, a directory above it, or a computed prefix. + * The directories whose tests the Vitest `ui` project collects, read from + * vitest.config.ts so the two cannot drift; every other test belongs to the + * `node` project. Throws when the config's `ui` include list has another + * shape, so a config change fails the lister instead of misrouting tests. + * + * @param {string} config the source of vitest.config.ts + * @returns {string[]} directory prefixes, each ending in `/` + */ +export function uiTestRoots(config) { + const block = /name:\s*'ui'[\s\S]*?include:\s*\[([\s\S]*?)\]/.exec(config); + if (!block) throw new Error('vitest.config.ts: no ui project include list'); + const roots = [...block[1].matchAll(/'([^']+)'/g)].map(([, glob]) => { + const match = /^(.+\/)\*\*\/\*\.test\.\{ts,tsx,mjs\}$/.exec(glob); + if (!match) + throw new Error(`vitest.config.ts: unexpected ui include ${glob}`); + return match[1]; + }); + if (roots.length === 0) + throw new Error('vitest.config.ts: empty ui project include list'); + return roots; +} + +/** + * The tests that read a record a spec-only change may touch: the import + * closure (relative imports followed, as for the guards above) reads files + * and names a record path in its code. With `changedFiles`, only those whose + * named paths cover a changed record: the record itself, a directory above + * it, or a computed prefix. A renamed record counts under both names, so the + * caller passes the change's paths without rename detection. * * @param {string[]} files tracked repository paths * @param {(file: string) => string} read @@ -242,7 +293,7 @@ export function specReaderTests(files, read, changedFiles = null) { source = ''; } result.reads = READS_FILES.test(source); - for (const named of specPathsIn(file, source)) result.paths.add(named); + for (const named of recordPathsIn(file, source)) result.paths.add(named); for (const [, raw] of source.matchAll(SPECIFIER)) { if (!raw.startsWith('.')) continue; const target = resolve(file, raw, tracked); @@ -258,7 +309,7 @@ export function specReaderTests(files, read, changedFiles = null) { const changedSpecs = changedFiles == null ? null - : changedFiles.filter(file => file.startsWith(SPEC_ROOT)); + : changedFiles.filter(file => RECORD_PATH.test(file)); return files.filter(file => { if (!TEST_FILE.test(file)) return false; const {reads, paths} = visit(file, new Set()); @@ -281,20 +332,47 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { }) .split('\0') .filter(Boolean); + const specReaders = process.argv.includes('--spec-readers'); const changedFlag = process.argv.indexOf('--changed'); const changedFiles = changedFlag === -1 ? [] : execFileSync( 'git', - ['diff', '--name-only', '-z', process.argv[changedFlag + 1], 'HEAD'], + [ + 'diff', + '--name-only', + '-z', + // A renamed record counts under its old name too: a test that + // reads the old path is the one the rename breaks. + ...(specReaders ? ['--no-renames'] : []), + process.argv[changedFlag + 1], + 'HEAD', + ], {encoding: 'utf8', maxBuffer: 64 * 1024 * 1024}, ) .split('\0') .filter(Boolean); const read = file => fs.readFileSync(file, 'utf8'); - const tests = process.argv.includes('--spec-readers') - ? specReaderTests(files, read, changedFlag === -1 ? null : changedFiles) - : scopedExtraTests(files, read, changedFiles); + let tests; + if (specReaders) { + tests = specReaderTests( + files, + read, + changedFlag === -1 ? null : changedFiles, + ); + // `--project ui|node`: only that Vitest project's tests. + const projectFlag = process.argv.indexOf('--project'); + if (projectFlag !== -1) { + const project = process.argv[projectFlag + 1]; + if (project !== 'ui' && project !== 'node') + throw new Error(`--project must be ui or node, not ${project}`); + const roots = uiTestRoots(read('vitest.config.ts')); + const inUi = test => roots.some(root => test.startsWith(root)); + tests = tests.filter(test => inUi(test) === (project === 'ui')); + } + } else { + tests = scopedExtraTests(files, read, changedFiles); + } process.stdout.write(tests.length > 0 ? `${tests.join('\n')}\n` : ''); } diff --git a/.github/scripts/fs-guard-tests.test.mjs b/.github/scripts/fs-guard-tests.test.mjs index 010485c532cc9..625090211c8ff 100644 --- a/.github/scripts/fs-guard-tests.test.mjs +++ b/.github/scripts/fs-guard-tests.test.mjs @@ -10,7 +10,9 @@ import { fsGuardTests, scopedExtraTests, specReaderTests, + uiTestRoots, } from './fs-guard-tests.mjs'; +import os from 'node:os'; import yaml from 'yaml'; const sources = { @@ -194,6 +196,16 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' // Names a record only in prose. 'packages/core/src/Button/Button.a11y.test.tsx': "import fs from 'node:fs';\n/**\n * The contract (`docs/specs/AST-021/spec.md` FR5).\n */\n// see docs/specs/AST-021/spec.md\nexport {};", + // Reads family and design contracts through a helper. + 'scripts/contracts.test.mjs': "import {load} from './lib/contracts.mjs';", + 'scripts/lib/contracts.mjs': + "import fs from 'node:fs';\nexport const load = () => [fs.readdirSync(path.join(root, 'docs/families')), fs.readdirSync(path.join(root, 'docs', 'design'))];", + // Reads theme specs: the theme root and a spec file name. + 'scripts/theme-records.test.mjs': + "import fs from 'node:fs';\nconst read = name => fs.readFileSync(path.join('packages/themes', name, `${name}.spec.md`), 'utf8');", + // Reads theme sources, not their specs. + 'scripts/theme-sources.test.mjs': + "import fs from 'node:fs';\nconst dirs = fs.readdirSync('packages/themes');", // Names a record as data but reads no files. 'scripts/classify.test.mjs': "const path = 'docs/specs/AST-094-x/spec.md';\nexpect(classify(path)).toBe(true);", @@ -207,6 +219,8 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' 'scripts/components.test.mjs', 'scripts/any.test.mjs', 'scripts/joined.test.mjs', + 'scripts/contracts.test.mjs', + 'scripts/theme-records.test.mjs', ]); }); @@ -233,6 +247,19 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' ).toEqual(['scripts/any.test.mjs', 'scripts/joined.test.mjs']); }); + it('covers every record a spec-only change may touch: family, design and theme spec records', () => { + expect( + specReaderTests(files, read, ['docs/families/action-groups.md']), + ).toEqual(['scripts/contracts.test.mjs']); + expect(specReaderTests(files, read, ['docs/design/motion.md'])).toEqual([ + 'scripts/contracts.test.mjs', + ]); + // A theme spec runs the theme-spec reader, not the theme-source reader. + expect( + specReaderTests(files, read, ['packages/themes/butter/butter.spec.md']), + ).toEqual(['scripts/theme-records.test.mjs']); + }); + it('lists none for a change outside the spec tree', () => { expect(specReaderTests(files, read, ['packages/core/src/x.ts'])).toEqual( [], @@ -265,13 +292,65 @@ describe('spec readers on this repository (contract)', () => { ).toContain('packages/cli/foundation/discovery/icon-set-checks.test.mjs'); }); + it("a renamed record runs the readers of its old name: the lister's diff turns renames off", () => { + const work = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-readers-')); + const git = (...args) => + execFileSync('git', args, {cwd: work, encoding: 'utf8'}); + const write = (file, text) => { + fs.mkdirSync(path.join(work, path.dirname(file)), {recursive: true}); + fs.writeFileSync(path.join(work, file), text); + }; + try { + git('init', '-q'); + git('config', 'user.email', 'test@example.com'); + git('config', 'user.name', 'test'); + write('docs/specs/AST-1-old/spec.md', '# Record\n'); + write( + 'packages/core/src/x.test.ts', + "import fs from 'node:fs';\nfs.readFileSync('docs/specs/AST-1-old/spec.md');\n", + ); + git('add', '-A'); + git('commit', '-qm', 'base'); + git('mv', 'docs/specs/AST-1-old', 'docs/specs/AST-1-new'); + git('commit', '-qm', 'rename'); + const listed = execFileSync( + process.execPath, + [ + path.join(root, '.github/scripts/fs-guard-tests.mjs'), + '--spec-readers', + '--changed', + 'HEAD^1', + ], + {cwd: work, encoding: 'utf8'}, + ); + expect(listed.trim().split('\n')).toEqual([ + 'packages/core/src/x.test.ts', + ]); + } finally { + fs.rmSync(work, {recursive: true, force: true}); + } + }); + + it('splits the readers by Vitest project as vitest.config.ts collects them', () => { + const roots = uiTestRoots(read('vitest.config.ts')); + expect(roots).toContain('packages/core/src/'); + const all = specReaderTests(files, read); + const ui = all.filter(test => roots.some(root => test.startsWith(root))); + expect(ui).toContain('packages/core/src/motion/roles.test.ts'); + expect(ui).not.toContain('scripts/check-knowledge.test.mjs'); + expect(() => + uiTestRoots("name: 'ui', include: ['packages/core/**/*.spec.ts']"), + ).toThrow(/unexpected ui include/); + expect(() => uiTestRoots("name: 'node'")).toThrow(/no ui project/); + }); + const ci = yaml.parse(read('.github/workflows/ci.yml')); it.each([ - ['test-ui', 'test:ui'], - ['test-node', 'test:node'], + ['test-ui', 'test:ui', 'ui'], + ['test-node', 'test:node', 'node'], ])( - '%s runs the readers of a changed record on a spec-only change, on one leg', - (id, script) => { + "%s runs its own project's readers of a changed record on a spec-only change, on one leg", + (id, script, project) => { const steps = ci.jobs[id].steps; const index = name => steps.findIndex(step => step.name === name); const SPEC_LEG = @@ -288,7 +367,7 @@ describe('spec readers on this repository (contract)', () => { const list = steps[index('List the tests that read a changed record')]; expect(list.if).toBe(SPEC_LEG); expect(list.run).toContain( - 'node .github/scripts/fs-guard-tests.mjs --spec-readers --changed HEAD^1', + `node .github/scripts/fs-guard-tests.mjs --spec-readers --project ${project} --changed HEAD^1`, ); const setup = steps[index('List the tests that read a changed record') + 1]; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 019e4536b979a..4dd1ed6b1cc3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -733,7 +733,8 @@ jobs: # A spec-only change runs no other test here, so it runs the tests that # read a record it changes: a record such a test reads can break it, and # the break would otherwise show first on main (spec:AST-030 FR2). One - # leg runs them all; the lister needs only git and Node. + # leg runs this project's readers; the lister needs only git and Node, + # so a change no test here reads sets up nothing. - name: Check out the change for the tests that read its records if: matrix.shard == 1 && steps.scope.outputs.spec_only == 'true' uses: actions/checkout@v7 @@ -744,8 +745,8 @@ jobs: id: spec-readers if: matrix.shard == 1 && steps.scope.outputs.spec_only == 'true' run: | - node .github/scripts/fs-guard-tests.mjs --spec-readers --changed HEAD^1 > "$RUNNER_TEMP/spec-readers.txt" - echo "Tests that read a changed record:" + node .github/scripts/fs-guard-tests.mjs --spec-readers --project ui --changed HEAD^1 > "$RUNNER_TEMP/spec-readers.txt" + echo "UI tests that read a changed record:" cat "$RUNNER_TEMP/spec-readers.txt" if [ -s "$RUNNER_TEMP/spec-readers.txt" ]; then echo 'any=true' >> "$GITHUB_OUTPUT" @@ -756,7 +757,6 @@ jobs: - uses: ./.github/actions/setup if: steps.spec-readers.outputs.any == 'true' - # The list holds both projects' tests; this project runs its own. - name: Run the UI tests that read a changed record if: steps.spec-readers.outputs.any == 'true' run: | @@ -880,7 +880,8 @@ jobs: # A spec-only change runs no other test here, so it runs the tests that # read a record it changes: a record such a test reads can break it, and # the break would otherwise show first on main (spec:AST-030 FR2). One - # leg runs them all; the lister needs only git and Node. + # leg runs this project's readers; the lister needs only git and Node, + # so a change no test here reads sets up nothing. - name: Check out the change for the tests that read its records if: matrix.shard == 1 && steps.scope.outputs.spec_only == 'true' uses: actions/checkout@v7 @@ -891,8 +892,8 @@ jobs: id: spec-readers if: matrix.shard == 1 && steps.scope.outputs.spec_only == 'true' run: | - node .github/scripts/fs-guard-tests.mjs --spec-readers --changed HEAD^1 > "$RUNNER_TEMP/spec-readers.txt" - echo "Tests that read a changed record:" + node .github/scripts/fs-guard-tests.mjs --spec-readers --project node --changed HEAD^1 > "$RUNNER_TEMP/spec-readers.txt" + echo "Node tests that read a changed record:" cat "$RUNNER_TEMP/spec-readers.txt" if [ -s "$RUNNER_TEMP/spec-readers.txt" ]; then echo 'any=true' >> "$GITHUB_OUTPUT" @@ -903,7 +904,6 @@ jobs: - uses: ./.github/actions/setup if: steps.spec-readers.outputs.any == 'true' - # The list holds both projects' tests; this project runs its own. - name: Run the Node tests that read a changed record if: steps.spec-readers.outputs.any == 'true' run: | From 2849fa88051bbac8f2be24c6fd4922a8255a4d53 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 1 Nov 2026 20:22:00 -0800 Subject: [PATCH 5/6] ci: spec-reader runs fail on an empty match, the project filter has a CLI case, and a computed prefix inside a segment names its directory --- .github/scripts/fs-guard-tests.mjs | 33 +++++++++-- .github/scripts/fs-guard-tests.test.mjs | 76 +++++++++++++++++++++++-- .github/workflows/ci.yml | 8 ++- 3 files changed, 103 insertions(+), 14 deletions(-) diff --git a/.github/scripts/fs-guard-tests.mjs b/.github/scripts/fs-guard-tests.mjs index 8651eb9c17d47..527059976451a 100644 --- a/.github/scripts/fs-guard-tests.mjs +++ b/.github/scripts/fs-guard-tests.mjs @@ -214,10 +214,16 @@ function code(source) { /** * The record paths a file names in its code, as repository paths: an exact - * record, a directory, or a prefix where a template computes the rest - * (`docs/specs/${id}/spec.md` names the whole spec tree). + * record, a directory, or a prefix where code computes the rest. A path that + * is neither a tracked file nor a tracked directory (`docs/specs/AST-` before + * `${id}` or `+ id`, or a record since renamed) is cut back to its last `/`: + * `docs/specs/AST-${id}/spec.md` names the whole spec tree. + * + * @param {string} file + * @param {string} source + * @param {(candidate: string) => boolean} isPath a tracked file or directory */ -function recordPathsIn(file, source) { +function recordPathsIn(file, source, isPath) { const body = code(source); const paths = new Set(); // Theme packages hold sources as well as their spec, and many tests read @@ -233,8 +239,15 @@ function recordPathsIn(file, source) { const root = RECORD_ROOTS.find( prefix => joined === prefix.slice(0, -1) || joined.startsWith(prefix), ); - if (root && counts(root)) - paths.add(joined.length < root.length ? root : joined); + if (!root || !counts(root)) continue; + if (joined.length < root.length) { + paths.add(root); + continue; + } + const bare = joined.replace(/\/$/, ''); + paths.add( + isPath(bare) ? joined : joined.slice(0, joined.lastIndexOf('/') + 1), + ); } for (const [, , first, , second] of body.matchAll(RECORD_SEGMENTS)) { const root = `${first}/${second}/`; @@ -280,6 +293,13 @@ export function uiTestRoots(config) { */ export function specReaderTests(files, read, changedFiles = null) { const tracked = new Set(files); + const directories = new Set(); + for (const file of files) { + for (let at = file.indexOf('/'); at !== -1; at = file.indexOf('/', at + 1)) + directories.add(file.slice(0, at)); + } + const isPath = candidate => + tracked.has(candidate) || directories.has(candidate); const memo = new Map(); const visit = (file, visiting) => { if (memo.has(file)) return memo.get(file); @@ -293,7 +313,8 @@ export function specReaderTests(files, read, changedFiles = null) { source = ''; } result.reads = READS_FILES.test(source); - for (const named of recordPathsIn(file, source)) result.paths.add(named); + for (const named of recordPathsIn(file, source, isPath)) + result.paths.add(named); for (const [, raw] of source.matchAll(SPECIFIER)) { if (!raw.startsWith('.')) continue; const target = resolve(file, raw, tracked); diff --git a/.github/scripts/fs-guard-tests.test.mjs b/.github/scripts/fs-guard-tests.test.mjs index 625090211c8ff..105c3e78abdaa 100644 --- a/.github/scripts/fs-guard-tests.test.mjs +++ b/.github/scripts/fs-guard-tests.test.mjs @@ -206,12 +206,25 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' // Reads theme sources, not their specs. 'scripts/theme-sources.test.mjs': "import fs from 'node:fs';\nconst dirs = fs.readdirSync('packages/themes');", + // A computed segment: the prefix ends inside a directory name. + 'scripts/segment.test.mjs': + "import fs from 'node:fs';\nconst read = n => fs.readFileSync(`docs/specs/AST-${n}/spec.md`, 'utf8');", // Names a record as data but reads no files. 'scripts/classify.test.mjs': "const path = 'docs/specs/AST-094-x/spec.md';\nexpect(classify(path)).toBe(true);", }; - const files = Object.keys(sources); - const read = file => sources[file]; + // The records themselves are tracked too: a named path that is neither a + // tracked file nor a directory is cut back to its last `/`. + const files = [ + ...Object.keys(sources), + 'docs/specs/AST-094-x/spec.md', + 'docs/specs/AST-001/spec.md', + 'docs/specs/components/Button/Button.spec.md', + 'docs/families/action-groups.md', + 'docs/design/motion.md', + 'packages/themes/butter/butter.spec.md', + ]; + const read = file => sources[file] ?? ''; it('lists every test whose imports read files and name a spec path in code', () => { expect(specReaderTests(files, read)).toEqual([ @@ -221,6 +234,7 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' 'scripts/joined.test.mjs', 'scripts/contracts.test.mjs', 'scripts/theme-records.test.mjs', + 'scripts/segment.test.mjs', ]); }); @@ -231,6 +245,7 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' 'packages/core/src/motion/roles.test.ts', 'scripts/any.test.mjs', 'scripts/joined.test.mjs', + 'scripts/segment.test.mjs', ]); expect( specReaderTests(files, read, [ @@ -240,11 +255,16 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' 'scripts/components.test.mjs', 'scripts/any.test.mjs', 'scripts/joined.test.mjs', + 'scripts/segment.test.mjs', ]); // A record no test names at all still runs the whole-tree readers. expect( specReaderTests(files, read, ['docs/specs/AST-001/spec.md']), - ).toEqual(['scripts/any.test.mjs', 'scripts/joined.test.mjs']); + ).toEqual([ + 'scripts/any.test.mjs', + 'scripts/joined.test.mjs', + 'scripts/segment.test.mjs', + ]); }); it('covers every record a spec-only change may touch: family, design and theme spec records', () => { @@ -292,6 +312,50 @@ describe('spec readers on this repository (contract)', () => { ).toContain('packages/cli/foundation/discovery/icon-set-checks.test.mjs'); }); + it("each leg lists only its own Vitest project's readers", () => { + const work = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-readers-')); + const git = (...args) => + execFileSync('git', args, {cwd: work, encoding: 'utf8'}); + const write = (file, text) => { + fs.mkdirSync(path.join(work, path.dirname(file)), {recursive: true}); + fs.writeFileSync(path.join(work, file), text); + }; + const list = project => + execFileSync( + process.execPath, + [ + path.join(root, '.github/scripts/fs-guard-tests.mjs'), + '--spec-readers', + '--project', + project, + '--changed', + 'HEAD^1', + ], + {cwd: work, encoding: 'utf8'}, + ) + .trim() + .split('\n'); + try { + git('init', '-q'); + git('config', 'user.email', 'test@example.com'); + git('config', 'user.name', 'test'); + write('vitest.config.ts', read('vitest.config.ts')); + write('docs/specs/AST-1/spec.md', '# Record\n'); + const reader = + "import fs from 'node:fs';\nfs.readFileSync('docs/specs/AST-1/spec.md');\n"; + write('packages/core/src/x.test.ts', reader); + write('scripts/y.test.mjs', reader); + git('add', '-A'); + git('commit', '-qm', 'base'); + write('docs/specs/AST-1/spec.md', '# Record, changed\n'); + git('commit', '-qam', 'change'); + expect(list('ui')).toEqual(['packages/core/src/x.test.ts']); + expect(list('node')).toEqual(['scripts/y.test.mjs']); + } finally { + fs.rmSync(work, {recursive: true, force: true}); + } + }); + it("a renamed record runs the readers of its old name: the lister's diff turns renames off", () => { const work = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-readers-')); const git = (...args) => @@ -381,9 +445,9 @@ describe('spec readers on this repository (contract)', () => { step.name.endsWith(' tests that read a changed record'), ); expect(runner.if).toBe("steps.spec-readers.outputs.any == 'true'"); - expect(runner.run).toContain( - `pnpm ${script} --passWithNoTests "\${READERS[@]}"`, - ); + expect(runner.run).toContain(`pnpm ${script} "\${READERS[@]}"`); + // A run that finds no test fails: the list is this project's own. + expect(runner.run).not.toContain('--passWithNoTests'); // Before the steps a spec-only change skips. expect(steps.indexOf(runner)).toBeLessThan( steps.findIndex( diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4dd1ed6b1cc3d..dfb5bc20d9074 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -757,11 +757,13 @@ jobs: - uses: ./.github/actions/setup if: steps.spec-readers.outputs.any == 'true' + # No --passWithNoTests: the list holds this project's tests only, so a + # run that finds none is a lister fault. - name: Run the UI tests that read a changed record if: steps.spec-readers.outputs.any == 'true' run: | mapfile -t READERS < "$RUNNER_TEMP/spec-readers.txt" - pnpm test:ui --passWithNoTests "${READERS[@]}" + pnpm test:ui "${READERS[@]}" # Two commits: a pull request's merge commit and its base parent, the # diff a scoped run follows. @@ -904,11 +906,13 @@ jobs: - uses: ./.github/actions/setup if: steps.spec-readers.outputs.any == 'true' + # No --passWithNoTests: the list holds this project's tests only, so a + # run that finds none is a lister fault. - name: Run the Node tests that read a changed record if: steps.spec-readers.outputs.any == 'true' run: | mapfile -t READERS < "$RUNNER_TEMP/spec-readers.txt" - pnpm test:node --passWithNoTests "${READERS[@]}" + pnpm test:node "${READERS[@]}" - uses: actions/checkout@v7 if: steps.scope.outputs.docsite_only != 'true' && steps.scope.outputs.spec_only != 'true' From 68d0d61e74a1de791da02fe09e165d7611757e7a Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 1 Nov 2026 20:46:36 -0800 Subject: [PATCH 6/6] ci: spec readers keep glob strings out of comment stripping and cut a glob literal at its first wildcard --- .github/scripts/fs-guard-tests.mjs | 9 +++++++-- .github/scripts/fs-guard-tests.test.mjs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/scripts/fs-guard-tests.mjs b/.github/scripts/fs-guard-tests.mjs index 527059976451a..035d55938c271 100644 --- a/.github/scripts/fs-guard-tests.mjs +++ b/.github/scripts/fs-guard-tests.mjs @@ -209,7 +209,11 @@ const RECORD_PATH = /** The source without block comments and whole-line `//` comments, where prose names records. */ function code(source) { - return source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, ''); + // A comment starts a line or follows whitespace; `/**/` inside a glob + // string (`'docs/specs/**/spec.md'`) does neither. + return source + .replace(/(^|\s)\/\*[\s\S]*?\*\//g, '$1') + .replace(/^\s*\/\/.*$/gm, ''); } /** @@ -232,7 +236,8 @@ function recordPathsIn(file, source, isPath) { const namesSpecFile = /\.spec\.md['"`]/.test(body); const counts = root => root !== 'packages/themes/' || namesSpecFile; for (const [, , literal] of body.matchAll(RECORD_LITERAL)) { - const fixed = literal.split('${')[0]; + // Code or a glob computes the rest: keep the fixed part. + const fixed = literal.split(/\$\{|[*?[{]/)[0]; const joined = fixed.startsWith('.') ? path.posix.normalize(path.posix.join(path.posix.dirname(file), fixed)) : fixed; diff --git a/.github/scripts/fs-guard-tests.test.mjs b/.github/scripts/fs-guard-tests.test.mjs index 105c3e78abdaa..4887143466372 100644 --- a/.github/scripts/fs-guard-tests.test.mjs +++ b/.github/scripts/fs-guard-tests.test.mjs @@ -209,6 +209,11 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' // A computed segment: the prefix ends inside a directory name. 'scripts/segment.test.mjs': "import fs from 'node:fs';\nconst read = n => fs.readFileSync(`docs/specs/AST-${n}/spec.md`, 'utf8');", + // Globs over the tree, with `**` and with `*`. + 'scripts/glob-deep.test.mjs': + "import fs from 'node:fs';\nconst records = fs.globSync('docs/specs/**/spec.md');", + 'scripts/glob-star.test.mjs': + "import fs from 'node:fs';\nconst records = fs.globSync('docs/specs/*/spec.md');", // Names a record as data but reads no files. 'scripts/classify.test.mjs': "const path = 'docs/specs/AST-094-x/spec.md';\nexpect(classify(path)).toBe(true);", @@ -235,6 +240,8 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' 'scripts/contracts.test.mjs', 'scripts/theme-records.test.mjs', 'scripts/segment.test.mjs', + 'scripts/glob-deep.test.mjs', + 'scripts/glob-star.test.mjs', ]); }); @@ -246,6 +253,8 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' 'scripts/any.test.mjs', 'scripts/joined.test.mjs', 'scripts/segment.test.mjs', + 'scripts/glob-deep.test.mjs', + 'scripts/glob-star.test.mjs', ]); expect( specReaderTests(files, read, [ @@ -256,6 +265,8 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' 'scripts/any.test.mjs', 'scripts/joined.test.mjs', 'scripts/segment.test.mjs', + 'scripts/glob-deep.test.mjs', + 'scripts/glob-star.test.mjs', ]); // A record no test names at all still runs the whole-tree readers. expect( @@ -264,6 +275,8 @@ describe('specReaderTests: the tests a spec-only change runs (spec:AST-030 FR2)' 'scripts/any.test.mjs', 'scripts/joined.test.mjs', 'scripts/segment.test.mjs', + 'scripts/glob-deep.test.mjs', + 'scripts/glob-star.test.mjs', ]); });