Skip to content

feat(aria-spec): prototype APG conformance contracts (Switch, both tiers) - #4113

Closed
cixzhang wants to merge 7 commits into
mainfrom
feat/aria-spec-prototype
Closed

cixzhang wants to merge 7 commits into
mainfrom
feat/aria-spec-prototype

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Prototype for #4112 — proving the ARIA-spec architecture end-to-end on one pattern (Switch) before authoring the rest.

What this is

An internal, unpublished @astryxdesign/aria-spec package that encodes WAI-ARIA APG patterns once as data-driven conformance contracts, then binds components to them — so "which APG patterns are covered, across which components?" is a coverage matrix, not assertions scattered across ~120 test files.

The core idea: one contract, two tiers

Expectations are authored against an abstract AriaHarness, so the same contract runs in:

  • Tier 1 — jsdom (createJsdomHarness): Testing Library + user-event. Fast, runs in the existing pnpm test. Covers role/name/state/keyboard-logic.
  • Tier 2 — real Chromium (createBrowserHarness): Vitest Browser Mode + Playwright. Covers what jsdom can only fake — the real accessibility tree (toMatchAriaSnapshot), focus trapping, inert, top layer, :focus-visible.

Fidelity-critical expectations (e.g. switch-aria-snapshot) are a tracked gap in Tier 1 and pass in Tier 2 — the same contract, honest about what each runtime can prove.

expectedFailures — adoption without a wall of red

A binding declares known gaps by expectation id; each is an explicit, greppable line, not a missing test. A gap that later passes surfaces as unexpected-pass so stale entries get cleaned up. This is what lets the contract roll across all 122 components immediately.

What's here

