Repository navigation
fix(api): the organization profile contract described a response it has never sent - #743
Merged
Merged
Conversation
…as never sent #617 repaired the select behind GET /v1/profiles/organizations/{slug} — it used to ask for industry, size, location and founded_year and filter on is_public, none of which exist on core.organizations — but the response schema above it was left as written. So the endpoint has been returning 200 while its published OpenAPI contract, and the SDK type generated from it, were wrong in six ways. Checked against a live response rather than reasoned about: field declared actually returned description string object (rich-text document) industry string object { id, name, slug } size string ABSENT location string ABSENT founded_year number ABSENT address - returned, undeclared Nothing broke visibly: @hono/zod-openapi documents responses rather than validating them, and no screen imports useOrganizationProfile. The SDK tests passed throughout because their msw handler hand-wrote the declared shape, so they asserted against a response the API cannot produce (fixed in Scaffald/sdk#26, pointer bumped here). size, location and founded_year are dropped rather than added. No table in any schema has those columns — a search of information_schema.columns matches nothing outside pg_catalog and storage — so keeping them would mean inventing product surface to satisfy a schema that was only ever aspirational. `address` is the real column behind what it called `location`. Verified after the change: every declared field matches the live response by type, and no undeclared field is returned. deno check on profiles.ts is unchanged at 3 errors — all pre-existing members of the TS2345 handler-response family measured in #704, two of them on routes this does not touch. One trap is recorded in the code rather than left for the next reader: supabase-js types the embedded to-one relation as an array because it cannot infer cardinality from the select string, so the static type says `industry: {...}[]` while the wire format is an object. The schema follows the wire format. Closes #482 Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
📊 Performance Benchmark Results |
This was referenced Sep 11, 2026
Closed
thinkclay
added a commit
to Scaffald/sdk
that referenced
this pull request
Sep 11, 2026
…n was red at 7 (#28) #26 moved OrganizationProfile, getOrganization() and the tests to the { data } envelope with the real columns — description and address as jsonb documents, industry as the embedded core.industries row, no size / location / founded_year — and said the msw handler was corrected alongside. It was not in the diff. The handler kept returning the bare, invented shape, so every getOrganization test destructured `data` from a body that had none: 7 failures on main, TypeError on undefined. The handler now returns what the API returns (checked against Scaffald/SaaS#743's live-response table), inside the envelope. 776/776.
This was referenced Sep 11, 2026
thinkclay
added a commit
that referenced
this pull request
Sep 11, 2026
… hid an anonymous-viewer bug (#745) Closes #482. The organizations route was fixed in #617 and its schema in #743, but profiles.test.ts still asserted the phantom contract — industry as a string, size, location, founded_year, an is_public fixture flag — so the suite stayed red at 24/27 after the code was right. The three tests now assert what the table has: industry joined through industry_id to a real core.industries row, address as the jsonb object it was stored as, and an explicit check that none of the four phantom columns come back. The fixture seeds visibility, industry_id and address, and throws on insert errors instead of returning whatever the swallowed failure left behind. Two things the old tests could never have caught surfaced on the way: The job-count test inserted jobs with status "published", which core.jobs' CHECK (draft|open|paused|closed) rejects; the insert error was unawaited, so the count it expected (2) was unreachable. Now "open", and the error throws. The 27th test — a vanity slug resolving to a profile with a location — was red for a reason outside #482 and inside #732: GET /v1/profiles/slug/{slug} read core.profile with the request client, and every SELECT policy on that table is granted to `authenticated` (profile_public_read is `true`, so every signed-in viewer sees it). Anonymous viewers, the audience the public page exists for, got location: null. The read now goes through the service-role client alongside the preferences read that already did, after the user row is resolved, so nothing about who can find a profile changes. Verified against the running API: 27/27, with the edge runtime confirmed to be serving this worktree (it had been serving another one — the memory-noted gotcha — for the earlier runs). Fixed-name fixtures poisoned reruns: a run that died before cleanup left acme-corp / private-org behind and every later run hit organizations_slug_key. Slugs are now unique per run. tests/infrastructure/vitest/mocks/beyond-ui.tsx: Tabs was a bare div, so any screen using Tabs.Item / Tabs.Trigger / Tabs.Content threw "Element type is invalid". That is what kept two IPIPResultsPage tests skipped since #566 and what stopped the XP-award test from ever rendering the page it asserted on. Tabs is now a compound; both skips are lifted, and a regression test for #740 renders the page three times plus a tab switch and asserts the award fires once — with the hook mock returning a fresh object per call, as useMutation does, because a shared object cannot reproduce the loop. SDK pointer: 759b7ec -> sdk main (Scaffald/sdk#26 + #28). #743 recorded the bump to #26 in its description but main still pointed at sdk#25 — and #26 itself was red at 7: it moved the type, method and tests to the { data } envelope but not the msw handler. sdk#28 fixes the handler; 776/776. This is what `pnpm prepush` refused to stamp until it was fixed, which is the gate doing its job. profiles 27/27 · scf-core IPIPResultsPage 7/7 (was 4 + 2 skipped) and the three other Tabs-consuming suites 32/32 · scf-core:typecheck · sdk 776/776 · deno check profiles.ts unchanged at the 5 pre-existing errors · prepush stamped.
thinkclay
added a commit
that referenced
this pull request
Sep 11, 2026
…type can catch
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]>
thinkclay
added a commit
that referenced
this pull request
Sep 11, 2026
…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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the last open child of #660.
#617 repaired the select behind
GET /v1/profiles/organizations/{slug}— it used to ask forindustry,size,locationandfounded_yearand filter onis_public, none of which exist oncore.organizations. The response schema above it was left as written. So the endpoint has been answering 200 while its published OpenAPI contract, and the SDK type generated from it, were wrong in six ways.Checked against a live response, not reasoned about:
descriptionstringindustrystring{ id, name, slug }sizestringlocationstringfounded_yearnumberaddressWhy nothing broke visibly
@hono/zod-openapidocuments responses rather than validating them, and no screen importsuseOrganizationProfile. The SDK tests passed throughout because their msw handler hand-wrote the declared shape — so they asserted against a response the API cannot produce. Corrected in Scaffald/sdk#26 (merged, pointer bumped here), where four new assertions check the things that were actually wrong and are verified to fail when the mock regresses.That PR also caught a seventh mismatch the field table misses: the route wraps in
{ data }and the http client returns the body verbatim, sogetOrganizationresolved to{ data: OrganizationProfile }while declaring it bare.tscfound it the moment the method stopped lying.Dropped, not added
size,locationandfounded_yearare gone from the contract. No table in any schema has those columns — a search ofinformation_schema.columnsmatches nothing outsidepg_catalogandstorage. Keeping them would mean inventing product surface to satisfy a schema that was only ever aspirational.addressis the real column behind what it calledlocation.Verified
Every declared field matches the live response by type, and no undeclared field is returned:
deno checkonprofiles.tsis unchanged at 3 errors — all pre-existing members of theTS2345handler-response family measured in #704, two of them on routes this does not touch.deno fmt --checkclean, the reference and contract tests pass (9/9),scf-core:typecheckpasses.One trap recorded in the code
supabase-js types the embedded to-one relation as an array, because it cannot infer cardinality from the select string, so the static type says
industry: {...}[]while the wire format is an object. The schema follows the wire format, and there is a comment saying so — the same ambiguity that bit the embedded organization inmiddleware/auth.ts.Not fixed here
Two of the three public profile routes wrap in
{ data }and one does not, while the SDK declares all three bare. That inconsistency spans the surface; filed separately rather than half-fixed.Closes #482