An open source design system that's fully customizable and agent ready
TypeScript
ci(rtl): audit Core RTL in three parts and join them (#7419)
Cindy Zhang302fcd28d756
diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjsindex 5be0e595c7..7a271c2823 100644--- a/.github/scripts/ci-test-routing.test.mjs+++ b/.github/scripts/ci-test-routing.test.mjs@@ -281,7 +281,18 @@ describe('ci.yml RTL package sharding', () => {});it('runs one bounded shard for every canonical component package', () => {- expect(shard.strategy.matrix.package).toEqual([...COMPONENT_PACKAGE_NAMES]);+ const legs = shard.strategy.matrix.include;+ expect([...new Set(legs.map(leg => leg.package))]).toEqual([+ ...COMPONENT_PACKAGE_NAMES,+ ]);+ // Each package's parts are numbered 1..parts exactly once.+ for (const name of COMPONENT_PACKAGE_NAMES) {+ const parts = legs.filter(leg => leg.package === name);+ expect(parts.map(leg => leg.part)).toEqual(+ Array.from({length: parts[0].parts}, (_, index) => index + 1),+ );+ expect(new Set(parts.map(leg => leg.parts)).size).toBe(1);+ }expect(shard['runs-on']).toBe('4-core-ubuntu');expect(shard['timeout-minutes']).toBeLessThanOrEqual(30);expect(shard['continue-on-error']).not.toBe(true);@@ -336,14 +347,57 @@ describe('ci.yml RTL package sharding', () => {});it('publishes a distinct scope manifest and optional report for each shard', () => {- const upload = shard.steps.find(step =>- step.uses?.startsWith('actions/upload-artifact@'),+ const upload = shard.steps.find(+ step => step.name === 'Upload RTL shard evidence',);- expect(upload.if).toBe('always()');+ expect(upload.if).toBe('always() && matrix.parts == 1');expect(upload.with.name).toBe('rtl-audit-report-${{ matrix.package }}');expect(upload.with.path).toContain('rtl-shard-scope.json');expect(upload.with.path).toContain('rtl-audit-report.json');expect(upload.with['if-no-files-found']).toBe('error');+ const part = shard.steps.find(step => step.name === 'Upload RTL part');+ expect(part.if).toBe('always() && matrix.parts > 1');+ expect(part.with.name).toBe(+ 'rtl-audit-part-${{ matrix.package }}-${{ matrix.part }}',+ );+ expect(part.with['if-no-files-found']).toBe('error');+ });++ it('joins split packages into the report a whole leg would upload', () => {+ const merge = workflow.jobs['pr-rtl-merge'];+ expect(merge.needs).toContain('pr-rtl-shard');+ expect(merge.if).toContain('always()');+ const commands = runLines(merge);+ expect(commands).toContain('--merge-shards rtl-parts');+ expect(commands).toContain('.github/scripts/rtl-report-completion.mjs');+ expect(commands).toContain(+ 'case "$code" in 0|1) ;; *) exit "$code" ;; esac',+ );+ const upload = merge.steps.find(+ step => step.name === 'Upload RTL shard evidence',+ );+ expect(upload.with.name).toBe('rtl-audit-report-core');+ expect(upload.with['if-no-files-found']).toBe('error');+ expect(join.needs).toContain('pr-rtl-merge');+ // The join's --shards value: the shared result when the parts and the+ // merge agree (success, or both skipped on an out-of-scope PR), and both+ // results otherwise, which rtl-join.mjs rejects.+ const expression = /--shards "\$\{\{(.*?)\}\}"/.exec(runLines(join))[1];+ const render = (shards, merge) =>+ new Function(+ 'S',+ 'M',+ `return ${expression+ .replaceAll('needs.pr-rtl-shard.result', 'S')+ .replaceAll('needs.pr-rtl-merge.result', 'M')+ .replaceAll('==', '===')+ .replace("format('{0}/{1}', S, M)", '`${S}/${M}`')};`,+ )(shards, merge);+ expect(render('success', 'success')).toBe('success');+ expect(render('skipped', 'skipped')).toBe('skipped');+ expect(render('success', 'failure')).toBe('success/failure');+ expect(render('failure', 'skipped')).toBe('failure/skipped');+ expect(render('failure', 'failure')).toBe('failure');});});diff --git a/.github/scripts/release-check-workflow.test.mjs b/.github/scripts/release-check-workflow.test.mjsindex 8e60df1f17..01f57172ee 100644--- a/.github/scripts/release-check-workflow.test.mjs+++ b/.github/scripts/release-check-workflow.test.mjs@@ -30,6 +30,7 @@ const releaseJobs = ['pr-a11y','a11y-contracts','pr-rtl-shard',+ 'pr-rtl-merge','pr-rtl','release-check',];@@ -700,13 +701,11 @@ describe('full release scope without PR metadata or maintenance writes', () => {});it('keeps all canonical RTL packages and passes full scope to resolver and join', () => {- expect(jobs['pr-rtl-shard'].strategy.matrix.package).toEqual([- 'core',- 'lab',- 'charts',- 'richtext',- 'vega',- ]);+ expect([+ ...new Set(+ jobs['pr-rtl-shard'].strategy.matrix.include.map(leg => leg.package),+ ),+ ]).toEqual(['core', 'lab', 'charts', 'richtext', 'vega']);expect(step('pr-rtl-shard', 'Resolve RTL shard scope').run).toContain('--force-full "${{ needs.check-components.outputs.force_full_component_audits }}"',);diff --git a/.github/scripts/rtl-audit-shards.test.mjs b/.github/scripts/rtl-audit-shards.test.mjsnew file mode 100644index 0000000000..4b8c9d511e--- /dev/null+++ b/.github/scripts/rtl-audit-shards.test.mjs@@ -0,0 +1,134 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, expect, it} from 'vitest';+import {+ mergeRtlShards,+ parseShard,+ shardFile,+ shardPositions,+} from '../../apps/storybook/rtl-audit/rtl-audit-shards.mjs';++const plan = {+ d1: ['Button::core-button--a', 'Card::core-card--a', 'Chat::core-chat--a'],+ stories: [+ 'Button::core-button--a',+ 'Button::core-button--b',+ 'Card::core-card--a',+ 'Chat::core-chat--a',+ 'Chat::core-chat--b',+ ],+ curated: ['Carousel::core-carousel--a', 'Slider::core-slider--a'],+};+const card = (part, position) => ({part, position});+const contract = {ok: true};++function shards(count, {storybookSha = 'abc', withPlan = plan} = {}) {+ return Array.from({length: count}, (_, offset) => {+ const shard = {index: offset + 1, count};+ const cards = Object.fromEntries(+ ['d1', 'stories', 'curated'].map(part => [+ part,+ new Map(+ shardPositions(withPlan[part].length, shard).map(position => [+ position,+ card(part, position),+ ]),+ ),+ ]),+ );+ return {+ file: `rtl-shard-${shard.index}.json`,+ content: JSON.parse(+ JSON.stringify(+ shardFile({+ plan: withPlan,+ shard,+ storybookSha,+ cards,+ d8BrowserContract: contract,+ pageRecoveries: [{storyId: `recovered-${shard.index}`}],+ }),+ ),+ ),+ };+ });+}++describe('RTL audit shards', () => {+ it('parses index/count and refuses anything else', () => {+ expect(parseShard('2/3')).toEqual({index: 2, count: 3});+ for (const bad of [null, '', '0/3', '4/3', '1/0', 'x']) {+ expect(() => parseShard(bad), String(bad)).toThrow(/--shard/);+ }+ });++ it('gives every plan position to exactly one shard', () => {+ const owned = [1, 2, 3].flatMap(index =>+ shardPositions(5, {index, count: 3}),+ );+ expect(owned.sort()).toEqual([0, 1, 2, 3, 4]);+ });++ it('joins a complete set back into plan order', () => {+ const merged = mergeRtlShards(shards(3).reverse(), {+ plan,+ storybookSha: 'abc',+ });+ for (const part of ['d1', 'stories', 'curated']) {+ expect(merged[part]).toEqual(+ plan[part].map((_, position) => card(part, position)),+ );+ }+ expect(merged.d8BrowserContract).toEqual(contract);+ expect(merged.pageRecoveries.map(entry => entry.storyId)).toEqual([+ 'recovered-1',+ 'recovered-2',+ 'recovered-3',+ ]);+ });++ it('refuses a missing or duplicated shard', () => {+ const set = shards(3);+ expect(() =>+ mergeRtlShards(set.slice(1), {plan, storybookSha: 'abc'}),+ ).toThrow(/incomplete/);+ expect(() =>+ mergeRtlShards([set[0], set[1], set[1]], {plan, storybookSha: 'abc'}),+ ).toThrow(/twice/);+ expect(() => mergeRtlShards([], {plan, storybookSha: 'abc'})).toThrow(+ /No RTL shard files/,+ );+ });++ it('refuses shards of another plan or another build', () => {+ const otherPlan = {...plan, curated: plan.curated.slice(1)};+ expect(() =>+ mergeRtlShards(shards(2, {withPlan: otherPlan}), {+ plan,+ storybookSha: 'abc',+ }),+ ).toThrow(/different plan/);+ expect(() =>+ mergeRtlShards(shards(2, {storybookSha: 'zzz'}), {+ plan,+ storybookSha: 'abc',+ }),+ ).toThrow(/Storybook/);+ });++ it('refuses a shard missing one of its cards', () => {+ const set = shards(2);+ delete set[1].content.cards.stories['1'];+ expect(() => mergeRtlShards(set, {plan, storybookSha: 'abc'})).toThrow(+ /exactly the stories items of shard 2\/2/,+ );+ });++ it('refuses shards that disagree on the D8 self-check', () => {+ const set = shards(2);+ set[1].content.d8BrowserContract = {ok: false};+ expect(() => mergeRtlShards(set, {plan, storybookSha: 'abc'})).toThrow(+ /D8/,+ );+ });+});diff --git a/.github/scripts/rtl-scorecard-summary.mjs b/.github/scripts/rtl-scorecard-summary.mjsnew file mode 100644index 0000000000..8940c741a1--- /dev/null+++ b/.github/scripts/rtl-scorecard-summary.mjs@@ -0,0 +1,164 @@+#!/usr/bin/env node+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Markdown scorecard for one package's RTL audit report.+ * @input --report <rtl-audit-report.json> --scope <audited components label>+ * @output The job-summary section, on stdout.+ * @position Shared by the pr-rtl package legs and the sharded-package merge+ * job, so a joined report reads exactly like a single run's.+ */++import fs from 'node:fs';++const args = process.argv.slice(2);+const arg = name => {+ const index = args.indexOf(`--${name}`);+ return index === -1 ? null : args[index + 1];+};+const reportPath = arg('report') ?? 'rtl-audit-report.json';+const scope = arg('scope') ?? '';++const lines = [+ '## RTL semantic audit',+ '',+ `Audit scope: **${scope}**. The scheduled unfiltered sweep also runs weekly — see \`rtl-weekly.yml\`.`,+ '',+ 'Relationship-based (LTR vs RTL in the same run) — no golden screenshots. **Soft-gated** pending a stability window.',+ '',+];+if (!fs.existsSync(reportPath)) {+ lines.push('_No report produced — audit errored before writing output._');+} else {+ const r = JSON.parse(fs.readFileSync(reportPath, 'utf8'));+ const a = r.autoDiscovery;+ const known = new Set(r.knownNotRtl || []);+ const out = [];+ out.push(+ '### Auto-discovery (D1 icon-mirror, one representative story per scoped component)',+ );+ out.push('');+ out.push(+ `**${a.pass} pass · ${a.fail} not-RTL · ${a.na} N-A** (of ${a.total} scoped components). Surprises (not pre-labelled): **${a.surprises.length}**${a.surprises.length ? ': ' + a.surprises.join(', ') : ''}.`,+ );+ out.push('');+ const fails = a.results.filter(+ x => x.verdict === 'fail' || x.verdict === 'ERROR',+ );+ if (fails.length) {+ out.push('| Component | D1 | Label | Detail |');+ out.push('|-----------|----|-------|--------|');+ for (const c of fails) {+ const label = known.has(c.component) ? 'known-not-rtl' : '⚠️ surprise';+ out.push(+ `| ${c.component} | ${c.verdict} | ${label} | ${(c.notes || []).join('; ')} |`,+ );+ }+ } else {+ out.push('_No not-RTL findings._');+ }+ out.push('');+ const passes = a.results+ .filter(x => x.verdict === 'pass')+ .map(x => x.component);+ out.push(`RTL-ready (D1 pass): ${passes.join(', ') || '—'}.`);+ out.push('');+ const pm = r.positionalMirror;+ if (pm) {+ out.push('### Positional-mirror (D5, all scoped stories)');+ out.push('');+ out.push(+ 'Catches a logical anchor (insetInlineStart/End) paired with an UNFLIPPED physical transform (translate/translateX) → element lands on the wrong side in RTL. Lint can\u2019t see this (each prop is individually fine). Tolerance ' ++ pm.tolerancePx ++ 'px, degenerate-parent guard (<8px) applied.',+ );+ out.push('');+ out.push(+ `**${pm.pass} pass · ${pm.fail} FAIL · ${pm.na} N-A** (of ${pm.total} scoped stories scanned).`,+ );+ out.push('');+ const pmFails = pm.results.filter(+ x => x.verdict === 'fail' || x.verdict === 'ERROR',+ );+ if (pmFails.length) {+ out.push(+ '| Story | Element | LTR relCenterX | RTL relCenterX | \u0394 (px) |',+ );+ out.push(+ '|-------|---------|----------------|----------------|--------|',+ );+ for (const c of pmFails) {+ for (const f of c.fails || []) {+ out.push(+ `| ${c.storyId} | \`${f.cls || f.tag}\` | ${f.ltrRelCenterX} | ${f.rtlRelCenterX} (exp ~${f.expectedRtlCenterX}) | ${f.delta} |`,+ );+ }+ if (!(c.fails || []).length)+ out.push(+ `| ${c.storyId} | (error) | — | — | ${(c.notes || []).join('; ')} |`,+ );+ }+ out.push('');+ } else {+ out.push('_No positional-mirror FAILs._');+ out.push('');+ }+ }+ const decorations = r.directionalDecorations;+ if (decorations) {+ out.push('### Contextual directional decorations (D6, all stories)');+ out.push('');+ out.push(+ `**${decorations.pass} pass · ${decorations.fail} FAIL · ${decorations.na} N-A** (of ${decorations.total} stories scanned).`,+ );+ out.push('');+ const decorationFails = decorations.results.filter(+ x => x.verdict === 'fail' || x.verdict === 'ERROR',+ );+ if (decorationFails.length) {+ out.push('| Story | D6 | Detail |');+ out.push('|-------|----|--------|');+ for (const c of decorationFails)+ out.push(+ `| ${c.storyId} | ${c.verdict} | ${(c.notes || []).join('; ')} |`,+ );+ } else {+ out.push('_No directional-decoration FAILs._');+ }+ out.push('');+ }+ const coverage = r.coverage;+ if (coverage) {+ out.push('### Applicability coverage');+ out.push('');+ out.push(+ `**${coverage.measured} measured · ${coverage.verifiedNa} verified N-A · ${coverage.gaps} coverage gap · ${coverage.staleVerifiedNa} stale verified N-A.**`,+ );+ out.push('');+ const gaps = coverage.results.filter(+ x => x.status === 'coverage-gap' || x.status === 'stale-verified-na',+ );+ if (gaps.length) {+ out.push('| Component | Status | Detail |');+ out.push('|-----------|--------|--------|');+ for (const c of gaps)+ out.push(+ `| ${c.component} | ${c.status} | ${c.note || c.reason || 'unexplained all-N/A result'} |`,+ );+ out.push('');+ }+ }+ out.push('### Curated precision (D2 order / D3 behavior / D4 overlay)');+ out.push('');+ out.push('| Component | Rollup | Dimensions |');+ out.push('|-----------|--------|------------|');+ for (const c of r.curated.results) {+ const dims =+ Object.entries(c.dims)+ .map(([k, v]) => k + ':' + v)+ .join(', ') || '—';+ out.push(`| ${c.component} | ${c.rollup} | ${dims} |`);+ }+ lines.push(...out);+}+console.log(lines.join('\n'));diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex cefdf3aa9e..5a50d78709 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -2294,7 +2294,7 @@ jobs:# manifest and every applicable report.# To promote findings too, remove the audit step's continue-on-error.pr-rtl-shard:- name: pr-rtl (${{ matrix.package }})+ name: pr-rtl (${{ matrix.package }}${{ matrix.parts > 1 && format(' {0}/{1}', matrix.part, matrix.parts) || '' }})needs: [build-storybook, check-components]if: >-(github.event_name == 'pull_request' ||@@ -2302,10 +2302,19 @@ jobs:(needs.check-components.outputs.has_rtl_components == 'true' ||needs.check-components.outputs.has_rtl_harness == 'true' ||needs.check-components.outputs.force_full_component_audits == 'true')+ # Core is the largest package, so its audit is split three ways+ # (`--shard`) and joined by pr-rtl-merge; every other package runs whole.strategy:fail-fast: falsematrix:- package: [core, lab, charts, richtext, vega]+ include:+ - {package: core, part: 1, parts: 3}+ - {package: core, part: 2, parts: 3}+ - {package: core, part: 3, parts: 3}+ - {package: lab, part: 1, parts: 1}+ - {package: charts, part: 1, parts: 1}+ - {package: richtext, part: 1, parts: 1}+ - {package: vega, part: 1, parts: 1}runs-on: 4-core-ubuntutimeout-minutes: 30permissions:@@ -2370,11 +2379,16 @@ jobs:if [ -n "$FILTER" ]; thenFILTER_ARGS=(--filter "$FILTER")fi+ SHARD_ARGS=()+ if [ "${{ matrix.parts }}" -gt 1 ]; then+ SHARD_ARGS=(--shard "${{ matrix.part }}/${{ matrix.parts }}" --shard-output "rtl-shard-${{ matrix.part }}.json")+ fiecho "Auditing $PACKAGE components: $COMPONENTS"node apps/storybook/rtl-audit/rtl-audit.mjs \--storybook-dir apps/storybook/dist \--output rtl-audit-report.json \--packages "$PACKAGE" \+ "${SHARD_ARGS[@]}" \--concurrency 8 \"${FILTER_ARGS[@]}"@@ -2393,10 +2407,15 @@ jobs:echo "Applicable RTL audit did not run: $AUDIT_OUTCOME"exit 1fi- node .github/scripts/rtl-report-completion.mjs \- --report rtl-audit-report.json \- --package "${{ matrix.package }}" \- --filter "${{ steps.rtl-scope.outputs.filter }}"+ if [ "${{ matrix.parts }}" -gt 1 ]; then+ # A part writes cards only; pr-rtl-merge checks the joined report.+ test -s "rtl-shard-${{ matrix.part }}.json"+ else+ node .github/scripts/rtl-report-completion.mjs \+ --report rtl-audit-report.json \+ --package "${{ matrix.package }}" \+ --filter "${{ steps.rtl-scope.outputs.filter }}"+ fielif [ "$SHOULD_RUN" = "false" ]; thenif [ "$AUDIT_OUTCOME" != "skipped" ]; thenecho "Out-of-scope RTL audit unexpectedly ran: $AUDIT_OUTCOME"@@ -2408,111 +2427,14 @@ jobs:fi- name: Write scorecard summary- if: always() && steps.rtl-scope.outputs.should_run == 'true'+ if: always() && steps.rtl-scope.outputs.should_run == 'true' && matrix.parts == 1run: |- {- echo "## RTL semantic audit"- echo ""- echo "Audit scope: **${{ steps.rtl-scope.outputs.components }}**. The scheduled unfiltered sweep also runs weekly — see \`rtl-weekly.yml\`."- echo ""- echo "Relationship-based (LTR vs RTL in the same run) — no golden screenshots. **Soft-gated** pending a stability window."- echo ""- if [ -f rtl-audit-report.json ]; then- node -e '- const r = JSON.parse(require("fs").readFileSync("rtl-audit-report.json"));- const a = r.autoDiscovery;- const known = new Set(r.knownNotRtl || []);- const out = [];- out.push("### Auto-discovery (D1 icon-mirror, one representative story per scoped component)");- out.push("");- out.push(`**${a.pass} pass · ${a.fail} not-RTL · ${a.na} N-A** (of ${a.total} scoped components). Surprises (not pre-labelled): **${a.surprises.length}**${a.surprises.length ? ": " + a.surprises.join(", ") : ""}.`);- out.push("");- const fails = a.results.filter(x => x.verdict === "fail" || x.verdict === "ERROR");- if (fails.length) {- out.push("| Component | D1 | Label | Detail |");- out.push("|-----------|----|-------|--------|");- for (const c of fails) {- const label = known.has(c.component) ? "known-not-rtl" : "⚠️ surprise";- out.push(`| ${c.component} | ${c.verdict} | ${label} | ${(c.notes||[]).join("; ")} |`);- }- } else {- out.push("_No not-RTL findings._");- }- out.push("");- const passes = a.results.filter(x => x.verdict === "pass").map(x => x.component);- out.push(`RTL-ready (D1 pass): ${passes.join(", ") || "—"}.`);- out.push("");- const pm = r.positionalMirror;- if (pm) {- out.push("### Positional-mirror (D5, all scoped stories)");- out.push("");- out.push("Catches a logical anchor (insetInlineStart/End) paired with an UNFLIPPED physical transform (translate/translateX) → element lands on the wrong side in RTL. Lint can\u2019t see this (each prop is individually fine). Tolerance " + pm.tolerancePx + "px, degenerate-parent guard (<8px) applied.");- out.push("");- out.push(`**${pm.pass} pass · ${pm.fail} FAIL · ${pm.na} N-A** (of ${pm.total} scoped stories scanned).`);- out.push("");- const pmFails = pm.results.filter(x => x.verdict === "fail" || x.verdict === "ERROR");- if (pmFails.length) {- out.push("| Story | Element | LTR relCenterX | RTL relCenterX | \u0394 (px) |");- out.push("|-------|---------|----------------|----------------|--------|");- for (const c of pmFails) {- for (const f of (c.fails || [])) {- out.push(`| ${c.storyId} | \`${f.cls || f.tag}\` | ${f.ltrRelCenterX} | ${f.rtlRelCenterX} (exp ~${f.expectedRtlCenterX}) | ${f.delta} |`);- }- if (!(c.fails || []).length) out.push(`| ${c.storyId} | (error) | — | — | ${(c.notes||[]).join("; ")} |`);- }- out.push("");- } else {- out.push("_No positional-mirror FAILs._");- out.push("");- }- }- const decorations = r.directionalDecorations;- if (decorations) {- out.push("### Contextual directional decorations (D6, all stories)");- out.push("");- out.push(`**${decorations.pass} pass · ${decorations.fail} FAIL · ${decorations.na} N-A** (of ${decorations.total} stories scanned).`);- out.push("");- const decorationFails = decorations.results.filter(x => x.verdict === "fail" || x.verdict === "ERROR");- if (decorationFails.length) {- out.push("| Story | D6 | Detail |");- out.push("|-------|----|--------|");- for (const c of decorationFails) out.push(`| ${c.storyId} | ${c.verdict} | ${(c.notes||[]).join("; ")} |`);- } else {- out.push("_No directional-decoration FAILs._");- }- out.push("");- }- const coverage = r.coverage;- if (coverage) {- out.push("### Applicability coverage");- out.push("");- out.push(`**${coverage.measured} measured · ${coverage.verifiedNa} verified N-A · ${coverage.gaps} coverage gap · ${coverage.staleVerifiedNa} stale verified N-A.**`);- out.push("");- const gaps = coverage.results.filter(x => x.status === "coverage-gap" || x.status === "stale-verified-na");- if (gaps.length) {- out.push("| Component | Status | Detail |");- out.push("|-----------|--------|--------|");- for (const c of gaps) out.push(`| ${c.component} | ${c.status} | ${c.note || c.reason || "unexplained all-N/A result"} |`);- out.push("");- }- }- out.push("### Curated precision (D2 order / D3 behavior / D4 overlay)");- out.push("");- out.push("| Component | Rollup | Dimensions |");- out.push("|-----------|--------|------------|");- for (const c of r.curated.results) {- const dims = Object.entries(c.dims).map(([k,v]) => k+":"+v).join(", ") || "—";- out.push(`| ${c.component} | ${c.rollup} | ${dims} |`);- }- console.log(out.join("\n"));- '- else- echo "_No report produced — audit errored before writing output._"- fi- } >> "$GITHUB_STEP_SUMMARY"+ node .github/scripts/rtl-scorecard-summary.mjs \+ --report rtl-audit-report.json \+ --scope "${{ steps.rtl-scope.outputs.components }}" >> "$GITHUB_STEP_SUMMARY"- name: Upload RTL shard evidence- if: always()+ if: always() && matrix.parts == 1uses: actions/upload-artifact@v7with:name: rtl-audit-report-${{ matrix.package }}@@ -2522,9 +2444,114 @@ jobs:if-no-files-found: errorretention-days: 1+ - name: Upload RTL part+ if: always() && matrix.parts > 1+ uses: actions/upload-artifact@v7+ with:+ name: rtl-audit-part-${{ matrix.package }}-${{ matrix.part }}+ path: |+ rtl-shard-scope.json+ rtl-shard-${{ matrix.part }}.json+ if-no-files-found: error+ retention-days: 1++ # Joins the Core parts into the one report a whole Core leg would have+ # written (the same scope manifest, report and completion check), uploaded+ # under the same artifact name for the pr-rtl join. A missing or mismatched+ # part fails here.+ pr-rtl-merge:+ name: pr-rtl (core)+ needs: [build-storybook, check-components, pr-rtl-shard]+ if: >-+ always() && !cancelled() &&+ (github.event_name == 'pull_request' ||+ (github.event_name == 'workflow_dispatch' && inputs.operation == 'release-check')) &&+ (needs.check-components.outputs.has_rtl_components == 'true' ||+ needs.check-components.outputs.has_rtl_harness == 'true' ||+ needs.check-components.outputs.force_full_component_audits == 'true')+ runs-on: 2-core-ubuntu-arm+ timeout-minutes: 15+ permissions:+ contents: read+ steps:+ - name: Checkout+ uses: actions/checkout@v7+ with:+ ref: ${{ github.event.pull_request.head.sha || github.sha }}++ - name: Setup Node and pnpm+ uses: ./.github/actions/setup++ - name: Download Storybook artifact+ uses: actions/download-artifact@v8+ with:+ name: storybook-${{ needs.build-storybook.outputs.short_hash }}+ path: apps/storybook/dist++ - name: Download Core RTL parts+ uses: actions/download-artifact@v8+ with:+ pattern: rtl-audit-part-core-*+ path: rtl-parts++ - name: Join Core RTL parts+ id: join+ run: |+ set -eu+ manifests=(rtl-parts/*/rtl-shard-scope.json)+ if [ "${#manifests[@]}" -ne 3 ]; then+ echo "Expected 3 Core RTL parts, found ${#manifests[@]}."+ exit 1+ fi+ for manifest in "${manifests[@]}"; do+ cmp -s "$manifest" "${manifests[0]}" || { echo "Core RTL parts disagree on scope: $manifest"; exit 1; }+ done+ cp "${manifests[0]}" rtl-shard-scope.json+ FILTER=$(jq -r '.filter' rtl-shard-scope.json)+ echo "components=${FILTER:-full core roster}" >> "$GITHUB_OUTPUT"+ if [ "$(jq -r '.shouldRun' rtl-shard-scope.json)" != true ]; then+ echo "Core RTL audit not applicable."+ exit 0+ fi+ FILTER_ARGS=()+ if [ -n "$FILTER" ]; then FILTER_ARGS=(--filter "$FILTER"); fi+ set +e+ node apps/storybook/rtl-audit/rtl-audit.mjs \+ --storybook-dir apps/storybook/dist \+ --output rtl-audit-report.json \+ --packages core \+ --merge-shards rtl-parts \+ "${FILTER_ARGS[@]}"+ code=$?+ set -e+ # 1 is the soft findings signal; anything else is a failed join.+ case "$code" in 0|1) ;; *) exit "$code" ;; esac+ node .github/scripts/rtl-report-completion.mjs \+ --report rtl-audit-report.json \+ --package core \+ --filter "$FILTER"++ - name: Write scorecard summary+ if: always() && hashFiles('rtl-audit-report.json') != ''+ run: |+ node .github/scripts/rtl-scorecard-summary.mjs \+ --report rtl-audit-report.json \+ --scope "${{ steps.join.outputs.components }}" >> "$GITHUB_STEP_SUMMARY"++ - name: Upload RTL shard evidence+ if: always()+ uses: actions/upload-artifact@v7+ with:+ name: rtl-audit-report-core+ path: |+ rtl-shard-scope.json+ rtl-audit-report.json+ if-no-files-found: error+ retention-days: 1+# Stable required context joining the five package shards above.pr-rtl:- needs: [check-scope, check-components, pr-rtl-shard]+ needs: [check-scope, check-components, pr-rtl-shard, pr-rtl-merge]if: ${{ always() && !cancelled() && ((github.event_name == 'pull_request' && needs.check-scope.outputs.spec_only != 'true') || (github.event_name == 'workflow_dispatch' && inputs.operation == 'release-check')) }}runs-on: ubuntu-slimtimeout-minutes: 5@@ -2544,7 +2571,7 @@ jobs:run: |node .github/scripts/rtl-join.mjs \--check-components "${{ needs.check-components.result }}" \- --shards "${{ needs.pr-rtl-shard.result }}" \+ --shards "${{ needs.pr-rtl-shard.result == needs.pr-rtl-merge.result && needs.pr-rtl-shard.result || format('{0}/{1}', needs.pr-rtl-shard.result, needs.pr-rtl-merge.result) }}" \--should-run "${{ needs.check-components.outputs.has_rtl_components == 'true' || needs.check-components.outputs.has_rtl_harness == 'true' || needs.check-components.outputs.force_full_component_audits == 'true' }}" \--force-full "${{ needs.check-components.outputs.force_full_component_audits }}" \--reports-dir rtl-shard-reportsdiff --git a/apps/storybook/rtl-audit/README.md b/apps/storybook/rtl-audit/README.mdindex 81413e17fd..73669d9762 100644--- a/apps/storybook/rtl-audit/README.md+++ b/apps/storybook/rtl-audit/README.md@@ -24,7 +24,10 @@ independent auto passes: **D1 (icon-mirror)**, **D5 (positional-mirror)**, and> a missing policy, empty or unmatched path set, unresolved component list, or> registry/classifier/workflow mutation runs the full audit rather than accepting> an empty scope. CI partitions that full scope into one bounded shard per-> canonical package, each with four browser workers; the stable `pr-rtl` context+> canonical package, each with eight browser workers. Core, the largest, runs as+> three parts (`--shard i/3`, every third D1 target, story and curated target)+> that `pr-rtl-merge` joins with `--merge-shards` into the report a whole Core+> leg would write; a missing or mismatched part fails the join. The stable `pr-rtl` context> succeeds only after all five scope manifests arrive and every applicable> package produces a report whose requested package/filter, duplicate-free exact> D1/D5/D6 identities, and nonzero planned/completed scans match. When trusteddiff --git a/apps/storybook/rtl-audit/rtl-audit-shards.mjs b/apps/storybook/rtl-audit/rtl-audit-shards.mjsnew file mode 100644index 0000000000..58f0fb1e17--- /dev/null+++ b/apps/storybook/rtl-audit/rtl-audit-shards.mjs@@ -0,0 +1,191 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Split one package's RTL audit across jobs and join the parts.+ * @input The audit's ordered plan (D1 targets, D5/D6 stories, curated targets)+ * and one shard's cards.+ * @output A shard file per job, and — only when every shard of the same plan+ * and the same Storybook build is present — every card in plan order, as a+ * single run would have produced them.+ * @position Used by rtl-audit.mjs: `--shard`/`--shard-output` write,+ * `--merge-shards` reads. Coverage and completion are computed from the+ * joined cards, so a missing card would read as an unaudited component; a+ * partial or mismatched set is refused rather than merged.+ */++import crypto from 'node:crypto';+import fs from 'node:fs';+import path from 'node:path';++export const RTL_SHARD_FILE_VERSION = 1;+const PARTS = ['d1', 'stories', 'curated'];++export function parseShard(value) {+ const match = /^(\d+)\/(\d+)$/.exec(value ?? '');+ const index = match ? Number(match[1]) : NaN;+ const count = match ? Number(match[2]) : NaN;+ if (+ !Number.isInteger(index) ||+ !Number.isInteger(count) ||+ count < 1 ||+ index < 1 ||+ index > count+ ) {+ throw new Error(+ `--shard must be <index>/<count> with 1 <= index <= count, got ${value ?? 'nothing'}`,+ );+ }+ return {index, count};+}++/** Positions of the items a shard owns: every count-th, from its index. */+export function shardPositions(length, {index, count}) {+ return Array.from({length}, (_, position) => position).filter(+ position => position % count === index - 1,+ );+}++/** @param {{d1: string[], stories: string[], curated: string[]}} plan */+export function planDigest(plan) {+ return crypto+ .createHash('sha256')+ .update(JSON.stringify(PARTS.map(part => plan[part])))+ .digest('hex');+}++export function readStorybookSha(dist) {+ const stamp = path.join(dist, 'astryx-build-sha.txt');+ return fs.existsSync(stamp)+ ? fs.readFileSync(stamp, 'utf8').trim() || null+ : null;+}++/**+ * @param {object} options+ * @param {{d1: string[], stories: string[], curated: string[]}} options.plan+ * @param {{index: number, count: number}} options.shard+ * @param {{d1: Map<number, object>, stories: Map<number, object>, curated: Map<number, object>}} options.cards+ * position in the plan -> card(s) for that item+ */+export function shardFile({+ plan,+ shard,+ storybookSha,+ cards,+ d8BrowserContract,+ pageRecoveries,+}) {+ return {+ version: RTL_SHARD_FILE_VERSION,+ shard,+ storybookSha,+ planDigest: planDigest(plan),+ d8BrowserContract,+ pageRecoveries,+ cards: Object.fromEntries(+ PARTS.map(part => [part, Object.fromEntries(cards[part])]),+ ),+ };+}++/** Shard files directly in `dir` or one directory below it. */+export function readShardFiles(dir) {+ if (!dir || !fs.existsSync(dir)) return [];+ const files = [];+ for (const entry of fs+ .readdirSync(dir, {withFileTypes: true})+ .sort((a, b) => a.name.localeCompare(b.name))) {+ const entryPath = path.join(dir, entry.name);+ const candidates = entry.isDirectory()+ ? fs+ .readdirSync(entryPath)+ .sort()+ .map(name => path.join(entryPath, name))+ : [entryPath];+ for (const file of candidates) {+ if (!/^rtl-shard-\d+\.json$/.test(path.basename(file))) continue;+ files.push({file, content: JSON.parse(fs.readFileSync(file, 'utf8'))});+ }+ }+ return files;+}++/**+ * @returns {{d1: object[], stories: object[], curated: object[], d8BrowserContract: object, pageRecoveries: object[]}}+ * cards in plan order+ */+export function mergeRtlShards(files, {plan, storybookSha}) {+ if (files.length === 0) throw new Error('No RTL shard files to merge');+ const digest = planDigest(plan);+ const count = files[0].content?.shard?.count;+ const byIndex = new Map();+ for (const {file, content} of files) {+ const where = path.basename(file);+ if (content?.version !== RTL_SHARD_FILE_VERSION) {+ throw new Error(+ `${where}: unsupported RTL shard version ${content?.version}`,+ );+ }+ if (content.shard?.count !== count) {+ throw new Error(+ `${where}: shard count ${content.shard?.count} does not match ${count}`,+ );+ }+ if (byIndex.has(content.shard.index)) {+ throw new Error(+ `${where}: shard ${content.shard.index}/${count} appears twice`,+ );+ }+ if (content.planDigest !== digest) {+ throw new Error(`${where}: audited a different plan than this run`);+ }+ if ((content.storybookSha ?? null) !== (storybookSha ?? null)) {+ throw new Error(+ `${where}: audited Storybook ${content.storybookSha ?? 'unstamped'}, this run reads ${storybookSha ?? 'unstamped'}`,+ );+ }+ for (const part of PARTS) {+ const expected = shardPositions(plan[part].length, content.shard).map(+ String,+ );+ const actual = Object.keys(content.cards?.[part] ?? {});+ if (+ actual.length !== expected.length ||+ expected.some(position => !actual.includes(position))+ ) {+ throw new Error(+ `${where}: does not hold exactly the ${part} items of shard ${content.shard.index}/${count}`,+ );+ }+ }+ byIndex.set(content.shard.index, content);+ }+ if (byIndex.size !== count) {+ throw new Error(+ `RTL shards ${[...byIndex.keys()].sort((a, b) => a - b).join(', ')} of ${count}: the set is incomplete`,+ );+ }+ const shards = [...byIndex.entries()]+ .sort(([a], [b]) => a - b)+ .map(([, content]) => content);+ const contracts = new Set(+ shards.map(content => JSON.stringify(content.d8BrowserContract)),+ );+ if (contracts.size !== 1) {+ throw new Error(+ 'RTL shards disagree on the D8 browser contract self-check',+ );+ }+ const ordered = part =>+ plan[part].map((_, position) => {+ const owner = shards[position % count];+ return owner.cards[part][String(position)];+ });+ return {+ d1: ordered('d1'),+ stories: ordered('stories'),+ curated: ordered('curated'),+ d8BrowserContract: shards[0].d8BrowserContract,+ pageRecoveries: shards.flatMap(content => content.pageRecoveries ?? []),+ };+}diff --git a/apps/storybook/rtl-audit/rtl-audit.mjs b/apps/storybook/rtl-audit/rtl-audit.mjsindex 8fe0a24ed1..2d8ebdaafd 100644--- a/apps/storybook/rtl-audit/rtl-audit.mjs+++ b/apps/storybook/rtl-audit/rtl-audit.mjs@@ -27,6 +27,9 @@* @input --storybook-dir <path> --output <file> [--targets <path>]* [--verified-not-applicable <path>] [--filter <csv>] [--packages <csv>]* [--auto-only] [--curated-only]+ * [--shard <i>/<n> --shard-output <file>] audit every n-th planned item and+ * write only those cards; [--merge-shards <dir>] build the report from a+ * complete shard set without a browser (rtl-audit-shards.mjs).* @output JSON scorecard: D1/D5/D6 auto verdicts, curated D2/D3/D4/D7/D8/D9* results, exact planned/completed scan counts, a component coverage* rollup, and the worker pages replaced after a failed story@@ -68,6 +71,14 @@ import {mapPool,runSteps,} from './rtl-audit-pool.mjs';+import {+ mergeRtlShards,+ parseShard,+ readShardFiles,+ readStorybookSha,+ shardFile,+ shardPositions,+} from './rtl-audit-shards.mjs';const {componentPackage,@@ -125,6 +136,19 @@ const CONCURRENCY = Math.max(1, Number(getArg('concurrency') || process.env.RTL_// is validated (DateInput popover elements mirror), but stays opt-in until the// stability window promotes it. See README "D5 positional-mirror".const PM_REVEAL = hasFlag('pm-reveal');+// A sharded audit: each `--shard i/n` job audits every n-th D1 target, story+// and curated target and writes only those cards (`--shard-output`);+// `--merge-shards` then builds the report from the complete set, exactly as+// one run would, without opening a browser.+const SHARD = getArg('shard') === null ? null : parseShard(getArg('shard'));+const SHARD_OUTPUT = getArg('shard-output');+const MERGE_SHARDS = getArg('merge-shards');+if ((SHARD === null) !== (SHARD_OUTPUT === null)) {+ throw new Error('--shard and --shard-output must be given together');+}+if (SHARD !== null && MERGE_SHARDS !== null) {+ throw new Error('--shard and --merge-shards cannot be combined');+}// ---------------------------------------------------------------------------// static file server (same shape as accessibility-audit.js)@@ -1100,48 +1124,99 @@ async function cleanupRuntime() {filters: FILTER,});- const {server, port} = await serve(path.resolve(DIST));- runtime.server = server;- const browser = await chromium.launch();- runtime.browser = browser;- const pool = await createPagePool({- size: CONCURRENCY,- openPage: () =>- browser.newPage({viewport: {width: 1100, height: 760}, deviceScaleFactor: 1}),- });- runtime.pool = pool;- // Curated dims run serially on the first slot's current page.- const d8BrowserContract = await verifyD8BrowserContract(pool.first());- const coarseContext = await browser.newContext({- viewport: {width: 1100, height: 760},- deviceScaleFactor: 1,- hasTouch: true,- isMobile: true,- });- runtime.coarseContext = coarseContext;- const curatedPages = createCuratedPages({- pool,- coarsePage: await coarseContext.newPage(),- openCoarsePage: () => coarseContext.newPage(),- });-- // ---- (A) auto-discovery over every audited-package story ----- const autoResults = []; // D1 icon-mirror- const pmResults = []; // D5 positional-mirror- const decorationResults = []; // D6 contextual directional decoration+ // The audit's plan: D1 runs one representative story per component (extra+ // stories add little D1 signal); D5 (positional-mirror) and D6 run over+ // EVERY story — a positioned bug can be story-specific (only a `withStatus`+ // variant mounts the offending element), so they do not collapse to one per+ // component; curated targets add the behaviour and geometry dims.const perComponent = new Map();for (const {component, id} of scopedStoryRoutes) {if (!perComponent.has(component)) perComponent.set(component, id);}const d1Targets = [...perComponent].map(([component, id]) => ({comp: component, id}));- if (!CURATED_ONLY) {- // D1 runs one representative story per component (extra stories add little- // D1 signal). D5 (positional-mirror) runs over EVERY core story — a- // positioned bug can be story-specific (only a `withStatus` variant mounts- // the offending element), so we don't collapse to one-per-component.- autoResults.push(- ...(await mapPool(d1Targets, pool, {+ const storyTargets = scopedStoryRoutes.map(({id, component}) => ({id, comp: component}));+ const curatedTargets = [];+ for (const t of targets) {+ const component = componentFromTarget(+ t,+ AUDITED_PACKAGE_NAMES,+ publicComponentsByPackage,+ );+ if (!belongsToActivePackage({component, id: t.storyId})) continue;+ if (!matchesFilter(component)) continue;+ if (!entries[t.storyId]) {+ curatedTargets.push({t, component, missing: true});+ continue;+ }+ // skip if the entry only had D1 (now covered by auto-discovery)+ const dims = (t.dims || []).filter(d => d !== 'D1');+ if (dims.length === 0) continue;+ curatedTargets.push({t, component, dims});+ }+ const plan = {+ d1: CURATED_ONLY ? [] : d1Targets.map(({comp, id}) => `${comp}::${id}`),+ stories: CURATED_ONLY ? [] : storyTargets.map(({comp, id}) => `${comp}::${id}`),+ curated: AUTO_ONLY+ ? []+ : curatedTargets.map(({t, component}) => `${component}::${t.storyId}`),+ };+ const storybookSha = readStorybookSha(DIST);+ /** Positions of `items` this run audits. */+ const mine = items =>+ SHARD === null+ ? items.map((_, position) => position)+ : shardPositions(items.length, SHARD);++ const autoResults = []; // D1 icon-mirror+ const pmResults = []; // D5 positional-mirror+ const decorationResults = []; // D6 contextual directional decoration+ const curatedResults = [];+ let d8BrowserContract;+ let pageRecoveries;++ if (MERGE_SHARDS !== null) {+ const merged = mergeRtlShards(readShardFiles(MERGE_SHARDS), {plan, storybookSha});+ autoResults.push(...merged.d1);+ pmResults.push(...merged.stories.map(cards => cards.positional));+ decorationResults.push(...merged.stories.map(cards => cards.decoration));+ curatedResults.push(...merged.curated);+ d8BrowserContract = merged.d8BrowserContract;+ pageRecoveries = merged.pageRecoveries;+ console.error(`MERGED ${MERGE_SHARDS}: ${autoResults.length} D1, ${pmResults.length} story, ${curatedResults.length} curated cards`);+ } else {+ const {server, port} = await serve(path.resolve(DIST));+ runtime.server = server;+ const browser = await chromium.launch();+ runtime.browser = browser;+ const pool = await createPagePool({+ size: CONCURRENCY,+ openPage: () =>+ browser.newPage({viewport: {width: 1100, height: 760}, deviceScaleFactor: 1}),+ });+ runtime.pool = pool;+ // Curated dims run serially on the first slot's current page.+ d8BrowserContract = await verifyD8BrowserContract(pool.first());+ const coarseContext = await browser.newContext({+ viewport: {width: 1100, height: 760},+ deviceScaleFactor: 1,+ hasTouch: true,+ isMobile: true,+ });+ runtime.coarseContext = coarseContext;+ const curatedPages = createCuratedPages({+ pool,+ coarsePage: await coarseContext.newPage(),+ openCoarsePage: () => coarseContext.newPage(),+ });++ // Cards by plan position, for a shard file.+ const shardCards = {d1: new Map(), stories: new Map(), curated: new Map()};++ // ---- (A) auto-discovery over every audited-package story ----+ if (!CURATED_ONLY) {+ const d1Positions = mine(d1Targets);+ const d1Cards = await mapPool(d1Positions.map(position => d1Targets[position]), pool, {scan: async ({comp, id}, workerPage) => {const card = await autoD1(workerPage, port, id, comp);if (card.verdict !== 'N-A') {@@ -1154,62 +1229,77 @@ async function cleanupRuntime() {return {component: comp, storyId: id, dim: 'D1', verdict: 'ERROR', notes: [String(e).slice(0, 160)], icons: 0};},describe: ({id}) => ({phase: 'D1', storyId: id}),- })),- );- // D5 positional-mirror and D6 contextual decorations over every audited- // story, sharing one LTR load per story (see measureAutoStory).- const storyTargets = scopedStoryRoutes.map(({id, component}) => ({id, comp: component}));- const storyCards = await mapPool(storyTargets, pool, {- scan: async ({id, comp}, workerPage) => {- const cards = await autoPositionalAndDecorations(workerPage, port, id, comp);- if (cards.positional.verdict !== 'N-A') {- console.error(`PM ${cards.positional.verdict.toUpperCase().padEnd(4)} ${comp.padEnd(24)} ${id.padEnd(40)} cand=${cards.positional.candidates}`);- }- if (cards.decoration.verdict !== 'N-A') {- console.error(`DEC ${cards.decoration.verdict.toUpperCase().padEnd(4)} ${comp.padEnd(24)} ${id.padEnd(40)} glyphs=${cards.decoration.decorations}`);+ });+ autoResults.push(...d1Cards);+ d1Positions.forEach((position, i) => shardCards.d1.set(position, d1Cards[i]));+ // D5 positional-mirror and D6 contextual decorations over every audited+ // story, sharing one LTR load per story (see measureAutoStory).+ const storyPositions = mine(storyTargets);+ const storyCards = await mapPool(storyPositions.map(position => storyTargets[position]), pool, {+ scan: async ({id, comp}, workerPage) => {+ const cards = await autoPositionalAndDecorations(workerPage, port, id, comp);+ if (cards.positional.verdict !== 'N-A') {+ console.error(`PM ${cards.positional.verdict.toUpperCase().padEnd(4)} ${comp.padEnd(24)} ${id.padEnd(40)} cand=${cards.positional.candidates}`);+ }+ if (cards.decoration.verdict !== 'N-A') {+ console.error(`DEC ${cards.decoration.verdict.toUpperCase().padEnd(4)} ${comp.padEnd(24)} ${id.padEnd(40)} glyphs=${cards.decoration.decorations}`);+ }+ return cards;+ },+ onError: ({id, comp}, e) => {+ console.error(`PM+DEC ERROR ${comp} ${id}: ${String(e).slice(0, 120)}`);+ const notes = [String(e).slice(0, 160)];+ return {+ positional: {component: comp, storyId: id, dim: 'D5-positional', verdict: 'ERROR', notes, candidates: 0, fails: []},+ decoration: {component: comp, storyId: id, dim: 'D6-decoration', verdict: 'ERROR', notes: [...notes], decorations: 0, results: []},+ };+ },+ describe: ({id}) => ({phase: 'D5+D6', storyId: id}),+ });+ pmResults.push(...storyCards.map(cards => cards.positional));+ decorationResults.push(...storyCards.map(cards => cards.decoration));+ storyPositions.forEach((position, i) => shardCards.stories.set(position, storyCards[i]));+ }++ // ---- (B) curated precision dims ----+ // Deliberately serial on one page: only a handful of targets, and these do+ // multi-step interactions (setup clicks, scroll assertions) where a shared+ // machine under load is more likely to change behaviour than to save time.+ if (!AUTO_ONLY) {+ for (const position of mine(curatedTargets)) {+ const {t, component, dims, missing} = curatedTargets[position];+ if (missing) {+ const card = {component, storyId: t.storyId, rollup: 'MISSING-STORY', dims: {}, notes: ['story not in index.json']};+ curatedResults.push(card);+ shardCards.curated.set(position, card);+ continue;}- return cards;- },- onError: ({id, comp}, e) => {- console.error(`PM+DEC ERROR ${comp} ${id}: ${String(e).slice(0, 120)}`);- const notes = [String(e).slice(0, 160)];- return {- positional: {component: comp, storyId: id, dim: 'D5-positional', verdict: 'ERROR', notes, candidates: 0, fails: []},- decoration: {component: comp, storyId: id, dim: 'D6-decoration', verdict: 'ERROR', notes: [...notes], decorations: 0, results: []},- };- },- describe: ({id}) => ({phase: 'D5+D6', storyId: id}),- });- pmResults.push(...storyCards.map(cards => cards.positional));- decorationResults.push(...storyCards.map(cards => cards.decoration));- }+ // scoreCurated records each dim's failure itself; what escapes it is a+ // page that could not be replaced, which ends the run.+ const card = await scoreCurated(curatedPages, port, {...t, component, dims});+ curatedResults.push(card);+ shardCards.curated.set(position, card);+ console.error(`CUR ${card.rollup.padEnd(10)} ${component.padEnd(20)} ${JSON.stringify(card.dims)}`);+ }+ }+ pageRecoveries = pool.recoveries;- // ---- (B) curated precision dims ----- // Deliberately serial on one page: only a handful of targets, and these do- // multi-step interactions (setup clicks, scroll assertions) where a shared- // machine under load is more likely to change behaviour than to save time.- const curatedResults = [];- if (!AUTO_ONLY) {- for (const t of targets) {- const component = componentFromTarget(- t,- AUDITED_PACKAGE_NAMES,- publicComponentsByPackage,+ if (SHARD !== null) {+ fs.writeFileSync(+ SHARD_OUTPUT,+ JSON.stringify(+ shardFile({+ plan,+ shard: SHARD,+ storybookSha,+ cards: shardCards,+ d8BrowserContract,+ pageRecoveries,+ }),+ ),);- if (!belongsToActivePackage({component, id: t.storyId})) continue;- if (!matchesFilter(component)) continue;- if (!entries[t.storyId]) {- curatedResults.push({component, storyId: t.storyId, rollup: 'MISSING-STORY', dims: {}, notes: ['story not in index.json']});- continue;- }- // skip if the entry only had D1 (now covered by auto-discovery)- const dims = (t.dims || []).filter(d => d !== 'D1');- if (dims.length === 0) continue;- // scoreCurated records each dim's failure itself; what escapes it is a- // page that could not be replaced, which ends the run.- const card = await scoreCurated(curatedPages, port, {...t, component, dims});- curatedResults.push(card);- console.error(`CUR ${card.rollup.padEnd(10)} ${component.padEnd(20)} ${JSON.stringify(card.dims)}`);+ console.error(`WROTE ${SHARD_OUTPUT} (shard ${SHARD.index}/${SHARD.count})`);+ return;}}@@ -1277,7 +1367,7 @@ async function cleanupRuntime() {// Worker pages replaced after a story failed on them. The failed story// keeps its ERROR result; the record shows the stories after it ran on a// fresh page.- pageRecoveries: pool.recoveries,+ pageRecoveries,autoDiscovery: {total: autoResults.length,applicable: autoResults.filter(r => r.verdict !== 'N-A').length,@@ -1313,7 +1403,7 @@ async function cleanupRuntime() {console.error(`AUTO: ${report.autoDiscovery.pass} pass / ${report.autoDiscovery.fail} fail (${surprises.length} surprise) / ${report.autoDiscovery.na} N-A`);console.error(`PM : ${report.positionalMirror.pass} pass / ${report.positionalMirror.fail} fail / ${report.positionalMirror.na} N-A (tol ${PM_TOL}px)`);console.error(`DEC : ${report.directionalDecorations.pass} pass / ${report.directionalDecorations.fail} fail / ${report.directionalDecorations.na} N-A`);- console.error(`POOL: ${pool.recoveries.length} page replacement(s) after a failed story`);+ 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`);// 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.