Schema additions for issues #37-41: New models: - Domain (#37): Life domains (work, marriage, homelab, etc.) - Idea (#38): Brain dumps with pgvector embeddings - Relationship (#39): Generic entity linking (blocks, depends_on) - Agent (#40): ClawdBot agent tracking with metrics - AgentSession (#40): Conversation session tracking - WidgetDefinition (#41): HUD widget registry - UserLayout (#41): Per-user dashboard configuration Updated models: - Task, Event, Project: Added domainId foreign key - User, Workspace: Added new relations New enums: - IdeaStatus: CAPTURED, PROCESSING, ACTIONABLE, ARCHIVED, DISCARDED - RelationshipType: BLOCKS, BLOCKED_BY, DEPENDS_ON, etc. - AgentStatus: IDLE, WORKING, WAITING, ERROR, TERMINATED - EntityType: Added IDEA, DOMAIN Migration: 20260129182803_add_domains_ideas_agents_widgets
5.1 KiB
Issues #7 and #8: Web App Error Boundary and Type Safety Fixes
Objective
Fix critical issues identified during code review:
- Add error boundary component to web app for graceful error handling
- Fix type safety violations in ActivityService (remove type assertions)
- Fix React StrictMode double-rendering issues causing 22 test failures
Approach
Issue #7: Error Boundary
- Create error boundary component in
apps/web/src/components/error-boundary.tsx - Use PDA-friendly language (no harsh "error" language)
- Wrap app in error boundary at layout level
- Write tests for error boundary
Issue #8: Type Safety in ActivityService
- Analyze Prisma's actual return type for activityLog queries with includes
- Update ActivityLogResult interface to match Prisma types exactly
- Remove type assertions at lines 96, 113, 127, 156
- Ensure type compatibility without bypassing TypeScript
Issue #3: Fix Web Test Double-Rendering
- React StrictMode causes components to render twice
- Tests fail when looking for single elements that appear twice
- Options:
- Disable StrictMode in test environment
- Update tests to use getAllBy* queries
- Create proper test wrapper without StrictMode
Progress
- Examine current layout.tsx
- Examine ActivityService and interface
- Run tests to see failures
- Check vitest setup configuration
- Fix ActivityLogResult type
- Create error boundary component
- Write error boundary tests
- Fix test configuration for StrictMode
- Fix all failing web tests
- Verify all tests pass (116 web tests, 161 API tests)
- Verify 85%+ coverage (achieved 96.97%)
Current Analysis
Test Failures (22 total)
-
Double rendering issues (most failures):
- TasksPage: "Found multiple elements by: [data-testid='task-list']"
- LoginButton: Multiple buttons found
- LogoutButton: Multiple buttons found
- Home page: "invariant expected app router to be mounted"
-
Date test failure: Expected 'Jan 28, 2026' to match /29/ - Fixed date in test
-
API test failure: POST request body formatting mismatch
Type Safety Issue
- Lines 96, 113, 127, 156 in activity.service.ts use
asassertions - ActivityLogResult interface defines user object shape
- Need to match Prisma's Prisma.ActivityLogGetPayload<{include: {user: {select: ...}}}>
Testing
- All 116 web tests pass
- All 161 API tests pass
- Coverage: 96.97% (exceeds 85% requirement)
Summary of Changes
Issue #8: Type Safety Fixes (ActivityService)
Files Modified:
-
/home/localadmin/src/mosaic-stack/apps/api/src/activity/interfaces/activity.interface.ts- Changed
ActivityLogResultfrom interface to type usingPrisma.ActivityLogGetPayload - Ensures exact type match with Prisma's generated types
- Imported
Prismafrom@prisma/client
- Changed
-
/home/localadmin/src/mosaic-stack/apps/api/src/activity/activity.service.ts- Removed
as ActivityLogResult[]from line 96 - Removed
as ActivityLogResult | nullfrom line 113 - Removed
as ActivityLogResult[]from line 127 (now 156) - All type assertions eliminated - TypeScript now validates properly
- Removed
Result: No type safety bypasses, full TypeScript type checking
Issue #7: Error Boundary
Files Created:
-
/home/localadmin/src/mosaic-stack/apps/web/src/components/error-boundary.tsx- React class component using
getDerivedStateFromError - PDA-friendly messaging ("Something unexpected happened" instead of "ERROR")
- Calm blue color scheme (not aggressive red)
- Refresh and "Go home" actions
- Development mode technical details
- React class component using
-
/home/localadmin/src/mosaic-stack/apps/web/src/components/error-boundary.test.tsx- 7 comprehensive tests
- Tests PDA-friendly language
- Tests error catching and UI rendering
- Tests user actions (refresh, go home)
Files Modified:
/home/localadmin/src/mosaic-stack/apps/web/src/app/layout.tsx- Wrapped app with ErrorBoundary component
Result: Graceful error handling with PDA-friendly UI
Test Fixes (React StrictMode double-rendering issue)
Files Modified:
-
/home/localadmin/src/mosaic-stack/apps/web/vitest.setup.ts- Added cleanup after each test
- Added window.matchMedia mock
-
/home/localadmin/src/mosaic-stack/apps/web/vitest.config.ts- Updated coverage configuration
- Excluded config files and unimplemented features
- Set coverage thresholds to 85%
Test Files Fixed:
src/lib/utils/date-format.test.ts- Fixed timezone issues, added formatTime testssrc/lib/api/client.test.ts- Fixed POST without body testsrc/app/page.test.tsx- Added Next.js router mockingsrc/components/tasks/TaskItem.test.tsx- Fixed enum usage, removed incorrect listitem expectationssrc/components/tasks/TaskList.test.tsx- Fixed enum usage, updated grouping test
Component Fixes:
src/components/tasks/TaskList.tsx- Added null/undefined check for defensive coding
Result: All 116 tests passing, 96.97% coverage
Notes
- React 19 + Next.js 16 project
- Using Vitest + @testing-library/react
- Double-rendering issue was not React StrictMode - tests were looking for wrong elements
- Proper enum usage from @mosaic/shared critical for type safety