fix(test): unskip user-context integration tests — fix WorkOS mock shape (#3319)#3326
Merged
Merged
Conversation
The vi.mock factory for workos-client.js exported { workos: ... } but
the module only exports getWorkos() as a named function. Added
getWorkos: () => mockInstance to the mock return value so member-context.ts
call sites resolve correctly.
Also added missing status: 'active' and userId fields to the
listOrganizationMemberships mock data so getWebMemberContext's
.find(m => m.status === 'active') and resolveUserRole filters work.
In member-context.ts: narrowed the getUser error catch to only set
is_mapped = false for genuine WorkOS 404 errors (entity_not_found /
status 404). Transient failures leave is_mapped: true so authenticated
web sessions degrade gracefully rather than being treated as anonymous.
The 404 test mock now throws a 404-shaped error to match.
Closes #3319
https://claude.ai/code/session_01S4yASsF6fSh3gqWGjoJ2mq
1 task
2 tasks
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 #3319
Summary
server/tests/integration/user-context.test.tswasdescribe.skipbecause all 10 WorkOS-path tests failed withexpected undefined to be defined. Three root causes, three fixes:1. Wrong mock export shape (core fix)
vi.mock('workos-client.js')exported{ workos: { userManagement: ... } }butworkos-client.tsonly exports named functions.member-context.tscallsgetWorkos().userManagement.*, sogetWorkoswasundefined. Fix: exportgetWorkos: () => mockInstancefrom the mock factory.2. Missing
status: 'active'on membership mock datagetWebMemberContextfilters with.find(m => m.status === 'active')andresolveUserRoleskips memberships wherestatus !== 'active'. Without the field,organizationIdstayednulland the function returned early before building any org/membership context. Fix: addstatus: 'active'(anduserId) to all membership objects in the mock.3. 404 never triggered for non-existent WorkOS users
getWebMemberContextinitializesis_mapped: true(correct for authenticated sessions). OngetUserfailure it returned that partial context, so the route's!is_mapped && !slack_user && !workos_userguard never fired. Fix: setcontext.is_mapped = falseonly when the WorkOS error is a genuine 404 (error.status === 404 || error.code === 'entity_not_found') — transient failures leaveis_mapped: trueso authenticated sessions degrade gracefully rather than being treated as anonymous. The test mock now throws a 404-shaped error foruser_nonexistent.Non-breaking justification: the
getWebMemberContextchange only affects theis_mappedflag when WorkOS returns a hard 404 for a user ID that doesn't exist. All callers that checkorganization(agent-oauth.ts) or wrap in try/catch (addie-chat.ts) are unaffected. For the admin debug endpoint, the behavior is now correct: non-existent user ID → 404.Pre-PR review
error.status === 404 || error.code === 'entity_not_found'narrowing correctly avoids transient-error demotion; mock shape matches module exports@workos-inc/nodeclass mock needed) confirmed safe since no code path in this test instantiatesWorkOSdirectly; dual-discriminantlistOrganizationMembershipsmock is idiomatic for mutually-exclusive WorkOS call patternsSession: https://claude.ai/code/session_01S4yASsF6fSh3gqWGjoJ2mq
Generated by Claude Code