User Identity Testing Summary
Document Version: 1.0
Last Updated: December 31, 2025
Status: Test Documentation
Overview
This document provides a summary of all test scripts and documentation created for validating user identity consistency across the Engram platform.
Test Scripts Created
1. Voice WebSocket Authentication Test
Script: scripts/test-voice-websocket-auth.py
Purpose: Tests that voice WebSocket endpoint properly extracts and validates JWT tokens from query parameters.
Usage:
# With token
python3 scripts/test-voice-websocket-auth.py --token <JWT_TOKEN>
# Test without token (should fail if AUTH_REQUIRED=true)
python3 scripts/test-voice-websocket-auth.py --test-no-token
Documentation: docs/testing/voice-websocket-auth-test.md
2. MCP Tools User ID Attribution Test
Script: scripts/test-mcp-tools-user-id.py
Purpose: Tests that MCP tools properly receive and use user_id from agent context.
Usage:
# Test all tools
python3 scripts/test-mcp-tools-user-id.py --user-id <USER_ID>
# Test specific tool
python3 scripts/test-mcp-tools-user-id.py --user-id <USER_ID> --tool chat
Documentation: docs/testing/mcp-tools-user-id-test.md
3. Background Tasks User ID Preservation Test
Script: scripts/test-background-tasks-user-id.py
Purpose: Tests that background tasks properly preserve user_id throughout execution.
Usage:
# Test all background tasks
python3 scripts/test-background-tasks-user-id.py --user-id <USER_ID>
# Test specific background task
python3 scripts/test-background-tasks-user-id.py --user-id <USER_ID> --test chat
Documentation: docs/testing/background-tasks-user-id-test.md
Quick Test Guide
Prerequisites
- Get JWT Token:
# From browser DevTools > Application > Local Storage # Find: msal.{CLIENT_ID}.idtoken export AUTH_TOKEN='your-jwt-token-here' - Get User ID:
# Extract from token (token.oid) or use test user export TEST_USER_ID='d240186f-f80e-4369-9296-57fef571cd93'
Run All Tests
# 1. Voice WebSocket Authentication
python3 scripts/test-voice-websocket-auth.py --token $AUTH_TOKEN
# 2. MCP Tools User ID Attribution
python3 scripts/test-mcp-tools-user-id.py --user-id $TEST_USER_ID
# 3. Background Tasks User ID Preservation
python3 scripts/test-background-tasks-user-id.py --user-id $TEST_USER_ID
Test Coverage
✅ Voice WebSocket Authentication
- WebSocket connection with valid token
- WebSocket connection without token (should fail)
- WebSocket connection with invalid token (should fail)
- User ID extraction from token
- SecurityContext creation with authenticated user
✅ MCP Tools User ID Attribution
- Tool accepts
user_idparameter - Tool uses provided
user_id(not fallback) - Tool falls back correctly when
user_idnot provided - Agent injects
user_idfrom context - Tool schema inspection for
user_idfield
✅ Background Tasks User ID Preservation
- Chat persistence preserves
user_id - Document ingestion preserves
user_id - Voice persistence preserves
user_id - Background task logging includes
user_id - No user_id loss in async operations
Expected Test Results
Voice WebSocket Authentication
Success:
✅ WebSocket connection established
✅ Test message sent
✅ Received response
Failure (no token):
❌ WebSocket closed with code 1008: Authentication required
MCP Tools User ID Attribution
Success:
✅ chat_with_agent result: ...
✅ enrich_memory result: Memory enriched successfully.
✅ search_memory result: ...
Warning (no user_id):
WARNING: chat_with_agent called without user_id - using fallback
Background Tasks User ID Preservation
Success:
Background task started: persisting conversation for user: test-user-123
Background task completed: conversation persisted for user: test-user-123
✅ Chat persistence preserved user_id correctly
Backend Log Verification
All tests should produce logs showing user_id:
Voice WebSocket:
INFO: VoiceLive WebSocket: Authenticated user {user_id} for session {session_id}
MCP Tools:
INFO: chat_with_agent called with user_id: {user_id}
DEBUG: Injected user_id={user_id} into tool chat_with_agent
Background Tasks:
INFO: Background task started: persisting conversation for user: {user_id}
INFO: Background task completed: conversation persisted for user: {user_id}
Troubleshooting
Common Issues
- Token Expired
- Get fresh token from browser
- Tokens expire after 1 hour
- User ID Mismatch
- Verify token contains correct
oidclaim - Check backend logs for actual user_id used
- Verify token contains correct
- Background Task Not Running
- Check if task is fire-and-forget (may complete after test)
- Wait a few seconds and check logs
- Import Errors
- Ensure backend dependencies are installed
- Run from project root directory
Related Documentation
docs/architecture/user-identity-flow-comprehensive.md- Complete user identity flowdocs/architecture/user-identity-fixes-required.md- Implementation detailsdocs/development/background-tasks-guidelines.md- Background task patternsdocs/testing/voice-websocket-auth-test.md- Voice WebSocket test detailsdocs/testing/mcp-tools-user-id-test.md- MCP tools test detailsdocs/testing/background-tasks-user-id-test.md- Background tasks test details
Next Steps
- Run Tests: Execute all test scripts to validate implementation
- Review Logs: Check backend logs for user_id in all operations
- Verify Zep: Check Zep memory for correct user_id attribution
- Monitor Production: Watch logs in production for user_id consistency
Key Takeaway: All test scripts validate that user_id flows correctly from authentication through all system components, ensuring proper user attribution and access control.