# Shipped parity checks

> Check that the UI you ship matches the approved design, locally and in CI: setup, configuration, results, decisions and the Shipped tab.

Approving a design is half the job. The shipped parity check tells you whether what you shipped is what was approved. It
renders the approved design and your running app **in the same browser**, with the same viewport, scale, locale,
timezone and reduced motion, and reports what differs, element by element: size, spacing, colours, type, corner radius,
shadows, and missing or hidden elements. Each difference names the design token it should use. A pixel diff is attached
as evidence. No AI model runs during the check, so the same app always gives the same result.

## Run it locally

```bash
npm i -D @specimo/check playwright-core
npx playwright install chromium
SPECIMO_TOKEN=adp_… npx specimo-check --base-url http://localhost:3000
```

With the Specimo CLI installed, `specimo check` does the same. The token is a project token with **read & write** scope
(Project → Connect agent), so results appear in Specimo.

By default every approved screen that has a route is checked at desktop width in the light theme. Narrow it down or add
scenarios:

```bash
specimo check --screen checkout --viewport desktop --viewport mobile --theme light --theme dark
specimo check --version latest     # compare with a draft that is still in review
specimo check --no-upload          # keep the results on your machine
```

## Add it to CI

Project settings → Repositories → **Set up the shipped parity check…** gives you a ready GitHub Actions workflow or
GitLab CI job: it builds and starts your app, waits for it, runs the check and keeps the report as an artifact. Store
the project token as the CI secret `SPECIMO_TOKEN`. On GitHub the job skips pull requests from forks, which get no
secrets.

The job writes a summary to the pull request run: one row per screen, the most important differences first, and a link
to each screen's **Shipped** tab in Specimo.

## Also check preview deploys (GitHub, public previews)

The CI job above works with any hosting, because it starts your app inside CI. If your previews are already deployed
somewhere public, Specimo can also check them on its side, with no job in your repository. This needs **all** of:

- **GitHub.** Specimo reacts to GitHub *deployment statuses*. GitLab isn't supported for this; use the CI job.
- **Your hosting reports previews to GitHub.** Vercel and Netlify do when their GitHub app is installed, and so do some
  others. AWS, Google Cloud or a custom pipeline can report them with one step (below).
- **Public https previews.** A preview behind a password, SSO or deployment protection (for example Vercel's) answers
  401 to Specimo: the run says the preview is protected. Make previews public for Specimo, or use the CI job.
- **Pro or Business.** Preview checks per hour depend on the plan.

Then: connect the GitHub repository (Project settings → Repositories), tick **Deployment statuses** in its webhook, and
turn on **Check preview deploys**. The settings show whether a preview has arrived and why the last one couldn't be
checked. To check one URL by hand, paste it in any screen's **Shipped** tab under **Check a deployed preview now**.

Every approved screen with a route is checked in its default state. Production deployments, failed deployments and
private or non-https addresses are skipped. Preview checks only ever warn: to block a pull request, use the CI job.

### Report previews from any CI

If you deploy previews yourself (AWS, Google Cloud, Kubernetes…), add this step after your deploy step in GitHub
Actions. It tells GitHub (and so Specimo) where the preview is:

```yaml
permissions:
  deployments: write
# … after the step that deploys the preview and outputs its URL:
      - name: Report the preview to GitHub
        uses: actions/github-script@v7
        env:
          PREVIEW_URL: ${{ steps.deploy.outputs.url }} # adjust to your deploy step
        with:
          script: |
            const { owner, repo } = context.repo;
            const ref = context.payload.pull_request?.head.sha ?? context.sha;
            const d = await github.rest.repos.createDeployment({ owner, repo, ref, environment: 'Preview', transient_environment: true, production_environment: false, auto_merge: false, required_contexts: [] });
            await github.rest.repos.createDeploymentStatus({ owner, repo, deployment_id: d.data.id, state: 'success', environment_url: process.env.PREVIEW_URL });
```

## Configure it

Settings live in `.specimo.json` at the root of your repository:

```json
{
  "api": "https://api.specimo.design",
  "project": "Shop",
  "check": {
    "baseURL": "http://localhost:3000",
    "viewports": ["desktop", "mobile"],
    "themes": ["light", "dark"],
    "screens": { "checkout": { "route": "/checkout", "version": 3 } },
    "checks": { "parity": { "severity": "warning", "maxDiffRatio": 0.02 } }
  }
}
```

| Setting | What it does |
| --- | --- |
| `baseURL` | Where your app runs during the check. |
| `screens.<key>.route` | The app's path for a screen, when it differs from the route in Specimo or the screen has none. |
| `screens.<key>.version` | Pin a design version for reproducible builds. Without it, the latest approved version is used. |
| `checks.parity.severity` | `warning` (default), `error` (blocks the pull request) or `off`. |
| `checks.parity.maxDiffRatio` | Share of pixels allowed to differ before the pixel diff counts as a difference (default 2 %). |
| `checks.states.severity` | Approved states (loading, empty, error…) that no scenario checked: `warning` (default), `error` or `off`. |
| `checks.accessibility.severity` | axe-core on the app, with violations the approved design doesn't have called out as regressions, and accessible names the app lost: `warning` (default), `error` or `off`. |
| `checks.accessibility.stress` | `true` (or a list of `"focus"`, `"text"`, `"rtl"`) adds stress passes: keyboard Tab order and focus indicators, text at 200% size, and right-to-left. Only what the app gets wrong and the approved design doesn't is reported. Off by default. |
| `checks.tokens.severity` | Colours and sizes in the app that match no design token and appear nowhere in the design: `warning` (default), `error` or `off`. |
| `checks.components.severity` | Places where the design uses a design-system component and the app renders its own markup instead: `warning` (default), `error` or `off`. |
| `checks.copy.severity` | Visible text against the approved copy: static design text always, and text from mock data when an adapter feeds the same data. `off` (default), `warning` or `error`. |
| `locales` | Check in more languages: `["de", "fr"]`, or `"all"` for every locale in the project's Strings (also `--locale de`). Each locale is its own scenario: the design renders in that locale, the app gets it through the browser language and `Accept-Language`. Findings name the locale. |
| `localePath` | When your app picks the language from the URL instead: `"/{locale}/{route}"`. |
| `checks.themes.severity` | A dark theme in the design that wasn't checked, and desktop-only runs: `warning` (default), `error` or `off`. |
| `adapters.strict` | In adapter scenarios, calls to your app's own API that no mock handled are always listed ("GET /api/user wasn't mocked by the empty scenario"). `true` also blocks them, so a state can't quietly use real data. |
| `adapters.apis` | Other API origins to watch besides the app's own, e.g. `["https://api.example.com"]`. |
| `components.<key>.checks` | Overrides for every element the design marks as that design-system component (for example `"button": { "checks": { "parity": { "severity": "error" } } }`). Screen overrides and the project minimum still win. |
| `components.<key>.ignore` | Properties to skip on that component, as globs: `["padding*", "box-shadow"]`. |
| `screens.<key>.checks` | Per-screen overrides with the same shape as `checks`, e.g. `{ "copy": { "severity": "error" } }` for a screen whose text is final. |
| `checks.drift.severity` | A screen pinned with `screens.<key>.version` has a newer approved version: `warning` (default), `error` or `off`. |

### Project minimum (Business)

In Specimo, **Project settings → Shipped parity policy** sets the lowest severity each check may have in this project.
Repositories can make a check stricter in `.specimo.json`, never weaker: if the project says accessibility is at least
`error`, a repository that sets `warning` or `off` still gets `error`, and the report says the project raised it.
Only people who manage the project's settings can change the minimum, and every change is in the audit log.

## Check only the affected screens

On a large app, `--affected` checks only the screens a pull request can have changed:

```bash
npx @specimo/check --base-url http://localhost:3000 --affected --base origin/main
```

A screen is picked when a changed file serves its route (`app/checkout/page.tsx`, `pages/orders/[id].tsx`,
`routes/settings/+page.svelte`), matches `check.screens.<key>.paths`, or is its adapter. It's also picked when the pull
request names it (`design:checkout`), or when a newer version was approved after the base commit. The report lists each
screen with the reason.

When it can't be sure, it checks everything and says why:

- **Global inputs:** lockfiles, `.specimo.json`, fonts, token and global CSS, root layouts, and framework or Tailwind config.
- **Shared code:** a changed UI file that belongs to no screen, such as `src/components/Button.tsx`.
- **Missing history:** no git history for the base. In GitHub Actions, check out with `fetch-depth: 0`.

Docs, tests, stories and CI files never trigger a check.

With `"affected": { "graph": true }`, shared code no longer forces a full run: Specimo reads the imports in your
repository (relative paths, tsconfig `paths`, package.json `imports`, CSS `@import` and `@use`) and checks the screens
that use the changed file. If an import it can't resolve might hide a screen, or the repository is very large, it checks
everything and says why. The graph is cached between runs; on 5,000 files it takes about a quarter of a second.

| Setting | What it does |
| --- | --- |
| `screens.<key>.paths` | Globs of files that only this screen uses, e.g. `["src/features/checkout/**"]`. |
| `affected.global` | More files that affect every screen (forces a full run). |
| `affected.ignore` | Files that can't change the UI, e.g. `["src/server/**"]`. |
| `workers` | Default for `--workers`. |
| `bundleCache` | Default for `--bundle-cache`. |
| `affected.graph` | `true` follows imports: a changed shared file (a component, a hook, a stylesheet) picks only the screens whose route files import it, directly or through other files. Off by default for now. |
| `affected.base` | The default for `--base` (otherwise the PR's base branch, then `origin/main`). |

## Make it fast on big apps

- **Workers:** scenarios render in parallel, each in its own isolated browser context, in one shared browser.
  `--workers <n>` sets how many; the default is your CPU count minus one, at most 4. Results come back in the same
  order whatever the timing. On our test suite (2 screens, 3 states, 2 widths, 2 themes), 4 workers took 4.6 s against
  16.1 s with one.
- **Shards:** `--shard 2/4` checks every fourth screen, sorted by key, so the shards never overlap. Shards of the same
  GitHub Actions or GitLab CI run merge into **one** run in Specimo; elsewhere, give them a shared `--shard-group`.
  Run-wide notes come only from shard 1.
- **Bundle cache:** `--bundle-cache .specimo-cache/bundle.json` reuses the approved-design download across jobs while
  its signed links are valid.
- **Nightly:** Project settings → Repositories → Shipped parity check → **Nightly, all screens** gives a scheduled
  workflow. It runs `--all` (every approved screen, ignoring `--affected`) at desktop and mobile width, over two
  merged shards.

## Design drift

Pinning `screens.<key>.version` keeps builds reproducible: an old commit is always checked against the design it was
built for. When a designer approves a newer version, the check reports **drift** ("pinned to v3, but v5 is approved")
until the code is updated and the pin bumped.

Design-only changes don't touch your repository, so nothing would run. **Project settings → Design drift** lists the
pinned screens from the latest CI run, and can check daily (Pro and Business): each new drift notifies the screen's
watchers once and sends the `parity.drift_detected` webhook, whose payload carries a ready agent prompt. Point the
webhook at your automation to open an issue or start your coding agent.

## Native apps (iOS and Android)

The same check works for SwiftUI and Jetpack Compose apps. Your test target renders each screen and writes a snapshot
(elements with their ids, roles, labels and sizes, plus a 1× image); `specimo check` renders the approved design at the
same size and compares them:

```bash
npx @specimo/check --native ios --snapshots specimo-snapshots      # after your iOS UI tests ran
npx @specimo/check --native android --snapshots specimo-snapshots  # after ./gradlew testDebugUnitTest
```

- **iOS:** add the Swift package `https://github.com/specimodesign/specimo-ios` (from `0.1.0`): `SpecimoScreens` to the
  app (debug) and `SpecimoSnapshot` to the UI test target. A UI test launches the app on each screen and captures it.
- **Android:** add `testImplementation("com.github.specimodesign:specimo-android:0.1.0")` from JitPack
  (`maven("https://jitpack.io")`) to your JVM tests (Robolectric, no emulator) and call
  `SpecimoSnapshot.capture(rule, screen = "sign-in")` after `setContent`.
- Specimo's SwiftUI and Compose exports already tag elements with the design's ids (`accessibilityIdentifier`,
  `testTag`); give your own views the same ids for the most precise comparison.

What it checks on native: elements that are missing, changed labels and text (with `checks.copy`), lost accessible names,
control sizes for elements with ids, and control colours from the images. A pixel diff is attached as evidence; native text
never renders exactly like the web, so it only counts as a finding if you set `checks.parity.nativeMaxDiffRatio`.

**In CI:** Project settings → Repositories → **Set up the shipped parity check…** → **iOS** or **Android** gives you a
ready GitHub Actions workflow or GitLab CI job.

- **iOS:** the UI tests run on a macOS runner and pass the snapshots to a Linux job that compares them, so only the
  tests use macOS minutes (GitHub bills them at 10×). On GitLab you need a macOS runner: GitLab's hosted ones (Premium
  and Ultimate) or your own Mac.
- **Android:** one Linux job. Point the snapshot folder at the project root in your test options:
  `all { it.systemProperty("specimo.snapshots", rootProject.file("specimo-snapshots").path) }`.

Both skip pull requests from forks and keep the report as an artifact, like the web job.

## Results on the pull request (Specimo GitHub app)

Install the **Specimo GitHub app** (Project settings → Repositories → Install the Specimo app on GitHub) to see results
where you review code:

- **A check on the pull request:** "Specimo shipped parity", passed or failed, with each screen and its top differences
  and links to the Shipped tab. Sharded runs update the same check as shards arrive. You can report warnings-only runs as
  *neutral* instead of passed.
- **One comment on the pull request,** updated in place on every run, never a new one each time.
- **Preview deploys** checked on Specimo's side report the same check on their pull request, and **Re-run** checks the
  preview again.
- **Design drift** can open one issue per screen, or a pull request that only bumps the pin in `.specimo.json` (Project
  settings → Design drift). It never pushes to your default branch and never merges.

Specimo keeps only the installation id; each request uses a short-lived token from GitHub. Remove access on GitHub at any
time and Specimo disconnects the repository. Without the app, the CI job's own pass/fail status still works.

## Make it a required check

Start with warnings. Once the job has passed five pull requests in a row, **Project settings → Repositories → Shipped
parity check** says it's ready, and which checks would block. Then:

1. Set the checks that should block to `"severity": "error"` in `.specimo.json` (or set a project minimum on Business).
   While every check only warns, a required check passes whatever it finds.
2. **GitHub:** Settings → Rules → Rulesets (or Branches → Branch protection rules) → Require status checks to pass →
   add `Specimo shipped parity`. It appears in the list after the job has run once. Pull requests from forks skip the
   job because they get no secrets, and GitHub counts a skipped job as passed.
3. **GitLab:** Settings → Merge requests → Merge checks → Pipelines must succeed.

A check that can't run (app down, browser missing) exits with code 2 and fails the job; it never passes.

## Read the result

| Exit code | Meaning |
| --- | --- |
| `0` | Nothing blocking. Warnings may still be listed. |
| `1` | Blocking differences: a check is set to `error` and found something. |
| `2` | The check could not run: the app was not reachable, a page failed to load, or Chromium is missing. This is never counted as a pass. |

Findings start as **warnings**. Once the check is quiet for your team, set a check to `error` and make the CI job a
required status check to block merges.

When something blocks (exit 1) or the check can't run (exit 2), the job log ends with a **For coding agents** block:
every blocking difference (element, expected, actual, the token to use) and a ready fix prompt per screen and scenario,
or the setup problem and how to fix it. A coding agent asked to fix the red job finds everything it needs there, without
the Specimo connector. The job summary has the same block, collapsed under the table. Accepted differences are left out.

## The Shipped tab

Every screen has a **Shipped** tab. It shows the approved design next to the shipped app for each scenario (viewport,
theme, state), the differences with their tokens, a copy-ready prompt for your coding agent, and the history of runs.
The screens list shows each screen's latest result: *as designed*, *shipped differs* or *check failed*.

For each difference, someone on the team decides:

- **Accept**: the difference is intended. Approvers give a reason and, optionally, an end date. Accepted differences
  stop counting, in Specimo and in CI, until the design changes or the date passes.
- **Flag for a fix**: watchers of the screen are notified and the fix prompt is ready to hand to an agent.
- **Update design**: the shipped version is better, so a change request is created on the design.

Decisions are made by people, never by agents, and every decision is recorded in the audit log.

## Trends

The project overview shows shipped parity over time: open findings per day by group (visual, accessibility, coverage,
everything else), the share of runs without blocking findings, how many approved screens with a route were checked, and
how many differences designers accepted. Each screen's Shipped tab has the same view for that screen. "Show as table"
lists the numbers. The window follows your plan's history: up to 90 days on Pro, a year on Business.

## Check every state, with the design's data

Without help, the check sees only each screen's default state. To check loading, empty and error states, add a small
**adapter** per screen. Your coding agent writes it (MCP prompt `write_parity_adapters`):

```js
// specimo/cart.specimo.mjs
import { defineScreen } from '@specimo/check';

export default defineScreen({
  screen: 'cart',
  scenarios: {
    default: async ({ goto, mock, fixture, ready }) => { await mock.json('**/api/cart', { items: fixture.items }); await goto(); await ready('li'); },
    empty: async ({ goto, mock, fixture }) => { await mock.json('**/api/cart', { items: fixture.items }); await goto(); },
    loading: async ({ goto, mock }) => { await mock.hold('**/api/cart'); await goto(); },
    error: async ({ goto, mock }) => { await mock.status('**/api/cart', 500, { message: 'Server error' }); await goto(); },
  },
});
```

Register it in `.specimo.json` under `check.screens.cart.adapter`. Each scenario gets:

- `goto()` to open the screen's route,
- `mock` to answer requests (`json`, `status`, and `hold`, which keeps a request pending for loading states),
- `fixture`, the design's mock data for that state (the empty state gets the `empty` variant, others `typical`),
- `ready(selector)` to wait for something real.

The design side renders the same state with the same data, so the comparison is like for like. A scenario that throws
counts as "could not run", never as a pass. States the design has but no scenario covers are listed as coverage
warnings. Requests made on the server (SSR), service workers and WebSockets can't be mocked this way; use your app's own
test mode for those.

## Find hard-coded values in your code

`specimo lint tokens [paths…]` scans CSS, SCSS, TSX, JSX, Vue, Svelte and HTML (default: `src`) for colours and pixel
values that should be design tokens. A value equal to a token says which variable to use; other values get the
nearest token. It needs no browser and works on every plan. Exit code 1 when it finds something (`--warn` to report
only), `--json` for tools, and `specimo-ignore` on a line to skip it.

```bash
specimo lint tokens src
# src/Button.css:4:12  16px is the token space.4: use var(--space-4)
# src/Badge.tsx:9:30   #e11d48 matches no design token (nearest: color.danger)
```

## Make matching reliable

The check pairs each element of the design with an element of your app. It looks first at `data-specimo-id`, then at the
accessible role and name, then at the text. Specimo's code export already writes `data-specimo-id` on headings,
buttons, links, fields, landmarks and components, for example `data-specimo-id="button-pay-now"`. Keep those
attributes when you edit the code. In hand-written code, add them to the elements that matter most.

Component instances also carry `data-specimo-component="<key>"`. When you map a design-system component to your own
code, have it pass that attribute through to its root element, so the check knows the real component is used.

## Agents

Coding agents read the results with the MCP tool `get_parity_results`. The prompt `fix_parity_findings` walks them through
fixing each difference at its cause, using the token or component instead of a one-off value, and running the check
again. Agents are told never to lower a severity to make a check pass.

## Plans

| | Free | Pro | Business |
| --- | --- | --- | --- |
| Run the check on your machine or in CI, with the full local report | Yes | Yes | Yes |
| Results kept in Specimo (Shipped tab, screens list, agents over MCP) | | Yes | Yes |
| Accept, flag or update the design from a difference | | Yes | Yes |
| Preview deploy checks (fair use: up to 60 per project per hour) | | Yes | Yes |
| History kept | | 30 days (failing runs 90) | 90 days (failing runs a year) |
| Daily design drift alerts (notification + webhook) | | Yes | Yes |
| Project minimum severities repositories can't lower | | | Yes |

On Free, `specimo check` says that results aren't stored and writes the report to `specimo-report/` as usual.

## What it does not cover yet

- **Text:** off by default, because your app shows real data; turn on `checks.copy` once adapters feed the design's data, and add `locales` to check every language.
- **Accessibility:** automated checks (axe-core, plus the optional keyboard, text-size and right-to-left stress passes)
  catch only part of WCAG. Screen-reader testing still matters.
- **Native apps:** checked on one device size per snapshot, light theme unless your test passes `dark: true`. Element sizes
  are only compared for elements with ids.
