Skip to content

test(infra): resolve the real tokens under vitest instead of a drifted stub (#944) - #947

Merged
thinkclay merged 1 commit into
mainfrom
fix/944-token-mock
Oct 2, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/944-token-mock

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #944. Clears the way for #833, whose whole job is auditing these tokens in dark.

What changed

vitest.config.ts aliased @scaffald/ui/tokens to a hand-maintained stub. The alias now points at packages/ui/src/tokens and the stub is deleted — 226 lines of it.

There was never a technical reason for the stub. The token modules are plain data with no react-native, expo, Platform or Dimensions import between them, so they load in jsdom as-is. Its git history is a series of commits called "expand token mock" and "expand beyond-ui token coverage" — people hitting a missing token and adding it by hand, one at a time.

It had drifted both ways

Real tokens The stub
borderRadius xxs 2, xs 4, s 4, m 4, l 7, xl 7, xxl 7 xxs 4, xs 6, s 8, m 10, l 12, xl 16, xxl 20
cool grey ramp zinc slate, and no zinc

The radius scale was the pre-#621 one. Nothing asserts on those numbers today, which is the only reason it went unnoticed — but any test that started asserting a radius would have asserted the wrong one and looked correct.

slate is the dangerous direction: it existed only in the stub, so colors.slate[500] passed every test and was undefined in production. Nothing in the repo turned out to depend on it, so removing it cost nothing.

The missing direction is what surfaced this during #820. A real token absent from the stub reads as undefined, and at module scope it kills the whole suite on import with a stack pointing at the feature file:

TypeError: Cannot read properties of undefined (reading '500')
 ❯ EEOReportScreen.tsx:80   two_or_more: colors.zinc[500],

Lines 78 and 79 of the same object literal resolved fine, because the stub happened to carry amber and emerald. So the first guess is always that the feature code is wrong.

The guard, and proof that it guards

packages/scf-core/__tests__/tokens-alias-is-real.test.ts sits beside the two existing tests that police the test infrastructure (no-duplicate-vi-mock, vi-mock-paths-resolve). It asserts the real radius scale, the six-step type scale, that zinc resolves, that slate does not, and that text[theme].quaternary flips.

A guard that passes proves nothing on its own, so I pointed the alias at a stub shaped like the old one:

 × carries ramps that no stub was ever hand-updated with
 × does not invent ramps the app lacks
 × reports the post-#621 interface radius scale
 × reports the six-step type scale
 × carries the theme dimension, so inverse text can flip with its fill
 Tests  5 failed (5)

Pointed it back: 5 passed. Then removed the temporary stub.

Verification

8 projects, 2137 tests, 0 failures — scf-core 1272, ui 714, app 98, schemas 53. Every suite now runs against production token values, and none of them needed changing, which is the useful finding: no test was quietly relying on the stub's wrong numbers.

@scaffald/integration-test fails for want of a local Supabase on :54321 (Docker isn't running here). I reproduced that on unmodified main before attributing it, and it is excluded from every repo script including test:unit and check.

pnpm prepush green.

Note on the diff

vitest.config.ts is 13 changed lines, not 118. My first commit ran biome check --write on it, which rewrote the whole file's quote style and semicolons — the file is double-quoted on main and biome's config prefers single. That is pure churn in a config other sessions touch, so I reverted it and re-applied the alias change by hand.

🤖 Generated with Claude Code

…d stub (#944)

Closes #944.

`vitest.config.ts` aliased `@scaffald/ui/tokens` to a hand-maintained stub.
There was never a technical reason for it — `packages/ui/src/tokens` is plain
data modules with no react-native, expo, Platform or Dimensions import between
them, so they load in jsdom as-is. The alias now points at the source and the
stub is deleted.

It had drifted from production in both directions:

- Its `borderRadius` was still the PRE-#621 scale (xs 6, s 8, l 12, xl 16)
  against the real 2 / 4 / 7. Nothing asserted on those numbers, which is the
  only reason it went unnoticed — any test that started asserting a radius
  would have asserted the wrong one and looked right.
- It carried a `slate` ramp the real tokens do not have, and lacked `zinc`,
  which they do. So `colors.slate[500]` passed every test and was `undefined`
  in the app. A stub more permissive than reality is the dangerous direction;
  nothing in the repo turned out to depend on `slate`.

The missing direction is what surfaced it: a real token absent from the stub
reads as `undefined`, and at module scope it kills the whole suite on import
with a stack pointing at the feature file, so the first guess is that the
feature code is wrong. That cost a detour during #820.

`packages/scf-core/__tests__/tokens-alias-is-real.test.ts` is the guard, next
to the other two tests that police the test infrastructure. Verified that it
actually guards rather than merely passing: pointed the alias at a stub shaped
like the old one and all five assertions failed; pointed it back and all five
passed.

8 projects, 2137 tests, 0 failures (scf-core 1272, ui 714, app 98, schemas 53).
`@scaffald/integration-test` fails for want of a local Supabase on :54321 —
reproduced identically on unmodified main, and it is excluded from every repo
script including `test:unit` and `check`.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit f751c28 into main Oct 2, 2026
10 checks passed
@thinkclay
thinkclay deleted the fix/944-token-mock branch October 2, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The vitest token mock has drifted from the real tokens in both directions

1 participant