Implements FED-010: Agent Spawn via Federation feature that enables spawning and managing Claude agents on remote federated Mosaic Stack instances via COMMAND message type. Features: - Federation agent command types (spawn, status, kill) - FederationAgentService for handling agent operations - Integration with orchestrator's agent spawner/lifecycle services - API endpoints for spawning, querying status, and killing agents - Full command routing through federation COMMAND infrastructure - Comprehensive test coverage (12/12 tests passing) Architecture: - Hub → Spoke: Spawn agents on remote instances - Command flow: FederationController → FederationAgentService → CommandService → Remote Orchestrator - Response handling: Remote orchestrator returns agent status/results - Security: Connection validation, signature verification Files created: - apps/api/src/federation/types/federation-agent.types.ts - apps/api/src/federation/federation-agent.service.ts - apps/api/src/federation/federation-agent.service.spec.ts Files modified: - apps/api/src/federation/command.service.ts (agent command routing) - apps/api/src/federation/federation.controller.ts (agent endpoints) - apps/api/src/federation/federation.module.ts (service registration) - apps/orchestrator/src/api/agents/agents.controller.ts (status endpoint) - apps/orchestrator/src/api/agents/agents.module.ts (lifecycle integration) Testing: - 12/12 tests passing for FederationAgentService - All command service tests passing - TypeScript compilation successful - Linting passed Refs #93 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
5.2 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