Skip to content

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

TypeScript

fix(rtl-audit): story identities with no public component are not roster entries (#9302)

Cindy Zhangb35ac9d716ad
diff --git a/.github/scripts/rtl-audit-coverage.test.mjs b/.github/scripts/rtl-audit-coverage.test.mjs
index 7cb7ccfdad..3839075b6b 100644
--- a/.github/scripts/rtl-audit-coverage.test.mjs
+++ b/.github/scripts/rtl-audit-coverage.test.mjs
@@ -29,6 +29,7 @@ import {
finishFiniteAnimations,
gradeDirectionalPair,
gradePositionedPair,
+ ignoredStoryIdentities,
orderD1StoryCandidates,
resolveD1Applicability,
resolveFilterRoutes,
@@ -614,6 +615,87 @@ describe('buildAuditedComponentRoster', () => {
).toEqual(['core/chat']);
});
+ it('leaves out a story identity that names no public component', () => {
+ const input = {
+ sourceComponents: ['core/Button', 'core/Table'],
+ storyComponents: [
+ 'core/button',
+ 'core/hooks-useclipboard',
+ 'core/tablesortable',
+ ],
+ };
+ // A public component keeps its entry (the story spelling, as before).
+ expect(buildAuditedComponentRoster(input)).toEqual([
+ 'core/button',
+ 'core/Table',
+ ]);
+ expect(ignoredStoryIdentities(input)).toEqual([
+ {component: 'core/hooks-useclipboard', reason: 'no-public-component'},
+ {component: 'core/tablesortable', reason: 'no-public-component'},
+ ]);
+ });
+
+ it('keeps a documented component discovery misses, whatever its story is titled', () => {
+ // The caller passes Core's Theme and MediaTheme as package-qualified
+ // public components; a retitled or missing story cannot drop them.
+ const input = {
+ sourceComponents: [
+ 'core/Button',
+ 'core/Theme',
+ 'core/MediaTheme',
+ 'lab/CodeEditor',
+ ],
+ storyComponents: [
+ 'core/button',
+ 'core/appearance-theming',
+ 'lab/codeeditor',
+ 'lab/themes-codeeditortheme',
+ ],
+ };
+ expect(buildAuditedComponentRoster(input)).toEqual([
+ 'core/button',
+ 'core/Theme',
+ 'core/MediaTheme',
+ 'lab/codeeditor',
+ ]);
+ // Core's Theme no longer keeps a Lab story identity that ends in "theme".
+ expect(ignoredStoryIdentities(input)).toEqual([
+ {component: 'core/appearance-theming', reason: 'no-public-component'},
+ {component: 'lab/themes-codeeditortheme', reason: 'no-public-component'},
+ ]);
+ });
+
+ it('ignores nothing in a package whose public roster is empty', () => {
+ const input = {
+ sourceComponents: ['core/Button'],
+ storyComponents: ['core/button', 'lab/chart-interactions'],
+ };
+ expect(ignoredStoryIdentities(input)).toEqual([]);
+ expect(buildAuditedComponentRoster(input)).toEqual([
+ 'core/button',
+ 'lab/chart-interactions',
+ ]);
+ });
+
+ it('keeps a public component with no story as a roster entry', () => {
+ expect(
+ buildAuditedComponentRoster({
+ sourceComponents: ['core/Button', 'core/LayerProvider'],
+ storyComponents: ['core/button'],
+ }),
+ ).toEqual(['core/button', 'core/LayerProvider']);
+ });
+
+ it('keeps a story identity a filter names explicitly', () => {
+ const input = {
+ sourceComponents: ['core/ChatComposer'],
+ storyComponents: ['core/chat'],
+ filters: ['chat'],
+ };
+ expect(buildAuditedComponentRoster(input)).toEqual(['core/chat']);
+ expect(ignoredStoryIdentities(input)).toEqual([]);
+ });
+
it('retains an unknown entry when neither source nor stories match', () => {
expect(
buildAuditedComponentRoster({
@@ -625,6 +707,25 @@ describe('buildAuditedComponentRoster', () => {
});
});
+describe('documented components outside component directories', () => {
+ it('routes a Core/Themes/Theme story to the documented Theme component', () => {
+ const routes = buildStoryComponentRoutes({
+ stories: [{id: 'core-themes-theme--default', title: 'Core/Themes/Theme'}],
+ publicComponentsByPackage: {core: ['Button', 'Theme']},
+ });
+ expect(routes.map(route => route.component)).toEqual(['core/Theme']);
+ });
+
+ it('finds Core Theme-family exports that live in a lowercase directory', () => {
+ const names =
+ componentPackages.documentedComponentsOutsideComponentDirectories(
+ new URL('../..', import.meta.url).pathname,
+ componentPackages.componentPackage('core'),
+ );
+ expect(names).toEqual(expect.arrayContaining(['MediaTheme', 'Theme']));
+ });
+});
+
describe('audited package and story routing', () => {
const publicComponentsByPackage = Object.fromEntries(
AUDITED_PACKAGE_NAMES.map(packageName => {
diff --git a/apps/storybook/rtl-audit/rtl-audit-coverage.mjs b/apps/storybook/rtl-audit/rtl-audit-coverage.mjs
index 27e742c8ab..077dba2d32 100644
--- a/apps/storybook/rtl-audit/rtl-audit-coverage.mjs
+++ b/apps/storybook/rtl-audit/rtl-audit-coverage.mjs
@@ -1071,14 +1071,61 @@ function componentName(component) {
}
/**
- * Build the component roster for a scoped audit.
+ * Story-title identities that name no public component, such as
+ * `core/hooks-useclipboard` or `core/tablesortable`. The roster is the public
+ * components (`architecture:rtl-audit-evidence` INV5), so these are not roster
+ * entries and cannot be coverage gaps; the audit reports them, typed, rather
+ * than dropping them silently.
+ *
+ * Public components are `sourceComponents`, package-qualified. The caller
+ * includes documented exports that directory discovery misses (Core's `Theme`
+ * and `MediaTheme`), so they stay roster entries whatever their stories are
+ * titled. It fails closed. An identity stays a roster entry when:
+ * - a filter names it explicitly (an umbrella surface such as `Core/Chat`);
+ * - its package has no discovered public component at all, so a discovery
+ * failure cannot hide that package's gaps.
+ */
+export function ignoredStoryIdentities({
+ sourceComponents = [],
+ storyComponents = [],
+ filters = [],
+}) {
+ const publicKeys = new Set(sourceComponents.map(c => c.toLowerCase()));
+ const packagesWithPublic = new Set(
+ sourceComponents.map(c => c.split('/')[0].toLowerCase()),
+ );
+ const normalizedFilters = filters.map(filter => filter.toLowerCase());
+ const named = component =>
+ normalizedFilters.some(
+ filter =>
+ component.toLowerCase() === filter ||
+ componentName(component) === filter,
+ );
+ const ignorable = component =>
+ !publicKeys.has(component.toLowerCase()) &&
+ packagesWithPublic.has(component.split('/')[0].toLowerCase()) &&
+ !named(component);
+ return Array.from(
+ new Map(
+ storyComponents.filter(ignorable).map(c => [c.toLowerCase(), c]),
+ ).values(),
+ )
+ .sort((left, right) => left.localeCompare(right))
+ .map(component => ({component, reason: 'no-public-component'}));
+}
+
+/**
+ * Build the component roster for a scoped audit: the public components, plus
+ * any story identity a filter names explicitly.
*
* Storybook can expose an umbrella story whose name matches the PR analyzer's
* module name even when no source component has that exact name. Chat is the
* canonical example: the source directory contains ChatComposer, ChatMessage,
* and related components, while Storybook also has a `Core/Chat` surface. A
* matching story must satisfy the filter so the roster does not invent a
- * second `unknown/chat` coverage entry for the same surface.
+ * second `unknown/chat` coverage entry for the same surface. Story identities
+ * with no public component and no filter naming them are left out (see
+ * `ignoredStoryIdentities`).
*/
export function buildAuditedComponentRoster({
sourceComponents = [],
@@ -1095,13 +1142,19 @@ export function buildAuditedComponentRoster({
!knownComponents.some(component => matchesFilter(component, filter)),
)
.map(filter => `unknown/${filter}`);
+ const ignored = new Set(
+ ignoredStoryIdentities({
+ sourceComponents,
+ storyComponents,
+ filters,
+ }).map(entry => entry.component.toLowerCase()),
+ );
return Array.from(
new Map(
- [...knownComponents, ...unmatchedFilters].map(component => [
- component.toLowerCase(),
- component,
- ]),
+ [...knownComponents, ...unmatchedFilters]
+ .filter(component => !ignored.has(component.toLowerCase()))
+ .map(component => [component.toLowerCase(), component]),
).values(),
).filter(
component =>
diff --git a/apps/storybook/rtl-audit/rtl-audit.mjs b/apps/storybook/rtl-audit/rtl-audit.mjs
index 1b718203ba..64d118e6b9 100644
--- a/apps/storybook/rtl-audit/rtl-audit.mjs
+++ b/apps/storybook/rtl-audit/rtl-audit.mjs
@@ -75,6 +75,7 @@ import {
glyphRendersOnBlockAxis,
gradeDirectionalPair,
gradePositionedPair,
+ ignoredStoryIdentities,
isUnchangedBlockAxisPair,
orderD1StoryCandidates,
resolveD1Applicability,
@@ -99,6 +100,7 @@ import {
const {
componentExportsFromBarrel,
componentPackage,
+ documentedComponentsOutsideComponentDirectories,
flatPackageComponentNames,
nestedPackageComponentNames,
} = componentPackages;
@@ -1366,9 +1368,15 @@ async function cleanupRuntime() {
try {
const pkg = componentPackage(packageName);
if (!pkg) throw new Error('package is missing from component registry');
+ // Documented exports outside component directories (Core's Theme
+ // family) are public too (INV5): they get roster entries and route
+ // their stories.
const componentNames = pkg.layout === 'flat'
? flatPackageComponentNames(PROJECT_ROOT, pkg)
- : nestedPackageComponentNames(PROJECT_ROOT, pkg);
+ : Array.from(new Set([
+ ...nestedPackageComponentNames(PROJECT_ROOT, pkg),
+ ...documentedComponentsOutsideComponentDirectories(PROJECT_ROOT, pkg),
+ ])).sort();
publicComponentsByPackage[packageName] = componentNames;
if (ACTIVE_PACKAGE_NAMES.includes(packageName)) {
sourceComponents.push(
@@ -1644,6 +1652,13 @@ async function cleanupRuntime() {
enforced: !AUTO_ONLY && !CURATED_ONLY,
});
if (verifiedNaError) coverage.registryError = verifiedNaError;
+ // Story identities with no public component are not roster entries (INV5);
+ // name them so the report shows what the roster left out.
+ coverage.ignoredStoryIdentities = ignoredStoryIdentities({
+ sourceComponents,
+ storyComponents: scopedStoryRoutes.map(route => route.component),
+ filters: FILTER,
+ });
const autoFails = autoResults.filter(r => r.verdict === 'fail' || r.verdict === 'ERROR');
// No allowlist: every not-RTL component is a surprise. The RTL migration is
@@ -1738,6 +1753,7 @@ async function cleanupRuntime() {
console.error(`DEC : ${report.directionalDecorations.pass} pass / ${report.directionalDecorations.fail} fail / ${report.directionalDecorations.na} N-A`);
console.error(`POOL: ${pageRecoveries.length} page replacement(s) after a failed story`);
console.error(`COV : ${coverage.measured} measured / ${coverage.verifiedNa} verified N-A / ${coverage.gaps} gap / ${coverage.staleVerifiedNa} stale`);
+ if (coverage.ignoredStoryIdentities.length > 0) console.error(`IGN : ${coverage.ignoredStoryIdentities.length} story identities name no public component (not roster entries): ${coverage.ignoredStoryIdentities.map(entry => entry.component).join(', ')}`);
if (declaredD5PhysicalRegions.length > 0) console.error(`D5P : ${declaredD5PhysicalRegions.length} declared physical region(s): ${declaredD5PhysicalRegions.map(r => `${r.storyId} (${r.physical} within ${r.within})`).join('; ')}`);
// Non-zero exit only signals CI (which is soft/continue-on-error). Surface a
// signal but never let it hard-block during the stability window.
diff --git a/scripts/component-packages.cjs b/scripts/component-packages.cjs
index 99cd885cdc..5a9be64456 100644
--- a/scripts/component-packages.cjs
+++ b/scripts/component-packages.cjs
@@ -239,6 +239,37 @@ function nestedPackageComponentNames(repoRoot, packageConfig) {
.sort();
}
+/**
+ * Documented, exported components that live outside PascalCase directories in
+ * a nested package (Core's `theme/` holds Theme, MediaTheme and SyntaxTheme;
+ * `i18n/` holds InternationalizationProvider), which
+ * `nestedPackageComponentNames` does not reach. Flat packages have none.
+ */
+function documentedComponentsOutsideComponentDirectories(
+ repoRoot,
+ packageConfig,
+) {
+ if (packageConfig.layout === 'flat') return [];
+ const sourceDir = path.join(repoRoot, packageConfig.src);
+ let entries;
+ try {
+ entries = fs.readdirSync(sourceDir, {withFileTypes: true});
+ } catch {
+ return [];
+ }
+ const exported = new Set(exportedComponentNames(sourceDir));
+ const names = new Set();
+ for (const entry of entries) {
+ if (!entry.isDirectory() || COMPONENT_NAME.test(entry.name)) continue;
+ for (const name of documentedComponentNames(
+ path.join(sourceDir, entry.name),
+ )) {
+ if (exported.has(name)) names.add(name);
+ }
+ }
+ return [...names].sort();
+}
+
function packageHasPublicComponent(repoRoot, packageName, componentName) {
const packageConfig = componentPackage(packageName);
if (!packageConfig) return false;
@@ -255,6 +286,7 @@ module.exports = {
componentExportsFromBarrel,
componentPackage,
documentedComponentNames,
+ documentedComponentsOutsideComponentDirectories,
documentedNestedComponentNames,
exportedComponentNames,
flatPackageComponentNames,