Problem Description
When using convex-test with libraries like convex-helpers that execute triggers, two critical authentication issues occur:
- Missing
getUserIdentity syscall support: convex-test throws "convexTest does not support async syscall: 1.0/getUserIdentity" when functions try to access user identity
- Authentication context not propagated to triggers: Triggers receive contexts with
_userIdentity: null instead of the mocked identity set with withIdentity()
Root Cause Analysis
Issue 1: Missing getUserIdentity syscall
The asyncSyscallImpl() function in index.ts doesn't implement the "1.0/getUserIdentity" case, causing authentication-related functions to fail.
Issue 2: Context propagation problem
In withAuth() function (lines 1773 and 1801), the context creation overwrites the original auth context:
// Line 1773 - runTransaction
const testCtx = { ...ctx, auth, ...extraCtx };
// Line 1801 - queryFromPath
const testCtx = { ...ctx, auth };
This means when triggers execute, they don't have access to the authentication context that was set up with withIdentity().
Expected Behavior
- Functions should be able to call
ctx.auth.getUserIdentity() without errors
- Triggers should have access to the same authentication context that was configured with
withIdentity()
- Tests should replicate real-world authentication scenarios
Proposed Solution
Fix 1: Add getUserIdentity syscall support
Add the missing case in asyncSyscallImpl():
case "1.0/getUserIdentity": {
const auth = getCurrentAuth(); // Need to implement this
const identity = await auth.getUserIdentity();
return JSON.stringify(convexToJson(identity));
}
Fix 2: Preserve authentication context in nested contexts
Modify context creation to preserve original auth when it exists:
// Line 1773 - runTransaction
const testCtx = { ...ctx, auth: ctx.auth || auth, ...extraCtx };
// Line 1801 - queryFromPath
const testCtx = { ...ctx, auth: ctx.auth || auth };
Environment
convex-test version: 0.0.38
convex-helpers version: 0.1.104
convex version: 1.27.3
Impact
This affects any project using convex-test with:
- Authentication-based functions
- Trigger-based workflows (like
convex-helpers)
- Complex nested function calls that require authentication context
Problem Description
When using
convex-testwith libraries likeconvex-helpersthat execute triggers, two critical authentication issues occur:getUserIdentitysyscall support:convex-testthrows"convexTest does not support async syscall: 1.0/getUserIdentity"when functions try to access user identity_userIdentity: nullinstead of the mocked identity set withwithIdentity()Root Cause Analysis
Issue 1: Missing
getUserIdentitysyscallThe
asyncSyscallImpl()function inindex.tsdoesn't implement the"1.0/getUserIdentity"case, causing authentication-related functions to fail.Issue 2: Context propagation problem
In
withAuth()function (lines 1773 and 1801), the context creation overwrites the original auth context:This means when triggers execute, they don't have access to the authentication context that was set up with
withIdentity().Expected Behavior
ctx.auth.getUserIdentity()without errorswithIdentity()Proposed Solution
Fix 1: Add
getUserIdentitysyscall supportAdd the missing case in
asyncSyscallImpl():Fix 2: Preserve authentication context in nested contexts
Modify context creation to preserve original auth when it exists:
Environment
convex-testversion: 0.0.38convex-helpersversion: 0.1.104convexversion: 1.27.3Impact
This affects any project using
convex-testwith:convex-helpers)