Skip to main content

CAIPE UI Test Coverage Improvement Plan

Status: Planned Category: Testing / Quality Date: February 25, 2026 Estimated Effort: 12–18 working days (2.5–3.5 weeks)

Overview​

Comprehensive plan to improve CAIPE UI unit test coverage from ~31% file coverage (~55 of ~175 source files) to near-complete coverage. This ADR captures the current state analysis, identified gaps, and a phased implementation plan.

Current State​

MetricValue
Test suites72
Total tests1,804
Source files (ts/tsx, excluding types/tests)~175
Files with tests~55 (~31%)
Files without tests~120 (~69%)

What's Well-Covered​

  • All 3 store files — chat-store.ts, agent-config-store.ts, workflow-run-store.ts
  • All 9 hooks — use-a2a-streaming, use-admin-role, use-caipe-health, use-prometheus, use-rag-health, useRagPermissions, use-service-health, use-user-init, use-version
  • 15 of 16 lib files — API clients, auth, config, MongoDB, streaming, storage, utils
  • Core chat components — ChatPanel (2 test files), AuthGuard, FeedbackButton, AgentStreamBox, SubAgentCard
  • ~23 API route handlers — admin, chat conversations/messages, auth, settings, RAG RBAC, skill templates

Gap Analysis​

Phase 1 — Quick Wins (1–2 days)​

Simple files with repeatable patterns. Good for building momentum.

FileTypeNotes
app/api/health/route.tsAPI routeTrivial GET handler
app/api/version/route.tsAPI routeTrivial GET handler
app/api/chat/conversations/[id]/share/route.tsAPI routeAuthorization-sensitive sharing
app/api/chat/conversations/[id]/pin/route.tsAPI routeState mutation
app/api/chat/conversations/[id]/archive/route.tsAPI routeState mutation
lib/markdown-components.tsxLibraryCustom renderers used across the app

Phase 2 — High-Value Components (3–4 days)​

User-facing components with significant logic. Priority based on user impact and bug history.

FilePriorityNotes
components/layout/Sidebar.tsxCriticalCore navigation; involved in race condition bug (conversation wipe during concurrent fetch). Needs regression tests.
components/chat/ShareDialog.tsxHighSharing authorization flow
components/chat/ShareButton.tsxHighEntry point for sharing
components/chat/MetadataInputForm.tsxHighUser input form with validation
components/chat/CustomCallButtons.tsxMediumAgent selection UX
components/a2a/A2AStreamPanel.tsxMediumStreaming display logic
components/a2a/A2UIRenderer.tsxMediumWidget rendering

Phase 3 — RAG Components (3–5 days)​

Entire RAG subsystem has 0% test coverage. IngestView.tsx is the largest untested file at ~2,067 lines.