Piece File
Types + AriaHarness seam internal/aria-spec/src/types.ts
jsdom (Tier 1) + browser (Tier 2) adapters src/harness/*
Runner (isolation, priorities, expectedFailures) src/runner/runContract.ts
Coverage matrix (0-100 score) src/report/coverage.ts
Switch pattern contract (reference) src/patterns/switch.ts
Switch bindings, both tiers packages/core/src/Switch/Switch.aria*.test.tsx
Proposed gated CI job internal/aria-spec/CI.md

Verified

  • ✅ Tier 1 runs in the ui project: [100%] switch/Switch (6/8, jsdom) — 2 known-gap
  • ✅ Contract catches regressions — a deliberately broken switch flags switch-labelled, switch-1 (Space), switch-click-toggles, switch-focusable as blocking failures
  • ✅ Existing Switch.test.tsx (40 tests) still green; browser test correctly excluded from the jsdom project
  • ✅ Package typechecks (strict); lint clean (0 errors)
  • ⚠️ Tier 2 config boots Chromium and reaches browser launch; the actual browser run needs pnpm add -Dw @vitest/browser @vitest/browser-playwright vitest-browser-react && pnpm exec playwright install --with-deps chromium on a runner that can fetch the binary (couldn't complete in the dev sandbox)

Relationship to existing a11y CI

The existing pr-a11y job already runs axe (static rules) against Storybook. aria-spec complements it with behavior + pattern conformance (keyboard, focus, real aria tree) — axe cannot do any of that. The proposed Tier 2 job (in CI.md) is gated on component changes, Chromium-only, cached, and should gate the build only on blocker expectations.

Not in this PR (follow-ups from #4112)

  • vitest-axe structural pass wired into the runner
  • Pixel screenshots for focus/contrast states
  • The remaining ~22 patterns
  • Migrating the existing ad-hoc APG-tagged assertions (switch-1, checkbox-42, menus-*) into contracts
  • Coverage dashboard

Kept as a draft for architecture review before scaling to all patterns.

@vercel

vercel Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 14, 2026 1:55am

Request Review

},
},
{
id: 'switch-aria-snapshot',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of a snapshot test? Does it check a specific property listed in WCAG? Or is it adhering to specific principles?

@github-actions

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Switch (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 469 -
Complexity N/A Very High (44) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

cixzhang and others added 7 commits August 13, 2026 18:52
… both tiers)

Adds internal, unpublished @astryxdesign/aria-spec: WAI-ARIA APG patterns
encoded once as data-driven conformance contracts, bound to components.

- types + AriaHarness (runtime seam), jsdom (Tier 1) and browser (Tier 2) adapters
- runContract with priority tiers + expectedFailures (tracked, greppable gaps)
- coverage matrix (pattern x component, 0-100 score)
- switch pattern authored; Switch bound in both tiers (jsdom in `pnpm test`,
  browser via `pnpm test:aria-browser`)
- proposed gated CI job documented in internal/aria-spec/CI.md (complements the
  existing axe audit with behavior + pattern conformance)

Prototype for #4112.
CI wiring belongs in the PR description, not a committed doc.
Every expectation now carries a required `criteria` (WCAG SC or APG clause) and
prefixes its test name with the citation via specLabel(), so results trace to a
specific normative requirement. Adds a "Creating a new spec test" guide to the
README: principles (trace-to-clause, broad vs pattern-specific layers, Level A
scoping, encode-or-excuse), a WCAG 2.2 + APG completeness checklist, tier
awareness, and a definition of done.
- add switch-disabled-state and switch-disabled-not-activatable expectations
  (a disabled switch must expose its state and must not toggle on activation)
- add a disabled-Switch binding proving both; document pattern exemptions
- skill: classify each checklist row by verification method (contract / lint /
  browser / manual) — not every requirement is a contract expectation
APG switch must toggle on AND back off; Space and click expectations now
verify both transitions, not just off->on. Closes the last contract-encodable
gap from the switch a11y review.
packages/core reached into internal/aria-spec/src by relative path and
resolved `@astryxdesign/aria-spec` through a Vitest alias only, so the
package existed for the test runner but not for TypeScript. Core's
typecheck therefore failed three ways at once: TS2307 on the bare
specifier, TS6059 on the relative import (internal/ is outside core's
rootDir), and a wave of TS7006 implicit-any where the unresolved import
poisoned the result types. The same any-typed values tripped
@typescript-eslint/promise-function-async ({allowAny: false}) five times
in Switch.aria.test.tsx, which is the lint job's failure too.

Wire it the way the repo wires a package instead:

- an exports map with a `types` condition, so consumers resolve
  declarations (exempt from the rootDir rule) while the test runner still
  loads `src/` — no build step on the `pnpm test` path;
- `./browser` as a second entry point, keeping the Tier 2 harness (and
  its Browser Mode imports) out of the jsdom tier's module graph;
- its own tsconfig + tsconfig.build.json emitting declarations only,
  built first by the root `pnpm build` so the typechecks that follow it
  in CI see them;
- `@astryxdesign/aria-spec: workspace:*` declared by packages/core, and
  the alias crutch dropped from both Vitest configs.

Also drops a `return await` outside try/catch that @typescript-eslint/
return-await only started seeing once the types resolved.
The browser harness called `page.elementLocator(el).ariaSnapshot()`, which
does not exist: Vitest's in-browser Locator has no such method (TS2339,
the last build-storybook error), and Vitest exposes the accessibility tree
only through the `toMatchAriaSnapshot` matcher, which asserts rather than
returning the tree. The tree is Playwright's, and Playwright lives in the
Node process.

Bridge to it with a browser command — the supported mechanism — and let
the harness address its target by marking it in the DOM. The accessible
name now comes from that same real tree instead of an aria-label/
textContent guess that reported a labelled `<input role="switch">` as
nameless.

Three fixes the tier needed before it could run at all, all found by
actually running it (`pnpm test:aria-browser`, real Chromium):

- the command must locate through the tester `iframe`, not the
  orchestrator page, or it waits forever for a selector that is not there;
- `render` from vitest-browser-react 2.x is async, so setup has to await
  it (the old `void render(...)` raced every first query);
- the binding passed no `teardown`, so mounts piled up and every role
  query hit a Playwright strict-mode violation from the second
  expectation on. Cleanup between expectations, as in the jsdom tier.

Also pins React in the browser config: without dedupe/optimizeDeps the
run loaded two React copies and every render threw "Cannot read
properties of null (reading 'useId')".

Tier 2 now passes end to end; the aria-snapshot expectation is a real
pass in Chromium and stays a tracked gap in jsdom. The stale @ts-expect-
error directives (TS2578) go with it, and the header no longer claims a
CI job that does not exist.
@cixzhang

Copy link
Copy Markdown
Contributor Author

Closing this. Since July the rubric, the score ledger and Night Watch own per-component a11y coverage with screenshots, and on Switch — the reference binding — everything this contract asserts is already in Switch.test.tsx except one line:

await user.keyboard(' ');

The two it can't do in jsdom are expectedFailures, and the browser tier isn't wired into CI, so tier 1 buys one assertion for a new package, a second test runner and a CI job. Landing the Space test and folding the coverage matrix into the ledger gets what #4112 wanted for far less.

@cixzhang cixzhang closed this Aug 16, 2026
@github-actions
github-actions Bot deleted the feat/aria-spec-prototype branch August 17, 2026 06:14
@astracat-bot astracat-bot Bot mentioned this pull request Nov 5, 2026
7 of 8 tasks

This branch was successfully deployed

1 active deployment
Preview — 4250fc48 Deployed Aug 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant