Repository navigation
fix: make nine methods agree with their route about the envelope - #30
Merged
Merged
Conversation
The remaining mismatches from Scaffald/SaaS#744, fixed the way each one needs rather than uniformly. **Seven declared the payload against a route that wraps.** apiKeys.update, apiKeys.getUsage, connections.accept, connections.send, engagement.track, follows.followJob and follows.followUser all did `return this.<verb><T>(path)` against a route ending `c.json({ data: … })`, so they resolved to `{ data: T }` while promising `T`. These unwrap now rather than widening the signature, which is what 39 other methods in this SDK already do. That is the fix that makes callers *work* rather than merely type-check: useUpdateApiKeyMutation already declares `UseMutationOptions<ApiKey, …>`, so the hook, the screens and the declared type were all right and only the runtime value was wrong. **Two declared an envelope their route does not send.** personalityAssessments.getStatus and getIPIPStatus declared `{ data: AssessmentStatus }` / `{ data: IPIPStatus }`. Probed against the running api: GET /v1/personality-assessment/status bare keys=[id,user_id,current_step,completion_score,started_at] GET /v1/personality-assessment/ipip/status bare keys=[isCompleted,completedAt,progress] so the envelope was never sent and anything reading `status?.data` was reading undefined. Both now declare the payload. Consumers in scf-core are corrected in the parent repo's companion change — PersonalityAssessmentWidget and usePersonalityAssessment both do `assessmentData?.data` today and have been getting undefined. **The mocks were wrong in the same direction,** which is why the suite was green across all nine. Eight handlers now mirror their route: six wrapped, and the follows/user handler has two success returns so both were. Wrapping only the first `HttpResponse.json({` in a handler wraps the 400 branch instead — worth stating because I did exactly that on the first attempt and the tests caught it. tsc clean; 777 tests across 36 files pass. Refs Scaffald/SaaS#744 Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay
added a commit
to Scaffald/SaaS
that referenced
this pull request
Sep 11, 2026
…g them Clears BASELINE_MISMATCHES to empty. Nine were real and are fixed in Scaffald/sdk#30; two were this test's own false positives. **Seven declared the payload against a route that wraps** — apiKeys.update, apiKeys.getUsage, connections.accept, connections.send, engagement.track, follows.followJob, follows.followUser. They now unwrap, as 39 other methods in the SDK already do, rather than widening the signature. That is the fix that makes callers work rather than merely type-check: useUpdateApiKeyMutation already declares `UseMutationOptions<ApiKey, …>`, so the hook, the screens and the type were all right and only the runtime value was wrong. **Two declared an envelope their route does not send,** and this one was live. personalityAssessments.getStatus and getIPIPStatus declared `{ data: … }`; probed against the running api, both routes answer bare. So every consumer reading `status?.data` was reading undefined: PersonalityAssessmentWidget.tsx const assessment = assessmentData?.data usePersonalityAssessment.ts const assessment = assessmentData?.data useAssessmentStatus.ts cast through `{ data?: … }` to compile All three corrected here. A fourth, LuscherTestWizard.tsx, already carried the workaround *and the diagnosis* — "SDK type declares { data: AssessmentStatus } but API returns AssessmentStatus directly", with a `??` fallback that made that one screen work while the other three silently did not. Now that the type is right, the fallback goes too. Typecheck found that fourth site on its own once the declaration stopped lying, which is the argument for fixing the type rather than the call sites. **Two were the guard's false positives.** auth.getUserRoles and jobs.officeDuplicateJob do unwrap, through spellings the detector did not recognise: return { roles: response.data.roles } // reshapes while unwrapping .then((res) => res.data) const response = (await this.get<…>(p)) as {…} // parenthesised cast Detection is now precise about the thing that matters: find the name the response is bound to, then ask whether the body reads `.data` off it. Widening it that way first hid four real unwraps in background-checks and feedback, because the binding regex did not allow the parenthesised form — caught by the baseline's own stale check, which is what that half of the guard is for. Re-attacked after the change, since a too-permissive detector would mask the class it exists to catch: reverting engagement.track to its pre-fix form is still reported as "sdk says bare, route says wrapped", and legitimate unwrapping is still not flagged. Also runs deno fmt over three files this branch does not otherwise touch — __tests__/lib/profile-visibility.test.ts, __tests__/routes/public-profile-sections.test.ts and routes/profile-widgets.ts, all from #748. They fail `Lint REST API Code` on main, and formatting them makes that check pass rather than fail less. scf-core typecheck and its 1151 tests pass; deno fmt and lint clean; the contract directory is 9/9. Closes #744 Co-Authored-By: Claude Opus 5 <[email protected]>
thinkclay
added a commit
to Scaffald/SaaS
that referenced
this pull request
Sep 11, 2026
…g them (#750) Clears BASELINE_MISMATCHES to empty. Nine were real and are fixed in Scaffald/sdk#30; two were this test's own false positives. **Seven declared the payload against a route that wraps** — apiKeys.update, apiKeys.getUsage, connections.accept, connections.send, engagement.track, follows.followJob, follows.followUser. They now unwrap, as 39 other methods in the SDK already do, rather than widening the signature. That is the fix that makes callers work rather than merely type-check: useUpdateApiKeyMutation already declares `UseMutationOptions<ApiKey, …>`, so the hook, the screens and the type were all right and only the runtime value was wrong. **Two declared an envelope their route does not send,** and this one was live. personalityAssessments.getStatus and getIPIPStatus declared `{ data: … }`; probed against the running api, both routes answer bare. So every consumer reading `status?.data` was reading undefined: PersonalityAssessmentWidget.tsx const assessment = assessmentData?.data usePersonalityAssessment.ts const assessment = assessmentData?.data useAssessmentStatus.ts cast through `{ data?: … }` to compile All three corrected here. A fourth, LuscherTestWizard.tsx, already carried the workaround *and the diagnosis* — "SDK type declares { data: AssessmentStatus } but API returns AssessmentStatus directly", with a `??` fallback that made that one screen work while the other three silently did not. Now that the type is right, the fallback goes too. Typecheck found that fourth site on its own once the declaration stopped lying, which is the argument for fixing the type rather than the call sites. **Two were the guard's false positives.** auth.getUserRoles and jobs.officeDuplicateJob do unwrap, through spellings the detector did not recognise: return { roles: response.data.roles } // reshapes while unwrapping .then((res) => res.data) const response = (await this.get<…>(p)) as {…} // parenthesised cast Detection is now precise about the thing that matters: find the name the response is bound to, then ask whether the body reads `.data` off it. Widening it that way first hid four real unwraps in background-checks and feedback, because the binding regex did not allow the parenthesised form — caught by the baseline's own stale check, which is what that half of the guard is for. Re-attacked after the change, since a too-permissive detector would mask the class it exists to catch: reverting engagement.track to its pre-fix form is still reported as "sdk says bare, route says wrapped", and legitimate unwrapping is still not flagged. Also runs deno fmt over three files this branch does not otherwise touch — __tests__/lib/profile-visibility.test.ts, __tests__/routes/public-profile-sections.test.ts and routes/profile-widgets.ts, all from #748. They fail `Lint REST API Code` on main, and formatting them makes that check pass rather than fail less. scf-core typecheck and its 1151 tests pass; deno fmt and lint clean; the contract directory is 9/9. Closes #744 Co-authored-by: Claude Opus 5 <[email protected]>
thinkclay
added a commit
that referenced
this pull request
Oct 6, 2026
…al round trip pins it (#35) The api wraps every api-keys response in { data }. #744 and #30 unwrapped update() and getUsage(); list(), create() and revoke() were left returning the body verbatim, so list() handed callers an object typed as an array and /office/api-keys crashed on `.map` for every office user (Scaffald/SaaS#1015). - list(), create(), revoke() unwrap { data }. - revoke() called POST /v1/api-keys/:id/revoke, a route that does not exist. Revocation is DELETE /v1/api-keys/:id (a soft delete). - The MSW mocks returned bare bodies and invented the /revoke route, so the unit tests encoded the wrong contract and passed. They now return what the route returns. - The integration smoke accepted either shape; it is strict now. Its default user has no organization, so it asserts the route's 403 for that case. - api-keys.integration.test.ts: create -> list -> revoke -> list against the real local api as a seeded team_admin. Red on the old resource (create() returned the wrapper: `expected undefined to deeply equal Any<String>`), green on this one. Co-authored-by: Claude Opus 5.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.
The remaining mismatches from Scaffald/SaaS#744 — fixed the way each one needs, rather than uniformly.
Seven declared the payload against a route that wraps
apiKeys.update,apiKeys.getUsage,connections.accept,connections.send,engagement.track,follows.followJob,follows.followUser.All did
return this.<verb><T>(path)against a route endingc.json({ data: … }), so they resolved to{ data: T }while promisingT.These unwrap now, rather than widening the signature — which is what 39 other methods in this SDK already do, and it is the fix that makes callers work rather than merely type-check:
The hook, the screens and the declared type were all already right about the shape. Only the runtime value was wrong. Re-declaring the envelope would have made the type honest and left every caller broken.
Two declared an envelope their route does not send
personalityAssessments.getStatusandgetIPIPStatusdeclared{ data: AssessmentStatus }/{ data: IPIPStatus }. Probed against the running api:The envelope was never sent, so anything reading
status?.datahas been readingundefined. Both now declare the payload.This one is a live bug, not a latent one.
PersonalityAssessmentWidgetandusePersonalityAssessmentboth doassessmentData?.datatoday. Corrected in the parent repo's companion change.The mocks were wrong in the same direction
Which is why the suite was green across all nine. Eight handlers now mirror their route — six wrapped, and
follows/userhas two success returns, so both were.Worth stating explicitly: wrapping only the first
HttpResponse.json({in a handler wraps the 400 branch instead of the success return. I did exactly that on the first attempt; the tests caught it, and I redid the six by hand.Verified
tsc --noEmitclean; 777 tests across 36 files pass.Refs Scaffald/SaaS#744