fix(web): return the full member from a role change
PATCH /api/teams/{teamId}/members/{userId} returns a member the macOS client cannot decode, so every successful role change surfaces to the user as an error.
changeMemberRole is typed Promise<{ userId: string; role: TeamRole }> and returns exactly that, and the route ships it as teamJson({ member }). TeamsClient.changeMemberRole decodes that into CloudTeamMember, whose isViewer: Bool is non-optional and has no CodingKeys or custom init(from:), so the synthesized Decodable throws:
keyNotFound(CodingKeys(stringValue: "isViewer"), ... "No value associated with key CodingKeys(stringValue: \"isViewer\")")
displayName, email and profileImageUrl are String? and tolerate absence. isViewer is the fatal one. The reply also violates the web's own declared TeamMember type in web/services/teams/types.ts:18-25, which requires isViewer: that handler is simply never type-checked against it, since changeMemberRole's own return type is the narrower one.
The fix
toMember moves out of detail.ts into members.ts as an exported toTeamMember, so the roster and the role change build one shape from one place. changeMemberRole returns that, on both the mutating path and the no-op current === role path. The role is passed in explicitly rather than read back: fresh is the snapshot taken before the grant, so memberRole(fresh, targetUserId) would report the role the member is being moved away from.
The dashboard procedure's .output widens to match. A zod object strips unknown keys, so leaving it narrow would have silently thrown the new fields away for the web client.
Tests
Three tests in web/tests/teams-members.test.ts, landed as a failing commit before the fix:
- the reply carries the full member, not just the id and role
isVieweris true when an admin changes their own role- a no-op role change returns the same full shape
bun test tests/teams-members.test.ts tests/teams-seat-sync.test.ts gives 23 pass / 0 fail, and bunx tsc --noEmit -p web is clean. On the first commit alone the three new tests fail with expected true, received undefined, which is the keyNotFound above seen from the JavaScript side.
Found while reviewing #16241, which fixes a different decode failure on the same client.
Fix, so no team review.
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Fixes role change responses so a successful PATCH /api/teams/{teamId}/members/{userId} no longer surfaces to the macOS client as an error.
Bug Fixes
- Returns the full member shape (
displayName,email,profileImageUrl,isViewer) instead of just{ userId, role }, which the client's non-optionalisViewercould not decode. - Shares
toTeamMemberbetween the roster and the role change so both build one shape, and widens the dashboard procedure's output to match a full member. - Passes the requested role explicitly since
freshis the pre-grant snapshot, and the no-op role change returns the same full shape.