Skip to content

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

TypeScript

ci: a component's knowledge record alone owns no browser audit (#8467)

Cindy Zhanga17ee0a801e3
diff --git a/.github/scripts/analyze-pr.js b/.github/scripts/analyze-pr.js
index ee2365b36f..c5354a0a8a 100644
--- a/.github/scripts/analyze-pr.js
+++ b/.github/scripts/analyze-pr.js
@@ -27,6 +27,7 @@ const {
flatPackageComponentNames,
nestedPackageComponentNames,
} = require('../../scripts/component-packages.cjs');
+const { isComponentSpecRecordPath } = require('./knowledge-paths.cjs');
const args = process.argv.slice(2);
const getArg = (name) => {
@@ -714,6 +715,9 @@ function analyze() {
for (const file of changedFiles) {
if (!file.startsWith(prefix)) continue;
changedPackages.add(pkg.name);
+ // A component's knowledge record (`<Name>.spec.md`) is never rendered,
+ // so changing it alone owns no browser audit of that component.
+ if (isComponentSpecRecordPath(file)) continue;
const relativePath = file.replace(prefix, '');
const componentName =
diff --git a/.github/scripts/analyze-pr.test.mjs b/.github/scripts/analyze-pr.test.mjs
index 7f9e433add..a8ff24b558 100644
--- a/.github/scripts/analyze-pr.test.mjs
+++ b/.github/scripts/analyze-pr.test.mjs
@@ -68,7 +68,12 @@ function buildFixture() {
git(upstream, ['config', 'user.email', '[email protected]']);
git(upstream, ['config', 'user.name', 'Test']);
fs.writeFileSync(path.join(upstream, 'package.json'), '{}');
- fs.writeFileSync(path.join(upstream, 'packages/core/src/index.ts'), "export {Card} from './Card';\n");
+ fs.mkdirSync(path.join(upstream, 'packages/core/src/Badge'), {recursive: true});
+ fs.writeFileSync(path.join(upstream, 'packages/core/src/index.ts'), "export {Card} from './Card';\nexport {Badge} from './Badge';\n");
+ fs.writeFileSync(path.join(upstream, 'packages/core/src/Badge/Badge.tsx'), 'export function Badge() {}\n');
+ fs.writeFileSync(path.join(upstream, 'packages/core/src/Badge/Badge.doc.mjs'), "export default {name: 'Badge'};\n");
+ fs.writeFileSync(path.join(upstream, 'packages/core/src/Badge/index.ts'), "export {Badge} from './Badge';\n");
+ fs.writeFileSync(path.join(upstream, 'packages/core/src/Badge/Badge.spec.md'), '---\nschema_version: 3\n---\n');
fs.writeFileSync(path.join(upstream, 'packages/core/src/Card/Card.tsx'), 'export function Card() {}\n');
fs.writeFileSync(path.join(upstream, 'packages/core/src/Card/Card.doc.mjs'), "export default {name: 'Card'};\n");
fs.writeFileSync(path.join(upstream, 'packages/core/src/Card/index.ts'), "export {Card} from './Card';\n");
@@ -128,6 +133,8 @@ function buildFixture() {
git(upstream, ['branch', 'feature', branchPoint]);
git(upstream, ['checkout', '-q', 'feature']);
fs.appendFileSync(path.join(upstream, 'packages/core/src/Card/index.ts'), 'export const Card = {}\n');
+ // Only Badge's knowledge record changes: no browser audit owns Badge.
+ fs.appendFileSync(path.join(upstream, 'packages/core/src/Badge/Badge.spec.md'), 'record text\n');
fs.appendFileSync(
path.join(upstream, 'packages/richtext/src/RichTextEditor.tsx'),
'export const richTextChanged = true\n',
@@ -194,6 +201,8 @@ describe('analyze-pr shallow-clone recovery', () => {
'richtext/RichTextView',
'vega/VegaChart',
]);
+ expect(analysis.modifiedComponentOwners).not.toContain('core/Badge');
+ expect(analysis.unresolvedComponentSources).not.toContain('core/Badge');
expect(analysis.modifiedComponentOwners).not.toContain('core/InteractiveRoleContext');
expect(analysis.modifiedComponentOwners).not.toContain('lab/Sankey');
expect(analysis.forceFullComponentAudits).toBe(true);
diff --git a/.github/scripts/component-audit-scope.cjs b/.github/scripts/component-audit-scope.cjs
index 51f60cd167..a06ccfad21 100644
--- a/.github/scripts/component-audit-scope.cjs
+++ b/.github/scripts/component-audit-scope.cjs
@@ -9,11 +9,14 @@
* @input Git name-status rows on stdin and --registry <trusted-base registry>.
* @output GitHub job outputs for component, RTL, and fail-closed full-audit scope;
* empty or unmatched input always selects the full audits.
- * @position Loaded with its registry from the pull request's trusted base ref.
+ * @position Loaded with its registry and knowledge-paths.cjs from the pull
+ * request's trusted base ref.
*/
const fs = require('node:fs');
const path = require('node:path');
+// Loaded beside this file from the same trusted base ref.
+const {isComponentSpecRecordPath} = require('./knowledge-paths.cjs');
function changedPathsFromNameStatus(input) {
return input
@@ -25,8 +28,11 @@ function changedPathsFromNameStatus(input) {
function classifyComponentAuditScope(paths, componentPackages) {
const sourceRoots = componentPackages.map(pkg => `${pkg.src}/`);
+ // A component's knowledge record (`<Name>.spec.md`) is never rendered, so
+ // neither browser audit can observe it, as the PR analysis also holds.
+ const isComponentRecord = file => isComponentSpecRecordPath(file);
const isComponentSource = file =>
- sourceRoots.some(root => file.startsWith(root));
+ sourceRoots.some(root => file.startsWith(root)) && !isComponentRecord(file);
const isStory = file => file.startsWith('apps/storybook/stories/');
const isAccessibilitySurface = file =>
file.startsWith('internal/a11y-spec/') ||
@@ -40,6 +46,7 @@ function classifyComponentAuditScope(paths, componentPackages) {
// These are positively owned surfaces that neither component browser audit
// can observe. Keep this list narrow: unmatched paths still fail closed.
const isKnownNonComponentSurface = file =>
+ isComponentRecord(file) ||
file.startsWith('.changeset/') ||
file.startsWith('apps/sandbox/') ||
file.startsWith('packages/cli/') ||
diff --git a/.github/scripts/component-audit-scope.test.mjs b/.github/scripts/component-audit-scope.test.mjs
index 83273bbc45..10f1f3bc9f 100644
--- a/.github/scripts/component-audit-scope.test.mjs
+++ b/.github/scripts/component-audit-scope.test.mjs
@@ -41,6 +41,9 @@ describe('component audit scope', () => {
expect(workflow).toContain(
'origin/${{ github.base_ref }}:scripts/component-packages.cjs',
);
+ expect(workflow).toContain(
+ 'origin/${{ github.base_ref }}:.github/scripts/knowledge-paths.cjs',
+ );
expect(workflow).toContain('force_full_component_audits=true');
});
@@ -101,6 +104,34 @@ describe('component audit scope', () => {
).toEqual(NO_COMPONENT_AUDIT_SCOPE);
});
+ it('skips component audits for knowledge records beside a known non-component surface', () => {
+ expect(
+ classifyComponentAuditScope(
+ [
+ 'packages/core/src/Button/Button.spec.md',
+ 'packages/cli/api/theme/build/build.mjs',
+ ],
+ COMPONENT_PACKAGES,
+ ),
+ ).toEqual(NO_COMPONENT_AUDIT_SCOPE);
+ });
+
+ it('still audits a component whose record changes beside its code', () => {
+ expect(
+ classifyComponentAuditScope(
+ [
+ 'packages/core/src/Button/Button.spec.md',
+ 'packages/core/src/Button/Button.tsx',
+ ],
+ COMPONENT_PACKAGES,
+ ),
+ ).toMatchObject({
+ has_components: true,
+ has_rtl_components: true,
+ force_full_component_audits: false,
+ });
+ });
+
it('keeps root scripts on full component audits', () => {
expect(
classifyComponentAuditScope(['scripts/build-css.mjs'], COMPONENT_PACKAGES),
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a462cbf7e9..ad2191efe0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -573,6 +573,7 @@ jobs:
SCOPE="$POLICY_ROOT/.github/scripts/component-audit-scope.cjs"
REGISTRY="$POLICY_ROOT/scripts/component-packages.cjs"
if git show "origin/${{ github.base_ref }}:.github/scripts/component-audit-scope.cjs" > "$SCOPE" 2>/dev/null \
+ && git show "origin/${{ github.base_ref }}:.github/scripts/knowledge-paths.cjs" > "$POLICY_ROOT/.github/scripts/knowledge-paths.cjs" 2>/dev/null \
&& git show "origin/${{ github.base_ref }}:scripts/component-packages.cjs" > "$REGISTRY" 2>/dev/null; then
git diff --name-status "$MERGE_BASE"...HEAD \
| node "$SCOPE" --registry "$REGISTRY" --github-output