An open source design system that's fully customizable and agent ready
TypeScript
ci: a spec-only pull request runs the tests that read a record it changes (AST-030 FR2) (#9446)
Cindy Zhang358c2c569d49
diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjsindex 1f6daf4f60..b8414b76d0 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 <root script>` 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.@@ -255,8 +262,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(@@ -343,8 +352,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.mjsindex f9a19c09db..035d55938c 100644--- a/.github/scripts/fs-guard-tests.mjs+++ b/.github/scripts/fs-guard-tests.mjs@@ -17,7 +17,13 @@// 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 <ref>]+// - With `--spec-readers --changed <ref>`: instead, the tests that read a+// 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). `--project ui|node` keeps one Vitest project's.+//+// Usage: node .github/scripts/fs-guard-tests.mjs [--spec-readers [--project ui|node]] [--changed <ref>]// (newline-separated paths)import {execFileSync} from 'node:child_process';@@ -181,6 +187,170 @@ export function scopedExtraTests(files, read, changedFiles = []) {return files.filter(file => guards.has(file));}+/**+ * 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) {+ // 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, '');+}++/**+ * The record paths a file names in its code, as repository paths: an exact+ * 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, isPath) {+ const body = code(source);+ const paths = new Set();+ // 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)) {+ // 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;+ const root = RECORD_ROOTS.find(+ prefix => joined === prefix.slice(0, -1) || joined.startsWith(prefix),+ );+ 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}/`;+ if (RECORD_ROOTS.includes(root) && counts(root)) paths.add(root);+ }+ return paths;+}++/**+ * 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+ * @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 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);+ 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 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);+ 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 => RECORD_PATH.test(file));+ 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',@@ -188,18 +358,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 = 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.mjsindex 9d16d86adb..4887143466 100644--- a/.github/scripts/fs-guard-tests.test.mjs+++ b/.github/scripts/fs-guard-tests.test.mjs@@ -6,7 +6,14 @@ 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,+ uiTestRoots,+} from './fs-guard-tests.mjs';+import os from 'node:os';+import yaml from 'yaml';const sources = {'packages/core/src/Button/Button.test.tsx':@@ -170,3 +177,298 @@ 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 {};",+ // 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');",+ // 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);",+ };+ // 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([+ 'packages/core/src/motion/roles.test.ts',+ 'scripts/components.test.mjs',+ 'scripts/any.test.mjs',+ 'scripts/joined.test.mjs',+ 'scripts/contracts.test.mjs',+ 'scripts/theme-records.test.mjs',+ 'scripts/segment.test.mjs',+ 'scripts/glob-deep.test.mjs',+ 'scripts/glob-star.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',+ 'scripts/segment.test.mjs',+ 'scripts/glob-deep.test.mjs',+ 'scripts/glob-star.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',+ '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(+ specReaderTests(files, read, ['docs/specs/AST-001/spec.md']),+ ).toEqual([+ 'scripts/any.test.mjs',+ 'scripts/joined.test.mjs',+ 'scripts/segment.test.mjs',+ 'scripts/glob-deep.test.mjs',+ 'scripts/glob-star.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(+ [],+ );+ });+});++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');+ });++ 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', '[email protected]');+ 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) =>+ 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', '[email protected]');+ 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', 'ui'],+ ['test-node', 'test:node', 'node'],+ ])(+ "%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 =+ "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 --project ${project} --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} "\${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(+ step =>+ step.uses === 'actions/checkout@v7' &&+ String(step.if).includes("spec_only != 'true'"),+ ),+ );+ },+ );+});diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 6bc38433d2..4e9be9fc35 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -742,6 +742,41 @@ 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 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+ 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 --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"+ else+ echo 'any=false' >> "$GITHUB_OUTPUT"+ fi++ - 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 "${READERS[@]}"+# Two commits: a pull request's merge commit and its base parent, the# diff a scoped run follows.- uses: actions/checkout@v7@@ -867,6 +902,41 @@ 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 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+ 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 --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"+ else+ echo 'any=false' >> "$GITHUB_OUTPUT"+ fi++ - 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 "${READERS[@]}"+- uses: actions/checkout@v7if: steps.scope.outputs.docsite_only != 'true' && steps.scope.outputs.spec_only != 'true'with:diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.mdindex 213e535c80..8881f00f36 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 initialtaxonomy 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:<package>` | 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:<package>` | 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,@@ -543,7 +543,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 |