File~LinesPriority
components/rag/IngestView.tsx2,067High — document ingestion workflows
components/rag/SearchView.tsxmediumHigh — core RAG search UX
components/rag/GraphView.tsx238Medium — knowledge graph visualization
components/rag/KnowledgePanel.tsxmediumMedium — RAG panel orchestrator
components/rag/KnowledgeSidebar.tsxmediumMedium — KB navigation
components/rag/api/index.ts—Medium — RAG API client functions
components/rag/graph/*—Low — Sigma.js graph controllers (heavy mocking needed)
components/rag/RagAuthBanner.tsxsmallLow — simple auth banner
components/rag/Models.ts—Low — type models
components/rag/typeConfig.ts—Low — config constants

Phase 4 — Remaining API Routes (2–3 days)​

16 untested route handlers. Follow the same mock-MongoDB + mock-auth + assert-response pattern as existing route tests.

RoutePriorityNotes
chat/messages/[id]/route.tsHighSingle message CRUD
chat/search/route.tsHighQuery/search with input validation
chat/bookmarks/route.tsMediumUser bookmarks
workflow-runs/route.tsMediumWorkflow execution tracking
agent-configs/seed/route.tsMediumSeed agent configurations
admin/metrics/route.tsMediumAdmin-only metrics
admin/stats/skills/route.tsMediumAdmin-only stats
users/me/route.tsMediumCurrent user profile
users/me/favorites/route.tsMediumUser favorites
users/me/stats/route.tsMediumUser analytics
users/me/insights/skills/route.tsLowSkills insights
users/search/route.tsLowUser search
users/debug/route.tsLowDebug endpoint
debug/auth-status/route.tsLowDebug auth
debug/session/route.tsLowDebug session
feedback/route.tsLowFeedback submission

Phase 5 — Admin, Skills & Pages (3–4 days)​

Admin dashboard components, the large SkillsEditor, and remaining app pages.

Admin Components​

FilePriorityNotes
components/admin/HealthTab.tsxMediumHealth monitoring dashboard
components/admin/MetricsTab.tsxMediumMetrics display
components/admin/PrometheusCharts.tsxMediumChart rendering
components/admin/SkillMetricsCards.tsxLowMetrics summary cards
components/admin/TeamDetailsDialog.tsxLowTeam management dialog
components/admin/CreateTeamDialog.tsxLowTeam creation dialog

Skills Components​

File~LinesPriority
components/skills/SkillsEditor.tsx998Medium — complex editor component
components/skills/WorkflowHistoryView.tsxmediumLow
FilePriority
components/gallery/IntegrationOrbit.tsxLow
components/gallery/UseCaseBuilder.tsxLow

App Pages​

PagePriorityNotes
(app)/knowledge-bases/page.tsxMediumKB entry point
(app)/knowledge-bases/ingest/page.tsxMediumIngestion page
(app)/knowledge-bases/search/page.tsxMediumSearch page
(app)/knowledge-bases/graph/page.tsxLowGraph page
(app)/skills/page.tsxLowSkills list
(app)/skills/editor/page.tsxLowEditor page
(app)/skills/history/page.tsxLowHistory page
unauthorized/page.tsxLowSimple error page
logout/page.tsxLowLogout redirect

Misc Components​

FilePriority
components/theme-provider.tsxLow
components/tech-stack.tsxLow
FileReason
components/ui/* (shadcn primitives)Third-party UI primitives — tested upstream
types/*.tsPure type definitions — no runtime behavior
app/api/auth/[...nextauth]/route.tsNextAuth handler — tested via integration
app/layout.tsx, (app)/layout.tsxLayout wrappers — minimal logic

Projected Outcome​

MetricBeforeAfter
Test suites72~130
Total tests1,804~2,400–2,600
File coverage~55/175 (31%)~155/175 (89%)
API route coverage23/45 (51%)43/45 (96%)
Component coverage~25/70 (36%)~60/70 (86%)

Test Fixture Utilities​

A reusable test fixture generator was created during the spinner/loading work and is available for use across new tests:

  • ui/src/__test-utils__/conversation-fixtures.ts — generates realistic conversation objects with configurable turn counts and message sizes (small/medium/large), inspired by the MongoDB seed scripts used for manual stress testing.

Implementation Notes​

  • API route tests follow a consistent pattern: mock getServerSession, mock MongoDB collections, call the route handler, assert status codes and response bodies.
  • Component tests use the existing jest mock infrastructure for next/navigation, next-auth/react, @/store/chat-store, @/lib/config, and framer-motion.
  • RAG components will need mocks for Sigma.js graph library and fetch calls to the RAG API.
  • The Sidebar.tsx test should specifically include a regression test for the race condition where loadConversationsFromServer wiped messages from the active conversation during concurrent fetch.

References​

  • Test suite output: make caipe-ui-tests (72 suites, 1,804 tests as of Feb 25, 2026)
  • Existing test patterns: ui/src/app/api/__tests__/, ui/src/components/__tests__/, ui/src/hooks/__tests__/
  • Conversation fixture generator: ui/src/__test-utils__/conversation-fixtures.ts
  • Related work: Spinner/loading fix and auth redirect callbackUrl preservation tests added Feb 24, 2026