Commit 04700ea
test(hydrogen-api): assert checked-in generated types match declared API versions
Adds a unit test that fails if SF_API_VERSION or CA_API_VERSION in
api-versions.ts doesn't match the version the checked-in .d.ts files
were generated against — i.e. someone bumped a version constant
without running `pnpm graphql-types` to regenerate.
Why: the generated .d.ts files are committed to the repo so consumers
and CI get deterministic installs. That's only safe if what ships
matches what's declared. Without this check, a version bump in
isolation silently ships stale types, and `storefront.query()` calls
typecheck against the wrong schema shape.
How: extracted SF_API_VERSION and CA_API_VERSION from codegen.ts into
src/api-versions.ts as a single source of truth imported by both
codegen.ts (the writer) and src/generated-files.test.ts (the verifier).
The test reads the "Based on <API> API <version>" header codegen.ts
embeds on line 3 of each .d.ts and asserts the parsed version equals
the declared one. Uses parametrized `it.each` so each API gets its own
named test; the failure message names the file, both versions, and
the remediation command.
Unit test rather than a tsdown hook: this is an invariant on repo
state (are checked-in files fresh?), not on build output (did
bundling produce correct JS?) — it belongs with the other
`pnpm test` assertions where failures are discoverable and
compose with other invariants.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 85db71e commit 04700ea
3 files changed
Lines changed: 57 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
0 commit comments