Skip to content

Direct push to main: ac49dbd0 #747

Closed

Description

@github-actions

ac49dbd072519b2126550e79ef1fbabe65949239 landed on main without a merged pull request.

Author @thinkclay
Commit ac49dbd0
Message test(api): guard the response envelope, which no mock written from a type can catch (#746)

Some routes wrap their success body in { data } and some return it bare. The
http client returns the parsed body verbatim, so a method declaring
Promise<UserProfile> against a wrapping route actually resolves to
{ data: UserProfile }. TypeScript never notices, because the generic is
asserted — this.get<UserProfile>(...) — rather than inferred from the wire.
And the msw handlers are written from the declared types, so the suite agrees
with the type while the type disagrees with the API.

That combination has produced three wrong contracts a green suite certified:
Scaffald/sdk#21 (employers), #26 (organizations), #29 (getUser). The check has
to compare the route to the SDK, because comparing either to a fixture cannot
see it.

sdk-envelopes.test.ts parses both sides and fails on any pair that disagrees,
with a baseline enforced in both directions like its sibling — a new mismatch
fails, and so does a stale entry.

11 genuine mismatches are baselined. Which side moves is a public-API
decision (#744), not something to settle inside a test.

Getting that number right took three corrections, all of which are why the
guard looks the way it does:

  • "has a top-level data key" is too loose. It classified
    PrerequisitesCheckResponse as wrapped — that type has a data field among
    a dozen domain fields — and a live probe of /v1/prerequisites/check
    confirmed the body is bare. An envelope is data plus nothing but
    pagination/metadata keys.

  • 39 SDK methods across six resources unwrap the envelope themselves
    (const res = await this.get<X>(p); return res.data). Their declared type
    describes the inner payload and is correct because the route wraps.
    Comparing their declared type to the route reported all of them as broken;
    11 of my first 22 baseline entries were this false positive.

  • return c.json({ data }, 200) is shorthand for { data: data }. Requiring
    a colon to read a key called two correct routes bare.

Verified by attacking it rather than trusting a green run: flipping
legal.getCurrent to an envelope fails with "sdk says wrapped, route says bare",
and adding a baseline entry for a pair that agrees fails with "now agrees;
remove it". Both pass again once reverted.

Also bumps the sdk pointer to pick up #28 and #29. #743 should have carried
git submodule update --init --recursive and reset the submodule back to the
recorded commit after I had checked out the merged one. So main has been
carrying the honest route schema from #743 with the SDK type that contradicts
it.

Refs #744

Co-authored-by: Claude Opus 5 [email protected] |

This was caught after the fact — main is not protected server-side,
because the org's GitHub plan does not support rulesets on private
repositories. The apply-ready ruleset is committed at
.github/rulesets/main.json.

If this was an accident, open a PR that reverts it.
If it was deliberate, close this issue with a note saying why, so
the signal stays meaningful.

Activity

  1. added
    bug
    on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions