An open source design system that's fully customizable and agent ready
TypeScript
test(visual): cover all six theme axes, and the build path (#5479)
Cindy Zhangad29a5c4329d
diff --git a/.github/scripts/visual-gate/gate.mjs b/.github/scripts/visual-gate/gate.mjsindex 3b59503e98..69982626b5 100644--- a/.github/scripts/visual-gate/gate.mjs+++ b/.github/scripts/visual-gate/gate.mjs@@ -31,6 +31,7 @@ import {capture, scout} from './lib/capture.mjs';import {analyzeTargeting, buildVerdict, compareCaptures} from './lib/compare.mjs';import {buildPlan, readStoryIndex} from './lib/plan.mjs';import {READ_TARGETS, emptyAccumulator, fold} from './lib/probe-reach.mjs';+import {AXES, PROBE_TOKENS, READ_AXES} from './lib/probe-axes.mjs';import {renderReport} from './lib/report.mjs';import {accept, incomparable, readBaseline} from './lib/baseline.mjs';import {loadConfig, loadThemeOverrides, loadThemingTargets} from './lib/sources.mjs';@@ -363,6 +364,13 @@ async function main() {const browser = await chromium.launch();const page = await browser.newPage({viewport: config.viewport});const acc = emptyAccumulator();+ const axisHits = {+ tokens: new Set(),+ icon: new Set(),+ indicator: new Set(),+ fonts: new Set(),+ syntax: new Set(),+ };let done = 0;for (const story of subject) {try {@@ -373,6 +381,18 @@ async function main() {await page.waitForSelector('#storybook-root > *', {timeout: 20000});await page.evaluate(() => document.fonts.ready);fold(acc, await page.evaluate(READ_TARGETS), story.id);+ // The other five axes. A single story proves tokens and fonts; the+ // registry swaps and syntax need a story that renders one, so these+ // accumulate across the walk.+ const axes = await page.evaluate(READ_AXES);+ for (const [name, value] of Object.entries(axes.tokens)) {+ if (value && value === PROBE_TOKENS[name]) axisHits.tokens.add(name);+ }+ for (const kind of Object.keys(axes.swaps)) axisHits[kind]?.add(kind);+ if (/AstryxProbeFace/.test(axes.fontFamily)) axisHits.fonts.add('body');+ for (const color of axes.syntax) {+ if (/^rgb\(/.test(color)) axisHits.syntax.add(color);+ }} catch {// A story that will not render contributes no readings; the visual// tier reports it as a capture failure.@@ -386,9 +406,26 @@ async function main() {const unseen = [...new Set(declared)].filter(key => !acc.verified.has(key) && !acc.failures.has(key) && !acc.shadowed.has(key),);+ // An axis with nothing rendering it is UNVERIFIABLE, not passing — the+ // difference is the whole point, and reporting it as green is how a+ // check ends up asserting nothing.+ const axisReport = {+ components: {+ verified: acc.verified.size,+ missed: acc.failures.size,+ ...AXES.components,+ },+ tokens: {verified: axisHits.tokens.size, of: Object.keys(PROBE_TOKENS).length, ...AXES.tokens},+ icons: {verified: axisHits.icon.size > 0, ...AXES.icons},+ indicators: {verified: axisHits.indicator.size > 0, ...AXES.indicators},+ fonts: {verified: axisHits.fonts.size > 0, ...AXES.fonts},+ syntax: {verified: axisHits.syntax.size, ...AXES.syntax},+ };+const out = {version: 1,generatedAt: new Date().toISOString(),+ axes: axisReport,verified: [...acc.verified].sort(),failures: Object.fromEntries([...acc.failures].sort()),shadowed: Object.fromEntries([...acc.shadowed].sort()),@@ -397,8 +434,19 @@ async function main() {fs.mkdirSync(outDir, {recursive: true});fs.writeFileSync(path.join(outDir, 'reach.json'), `${JSON.stringify(out, null, 2)}\n`);+ process.stdout.write('theme axes:\n');+ for (const [name, info] of Object.entries(axisReport)) {+ const value =+ typeof info.verified === 'boolean'+ ? info.verified+ ? 'reached'+ : 'NOT REACHED'+ : `${info.verified}${info.of ? `/${info.of}` : ''} reached`;+ process.stdout.write(` ${name.padEnd(12)} ${value}\n`);+ }process.stdout.write(- `reached the pixels: ${out.verified.length}\n` ++ `\ncomponent targets\n` ++ `reached the pixels: ${out.verified.length}\n` +`shares an element with another: ${Object.keys(out.shadowed).length}\n` +`override did NOT arrive: ${Object.keys(out.failures).length}\n` +`no story renders it: ${out.neverRendered.length}\n`,diff --git a/.github/scripts/visual-gate/generate-probe-theme.mjs b/.github/scripts/visual-gate/generate-probe-theme.mjsindex d4eeb6b96e..c66b5df5b7 100644--- a/.github/scripts/visual-gate/generate-probe-theme.mjs+++ b/.github/scripts/visual-gate/generate-probe-theme.mjs@@ -20,10 +20,43 @@ import * as path from 'node:path';import {fileURLToPath, pathToFileURL} from 'node:url';import {buildProbeComponents, renderProbeTheme} from './lib/probe-theme.mjs';+import {PROBE_FONT, PROBE_SYNTAX, PROBE_TOKENS} from './lib/probe-axes.mjs';import {loadThemingTargets} from './lib/sources.mjs';const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');const OUT = path.join(REPO_ROOT, 'packages/themes/probe/src/probeTheme.ts');+const CONFIG_OUT = path.join(REPO_ROOT, 'packages/themes/probe/src/probeConfig.ts');++/**+ * The non-component axes, emitted as TypeScript.+ *+ * Generated rather than hand-kept so the values the theme SETS and the values+ * the gate ASSERTS are the same literals. Two copies of a fixture drift, and+ * the check would then report the drift as a broken theme.+ */+function renderProbeConfig() {+ const json = value => JSON.stringify(value, null, 2).replace(/"/g, "'");+ return `// Copyright (c) Meta Platforms, Inc. and affiliates.+// @generated by .github/scripts/visual-gate/generate-probe-theme.mjs — do not edit.+//+// The non-component axes of the probe theme, generated from+// .github/scripts/visual-gate/lib/probe-axes.mjs.++import type {SyntaxThemeTokenInput} from '@astryxdesign/core/theme';++/** Tokens the probe overrides, observable on any themed subtree. */+export const PROBE_TOKENS: Record<string, string> = ${json(PROBE_TOKENS)};++/** A font stack that can only have come from the theme. */+export const PROBE_FONT = '${PROBE_FONT.replace(/'/g, "\\'")}';++// Not annotated: the literal keys and tuple shapes ARE the contract+// (SyntaxThemeTokenInput requires all fourteen), so widening this to a Record+// would hide a missing token behind a type that accepts anything.+/** Syntax-token colours as [light, dark] pairs, one unmistakable value each. */+export const PROBE_SYNTAX: SyntaxThemeTokenInput = ${json(PROBE_SYNTAX)};+`;+}const check = process.argv.includes('--check');/**@@ -137,8 +170,20 @@ const source = await prettier.format(renderProbeTheme(built), {...options,filepath: OUT,});+const configSource = await prettier.format(renderProbeConfig(), {+ ...options,+ filepath: CONFIG_OUT,+});if (check) {+ const currentConfig = fs.existsSync(CONFIG_OUT) ? fs.readFileSync(CONFIG_OUT, 'utf8') : '';+ if (currentConfig !== configSource) {+ process.stderr.write(+ '::error::The probe theme config is out of date — a theme axis changed without regenerating it.\n' ++ 'Run: pnpm visual:probe-theme\n',+ );+ process.exit(1);+ }const current = fs.existsSync(OUT) ? fs.readFileSync(OUT, 'utf8') : '';if (current !== source) {process.stderr.write(@@ -156,6 +201,7 @@ if (check) {fs.mkdirSync(path.dirname(OUT), {recursive: true});fs.writeFileSync(OUT, source);+fs.writeFileSync(CONFIG_OUT, configSource);process.stdout.write(`Wrote ${path.relative(REPO_ROOT, OUT)} — ${built.coverage.targets} targets, ${built.coverage.selectors} selectors.\n`,);diff --git a/.github/scripts/visual-gate/lib/probe-axes.mjs b/.github/scripts/visual-gate/lib/probe-axes.mjsnew file mode 100644index 0000000000..d76ecd4479--- /dev/null+++ b/.github/scripts/visual-gate/lib/probe-axes.mjs@@ -0,0 +1,164 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file The other five theme axes, and the shape a probe needs for each.+ *+ * @input the theme contract (`defineTheme`) and the registries it accepts+ * @output the non-`components` half of the probe theme, plus what each axis+ * needs a story to render before it can be verified+ *+ * `defineTheme` takes six things. The generated component overrides cover one+ * of them, and until this file the other five had no coverage at all: a theme+ * could stop applying its icons, swap the wrong indicator, or lose a token,+ * and every test in the repo would still pass.+ *+ * They are not verifiable the same way, and pretending otherwise is how a+ * check ends up asserting nothing:+ *+ * tokens — a CSS custom property. Read it off the themed element and+ * compare; no component involvement, so this is exact.+ * icons — a component swap keyed by name. The proof is that the+ * REPLACEMENT rendered, so the probe swaps in a marked glyph+ * and the check looks for the marker.+ * indicators — the same, and the one Cindy named: `defineTheme({indicators})`+ * replaces the checkbox/radio/check visual everywhere at once.+ * A family-checked registry, so a `radio` replacement must+ * accept `singleSelection` states.+ * fonts — a font-family string; exact, same as a token.+ * syntax — a code-token colour map; exact per token, but only renders+ * inside a CodeBlock, so it needs a story that has one.+ *+ * Each probe value is deliberately absurd and unique, for the same reason the+ * component overrides are: the question is "did this arrive", not "does this+ * look right", and a value nothing else in the system would produce cannot+ * pass by coincidence.+ */++/** Tokens the probe overrides, chosen to be observable on any themed subtree. */+export const PROBE_TOKENS = {+ '--color-accent': 'rgb(255, 0, 128)',+ '--color-background-body': 'rgb(0, 32, 16)',+ '--color-text-primary': 'rgb(240, 255, 0)',+ '--color-border': 'rgb(0, 224, 255)',+ '--radius-element': '13px',+ '--spacing-4': '17px',+ '--duration-fast': '11ms',+ '--font-size-base': '15.5px',+};++/**+ * The font stack the probe declares. A real family name would be+ * indistinguishable from a fallback; this one can only come from the theme.+ */+export const PROBE_FONT = '"AstryxProbeFace", monospace';++/**+ * Syntax-token colours as the `[light, dark]` pairs `defineSyntaxTheme` takes,+ * one unmistakable value each. Distinct per mode, so a theme that applied the+ * light palette in dark mode is a visible failure rather than a silent one.+ */+export const PROBE_SYNTAX = {+ keyword: ['hsl(0 100% 45%)', 'hsl(0 100% 65%)'],+ string: ['hsl(26 100% 45%)', 'hsl(26 100% 65%)'],+ comment: ['hsl(51 100% 45%)', 'hsl(51 100% 65%)'],+ number: ['hsl(77 100% 45%)', 'hsl(77 100% 65%)'],+ function: ['hsl(103 100% 45%)', 'hsl(103 100% 65%)'],+ type: ['hsl(129 100% 45%)', 'hsl(129 100% 65%)'],+ variable: ['hsl(154 100% 45%)', 'hsl(154 100% 65%)'],+ operator: ['hsl(180 100% 45%)', 'hsl(180 100% 65%)'],+ constant: ['hsl(206 100% 45%)', 'hsl(206 100% 65%)'],+ tag: ['hsl(231 100% 45%)', 'hsl(231 100% 65%)'],+ attribute: ['hsl(257 100% 45%)', 'hsl(257 100% 65%)'],+ property: ['hsl(283 100% 45%)', 'hsl(283 100% 65%)'],+ punctuation: ['hsl(309 100% 45%)', 'hsl(309 100% 65%)'],+ background: ['hsl(334 100% 45%)', 'hsl(334 100% 65%)'],+};++/**+ * `data-*` marker a probe replacement carries.+ *+ * A swap is only proven by the replacement RENDERING. Comparing pixels cannot+ * do it — a themed icon and the default icon can easily paint the same — so+ * the replacement announces itself and the check looks for the announcement.+ */+export const PROBE_SWAP_ATTR = 'data-astryx-probe-swap';++/**+ * Every indicator name the theme contract can swap, with the family whose+ * state space a replacement must accept.+ *+ * Kept as data rather than inlined so the coverage check can say "the contract+ * has an indicator this probe does not swap" instead of silently missing it.+ * <!-- SYNC: packages/core/src/Indicator/types.ts (IndicatorMap) -->+ */+export const PROBE_INDICATORS = {+ check: 'singleSelection',+ radio: 'singleSelection',+ checkbox: 'multiSelection',+};++/**+ * What each axis needs before it can be checked, and how it is proven.+ *+ * The gate reads this to report an axis as unverifiable-for-a-reason rather+ * than as passing — an axis with no story to render it is not a green axis.+ */+export const AXES = {+ components: {+ proof: 'computed colour equals the selector-specific probe colour',+ needs: 'any story rendering the target',+ },+ tokens: {+ proof: 'custom property on the themed element equals the probe value',+ needs: 'any themed story',+ },+ icons: {+ proof: `an element carrying ${PROBE_SWAP_ATTR}="icon" is in the DOM`,+ needs: 'a story rendering a themeable icon',+ },+ indicators: {+ proof: `an element carrying ${PROBE_SWAP_ATTR}="indicator" is in the DOM`,+ needs: 'a story rendering a checkbox, radio, or selected option',+ },+ fonts: {+ proof: 'computed font-family names the probe face',+ needs: 'any themed story',+ },+ syntax: {+ proof: 'a highlighted code token equals the probe syntax colour',+ needs: 'a story rendering a CodeBlock',+ },+};++/**+ * Read the non-component axes off a themed page. Runs in the browser.+ *+ * Reads from the element the theme actually scopes to (`[data-astryx-theme]`),+ * not `:root` — the runtime path sets custom properties on that subtree, so+ * reading the document element would report every token as missing.+ */+export const READ_AXES = `(() => {+ const scope = document.querySelector('[data-astryx-theme]') ?? document.documentElement;+ const style = getComputedStyle(scope);+ const tokens = {};+ for (const name of ${JSON.stringify(Object.keys(PROBE_TOKENS))}) {+ tokens[name] = style.getPropertyValue(name).trim();+ }+ const swaps = {};+ for (const el of document.querySelectorAll('[${PROBE_SWAP_ATTR}]')) {+ swaps[el.getAttribute('${PROBE_SWAP_ATTR}')] = true;+ }+ return {+ tokens,+ swaps,+ // The token, not the scope element's computed font-family: the themed+ // wrapper sets no font of its own, so reading its computed value reports+ // the browser default and calls a working theme broken. The token is what+ // the theme sets and what every themed element inherits.+ fontFamily: style.getPropertyValue('--font-family-body').trim(),+ // Syntax colours only exist where a CodeBlock rendered.+ syntax: [...document.querySelectorAll('.astryx-code-block [class*="token"], .astryx-code-block span')]+ .slice(0, 60)+ .map((el) => getComputedStyle(el).color),+ };+})()`;diff --git a/.github/scripts/visual-gate/lib/probe-theme.mjs b/.github/scripts/visual-gate/lib/probe-theme.mjsindex f0ade098fa..c39a774d26 100644--- a/.github/scripts/visual-gate/lib/probe-theme.mjs+++ b/.github/scripts/visual-gate/lib/probe-theme.mjs@@ -161,17 +161,43 @@ export function renderProbeTheme({components, coverage}) {return `// Copyright (c) Meta Platforms, Inc. and affiliates.// @generated by .github/scripts/visual-gate/generate-probe-theme.mjs — do not edit.//-// A theme that styles EVERY declared theming target, so the visual gate can-// prove each one still reaches the pixels. Not shipped; not published; a test-// fixture. Regenerate with: pnpm visual:probe-theme+// A theme that exercises EVERY axis of the theme contract, so the visual gate+// can prove each one still reaches the pixels. Not shipped; not published; a+// test fixture. Regenerate with: pnpm visual:probe-theme//-// Coverage: ${coverage.targets} targets, ${coverage.selectors} selectors.+// defineTheme takes six things and this covers all six:+// components ${coverage.targets} targets, ${coverage.selectors} selectors (generated from the docs)+// tokens custom properties, read back off the themed element+// icons every registry entry swapped for a marked glyph+// indicators check / radio / checkbox swapped — the swap that reaches furthest+// fonts a family name nothing else could produce+// syntax one unmistakable colour per code token+//+// Only \`components\` is generated; the rest are fixed values that live in+// probeConfig.ts, because they are a contract to assert against rather than a+// projection of the component docs.++import {defineSyntaxTheme, defineTheme} from '@astryxdesign/core/theme';-import {defineTheme} from '@astryxdesign/core/theme';+import {PROBE_FONT, PROBE_SYNTAX, PROBE_TOKENS} from './probeConfig';+import {probeIconRegistry, probeIndicatorRegistry} from './registries';export const probeTheme = defineTheme({name: 'probe',+ tokens: PROBE_TOKENS,+ typography: {+ body: {family: 'AstryxProbeFace', fallbacks: 'monospace'},+ heading: {family: 'AstryxProbeFace', fallbacks: 'monospace'},+ code: {family: 'AstryxProbeFace', fallbacks: 'monospace'},+ },+ syntax: defineSyntaxTheme({name: 'probe', tokens: PROBE_SYNTAX}),+ icons: probeIconRegistry,+ indicators: probeIndicatorRegistry,components: ${JSON.stringify(components, null, 2).replace(/\n/g, '\n ')},});++// Re-exported so a consumer of the fixture (the gate, a story) can assert+// against the same values the theme was built from, rather than a copy.+export {PROBE_FONT, PROBE_SYNTAX, PROBE_TOKENS};`;}diff --git a/packages/themes/probe/package.json b/packages/themes/probe/package.jsonindex 939c192e5b..3f3b2be765 100644--- a/packages/themes/probe/package.json+++ b/packages/themes/probe/package.json@@ -20,7 +20,7 @@"src"],"scripts": {- "build": "rimraf dist && tsup && tsc --project tsconfig.build.json && node ../../../scripts/check-fully-specified.mjs"+ "build": "rimraf dist && astryx theme build src/probeTheme.ts -o dist/theme.css --icons-specifier ./registries.mjs && tsup && tsc --project tsconfig.build.json && node ../../../scripts/check-fully-specified.mjs"},"peerDependencies": {"@astryxdesign/core": "0.5.0",@@ -28,7 +28,8 @@},"devDependencies": {"rimraf": "^6.0.1",- "tsup": "^8.3.0"+ "tsup": "^8.3.0",+ "@astryxdesign/cli": "0.5.0"},"module": "./dist/source.mjs"}diff --git a/packages/themes/probe/src/probeConfig.ts b/packages/themes/probe/src/probeConfig.tsnew file mode 100644index 0000000000..0645854b1d--- /dev/null+++ b/packages/themes/probe/src/probeConfig.ts@@ -0,0 +1,43 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+// @generated by .github/scripts/visual-gate/generate-probe-theme.mjs — do not edit.+//+// The non-component axes of the probe theme, generated from+// .github/scripts/visual-gate/lib/probe-axes.mjs.++import type {SyntaxThemeTokenInput} from '@astryxdesign/core/theme';++/** Tokens the probe overrides, observable on any themed subtree. */+export const PROBE_TOKENS: Record<string, string> = {+ '--color-accent': 'rgb(255, 0, 128)',+ '--color-background-body': 'rgb(0, 32, 16)',+ '--color-text-primary': 'rgb(240, 255, 0)',+ '--color-border': 'rgb(0, 224, 255)',+ '--radius-element': '13px',+ '--spacing-4': '17px',+ '--duration-fast': '11ms',+ '--font-size-base': '15.5px',+};++/** A font stack that can only have come from the theme. */+export const PROBE_FONT = '"AstryxProbeFace", monospace';++// Not annotated: the literal keys and tuple shapes ARE the contract+// (SyntaxThemeTokenInput requires all fourteen), so widening this to a Record+// would hide a missing token behind a type that accepts anything.+/** Syntax-token colours as [light, dark] pairs, one unmistakable value each. */+export const PROBE_SYNTAX: SyntaxThemeTokenInput = {+ keyword: ['hsl(0 100% 45%)', 'hsl(0 100% 65%)'],+ string: ['hsl(26 100% 45%)', 'hsl(26 100% 65%)'],+ comment: ['hsl(51 100% 45%)', 'hsl(51 100% 65%)'],+ number: ['hsl(77 100% 45%)', 'hsl(77 100% 65%)'],+ function: ['hsl(103 100% 45%)', 'hsl(103 100% 65%)'],+ type: ['hsl(129 100% 45%)', 'hsl(129 100% 65%)'],+ variable: ['hsl(154 100% 45%)', 'hsl(154 100% 65%)'],+ operator: ['hsl(180 100% 45%)', 'hsl(180 100% 65%)'],+ constant: ['hsl(206 100% 45%)', 'hsl(206 100% 65%)'],+ tag: ['hsl(231 100% 45%)', 'hsl(231 100% 65%)'],+ attribute: ['hsl(257 100% 45%)', 'hsl(257 100% 65%)'],+ property: ['hsl(283 100% 45%)', 'hsl(283 100% 65%)'],+ punctuation: ['hsl(309 100% 45%)', 'hsl(309 100% 65%)'],+ background: ['hsl(334 100% 45%)', 'hsl(334 100% 65%)'],+};diff --git a/packages/themes/probe/src/probeTheme.ts b/packages/themes/probe/src/probeTheme.tsindex 60c6287a2b..f3fdaa9090 100644--- a/packages/themes/probe/src/probeTheme.ts+++ b/packages/themes/probe/src/probeTheme.ts@@ -1,16 +1,38 @@// Copyright (c) Meta Platforms, Inc. and affiliates.// @generated by .github/scripts/visual-gate/generate-probe-theme.mjs — do not edit.//-// A theme that styles EVERY declared theming target, so the visual gate can-// prove each one still reaches the pixels. Not shipped; not published; a test-// fixture. Regenerate with: pnpm visual:probe-theme+// A theme that exercises EVERY axis of the theme contract, so the visual gate+// can prove each one still reaches the pixels. Not shipped; not published; a+// test fixture. Regenerate with: pnpm visual:probe-theme//-// Coverage: 268 targets, 865 selectors.+// defineTheme takes six things and this covers all six:+// components 268 targets, 865 selectors (generated from the docs)+// tokens custom properties, read back off the themed element+// icons every registry entry swapped for a marked glyph+// indicators check / radio / checkbox swapped — the swap that reaches furthest+// fonts a family name nothing else could produce+// syntax one unmistakable colour per code token+//+// Only `components` is generated; the rest are fixed values that live in+// probeConfig.ts, because they are a contract to assert against rather than a+// projection of the component docs.++import {defineSyntaxTheme, defineTheme} from '@astryxdesign/core/theme';-import {defineTheme} from '@astryxdesign/core/theme';+import {PROBE_FONT, PROBE_SYNTAX, PROBE_TOKENS} from './probeConfig';+import {probeIconRegistry, probeIndicatorRegistry} from './registries';export const probeTheme = defineTheme({name: 'probe',+ tokens: PROBE_TOKENS,+ typography: {+ body: {family: 'AstryxProbeFace', fallbacks: 'monospace'},+ heading: {family: 'AstryxProbeFace', fallbacks: 'monospace'},+ code: {family: 'AstryxProbeFace', fallbacks: 'monospace'},+ },+ syntax: defineSyntaxTheme({name: 'probe', tokens: PROBE_SYNTAX}),+ icons: probeIconRegistry,+ indicators: probeIndicatorRegistry,components: {'alert-dialog': {base: {@@ -5740,3 +5762,7 @@ export const probeTheme = defineTheme({},},});++// Re-exported so a consumer of the fixture (the gate, a story) can assert+// against the same values the theme was built from, rather than a copy.+export {PROBE_FONT, PROBE_SYNTAX, PROBE_TOKENS};diff --git a/packages/themes/probe/src/registries.tsx b/packages/themes/probe/src/registries.tsxnew file mode 100644index 0000000000..55c0deaeb2--- /dev/null+++ b/packages/themes/probe/src/registries.tsx@@ -0,0 +1,127 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Probe replacements for the two registry axes: icons and indicators.+ *+ * A registry swap is not verifiable by looking at pixels. `defineTheme({icons})`+ * and `defineTheme({indicators})` replace a COMPONENT by name, and a+ * replacement can easily paint something a diff cannot distinguish from the+ * default. So each replacement announces itself with a `data-*` marker, and the+ * check asks whether the marker is in the DOM.+ *+ * That makes the assertion exact: the marker can only be there if the registry+ * entry was consulted and the replacement was chosen. `defineTheme({indicators})`+ * is the swap that reaches furthest — replace `check` and every component that+ * renders a selection mark follows — and until this file nothing tested it.+ *+ * Not a design. These render as visible labelled boxes on purpose: a probe that+ * looked plausible would be a probe you could not tell had failed.+ */++import * as React from 'react';+import {getIconRegistry} from '@astryxdesign/core/Icon';+import type {IconName, IconRegistry} from '@astryxdesign/core/Icon';+import type {+ IndicatorProps,+ IndicatorRegistry,+} from '@astryxdesign/core/Indicator';++/** Keep in sync with .github/scripts/visual-gate/lib/probe-axes.mjs. */+const SWAP_ATTR = 'data-astryx-probe-swap';++/**+ * The glyph every themed icon becomes under the probe theme.+ *+ * `aria-hidden` because it is decorative, and because the components that host+ * icons already own the accessible name — a probe that injected one would be+ * testing itself rather than the swap.+ */+function ProbeGlyph(props: {size?: number | string}) {+ const {size = '1em'} = props;+ return (+ <svg+ {...{[SWAP_ATTR]: 'icon'}}+ aria-hidden="true"+ width={size}+ height={size}+ viewBox="0 0 16 16"+ fill="none">+ <rect+ x="1"+ y="1"+ width="14"+ height="14"+ fill="#ff0080"+ stroke="#00e0ff"+ strokeWidth="2"+ />+ <path d="M4 8h8M8 4v8" stroke="#f0ff00" strokeWidth="2" />+ </svg>+ );+}++/**+ * Every icon the default registry serves, replaced.+ *+ * Reflects over the live registry rather than listing names: a hand-written+ * list silently stops covering an icon the day someone adds one, which is+ * exactly the drift this fixture exists to prevent. An `IconRegistry` maps a+ * name to a rendered node, not to a component, so these are elements.+ */+export const probeIconRegistry: IconRegistry = Object.fromEntries(+ (Object.keys(getIconRegistry()) as IconName[]).map(name => [+ name,+ <ProbeGlyph key={name} />,+ ]),+) as IconRegistry;++/**+ * An indicator replacement that draws its state as a letter.+ *+ * The state is rendered as text so the check can tell WHICH state was passed,+ * not merely that something replaced the default — an indicator that swapped+ * correctly but was handed the wrong state is a real bug and would otherwise+ * look identical.+ */+function makeProbeIndicator(kind: string) {+ return function ProbeIndicator({+ state,+ size = 'md',+ isDisabled,+ ...rest+ }: IndicatorProps) {+ return (+ <span+ {...rest}+ {...{[SWAP_ATTR]: 'indicator'}}+ data-probe-indicator={kind}+ data-probe-state={String(state)}+ aria-hidden="true"+ style={{+ display: 'inline-flex',+ alignItems: 'center',+ justifyContent: 'center',+ width: size === 'sm' ? 12 : 16,+ height: size === 'sm' ? 12 : 16,+ background: '#ff0080',+ color: '#f0ff00',+ border: '2px solid #00e0ff',+ fontSize: 9,+ lineHeight: 1,+ opacity: isDisabled ? 0.4 : 1,+ }}>+ {String(state).charAt(0).toUpperCase()}+ </span>+ );+ };+}++/**+ * Every indicator the theme contract can swap.+ * <!-- SYNC: packages/core/src/Indicator/types.ts (IndicatorMap) -->+ */+export const probeIndicatorRegistry: IndicatorRegistry = {+ check: makeProbeIndicator('check'),+ radio: makeProbeIndicator('radio'),+ checkbox: makeProbeIndicator('checkbox'),+};diff --git a/packages/themes/probe/tsup.config.ts b/packages/themes/probe/tsup.config.tsindex 9b99b9fbd7..827ee2ef02 100644--- a/packages/themes/probe/tsup.config.ts+++ b/packages/themes/probe/tsup.config.ts@@ -3,7 +3,7 @@import {defineConfig} from 'tsup';export default defineConfig({- entry: ['src/source.ts'],+ entry: ['src/source.ts', 'src/registries.tsx'],format: ['cjs', 'esm'],dts: false,clean: false,diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 62653333b5..b164ffd00c 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -900,6 +900,9 @@ importers:specifier: '>=19'version: 19.2.7devDependencies:+ '@astryxdesign/cli':+ specifier: 0.5.0+ version: link:../../clirimraf:specifier: ^6.0.1version: 6.1.3