Skip to content
Shell
9.5 KB
Raw Blame

DeepStack Comprehensive Testing Plan

Overview

Expand test coverage from 356 tests to ~770 tests using subagent orchestration. Current state: 324 unit tests + 32 integration tests (all passing) Target state: ~415 new tests across API routes, stores, hooks, and components


Phase 0: Mocking Infrastructure (Prerequisites)

Files to Create

web/src/__tests__/mocks/
├── supabase-auth.ts      # Mock Supabase auth client
├── supabase-db.ts        # Mock Supabase database client
├── ai-sdk.ts             # Mock Vercel AI SDK (streaming)
└── handlers-extended.ts  # Additional MSW handlers

Implementation

  1. Supabase Auth Mock (supabase-auth.ts)

    • Mock createClient from @supabase/supabase-js
    • Provide getUser(), getSession(), signIn(), signOut() mocks
    • Support authenticated/unauthenticated states
  2. Supabase DB Mock (supabase-db.ts)

    • Mock query builder chain: .from().select().eq().single()
    • Mock insert/update/delete operations
    • Mock RLS-protected table access
  3. AI SDK Mock (ai-sdk.ts)

    • Mock streamText from ai package
    • Return async iterable for streaming responses
    • Support tool calls and function responses
  4. Extended MSW Handlers (handlers-extended.ts)

    • Add handlers for all 19 API routes
    • Include error scenarios and edge cases

Phase 1: API Route Integration Tests

Subagent: test-engineer Parallel Workstreams: 4

Workstream 1A: Trading Routes (test-engineer)

web/src/__tests__/integration/api/
├── trades.integration.test.ts        # 15 tests
├── positions.integration.test.ts     # 12 tests
├── portfolio.integration.test.ts     # 10 tests
└── order.integration.test.ts         # 10 tests

Test Coverage:

  • Supabase auth required (401 unauthorized)
  • CRUD operations with mock DB
  • Error handling and validation
  • RLS policy enforcement

Workstream 1B: Market Data Routes (test-engineer)

web/src/__tests__/integration/api/
├── calendar.integration.test.ts      # 8 tests
├── economic-data.integration.test.ts # 8 tests
├── prediction-markets.integration.test.ts # 12 tests (expand existing)
└── assets.integration.test.ts        # 8 tests

Workstream 1C: AI/Chat Routes (test-engineer)

web/src/__tests__/integration/api/
├── chat.integration.test.ts          # 15 tests
├── search.integration.test.ts        # 10 tests
└── summarize.integration.test.ts     # 8 tests

Test Coverage:

  • AI SDK streaming mocks
  • Tool call handling
  • Rate limiting
  • Error recovery

Workstream 1D: User Data Routes (test-engineer)

web/src/__tests__/integration/api/
├── journal.integration.test.ts       # 12 tests
├── thesis.integration.test.ts        # 12 tests
└── settings.integration.test.ts      # 8 tests

Test Coverage:

  • Auth-protected routes
  • Supabase RLS enforcement
  • CRUD with user isolation

Phase 2: Store Unit Tests

Subagent: test-engineer Parallel Workstreams: 2

Workstream 2A: Trading Stores

web/src/stores/__tests__/
├── trade-store.test.ts               # 25 tests
├── portfolio-store.test.ts           # 20 tests
└── watchlist-store.test.ts           # 15 tests

Test Patterns:

import { act } from '@testing-library/react';
import { useTradeStore } from '../trade-store';

beforeEach(() => {
  useTradeStore.setState(useTradeStore.getInitialState());
});

it('adds trade to store', () => {
  act(() => {
    useTradeStore.getState().addTrade({ symbol: 'SPY', ... });
  });
  expect(useTradeStore.getState().trades).toHaveLength(1);
});

Workstream 2B: UI State Stores

web/src/stores/__tests__/
├── chat-store.test.ts                # 20 tests
├── settings-store.test.ts            # 10 tests
└── notification-store.test.ts        # 10 tests

Phase 3: Hook Unit Tests

Subagent: test-engineer Parallel Workstreams: 2

Workstream 3A: Data Fetching Hooks

web/src/hooks/__tests__/
├── use-market-data.test.ts           # 15 tests
├── use-bars.test.ts                  # 12 tests
├── use-quotes.test.ts                # 12 tests
└── use-news.test.ts                  # 10 tests

Test Patterns:

import { renderHook, waitFor } from '@testing-library/react';
import { QueryClientProvider } from '@tanstack/react-query';
import { useMarketData } from '../use-market-data';

const wrapper = ({ children }) => (
  <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);

it('fetches market data', async () => {
  const { result } = renderHook(() => useMarketData('SPY'), { wrapper });
  await waitFor(() => expect(result.current.data).toBeDefined());
});

Workstream 3B: UI/Behavior Hooks

web/src/hooks/__tests__/
├── use-debounce.test.ts              # 8 tests
├── use-local-storage.test.ts         # 8 tests
└── use-keyboard-shortcuts.test.ts    # 10 tests

Phase 4: Component Tests

Subagent: test-engineer Parallel Workstreams: 2

Workstream 4A: Trading Components

web/src/components/__tests__/
├── trade-form.test.tsx               # 15 tests
├── position-table.test.tsx           # 12 tests
├── portfolio-chart.test.tsx          # 10 tests
└── watchlist.test.tsx                # 10 tests

Workstream 4B: Dashboard Components

web/src/components/__tests__/
├── market-card.test.tsx              # 10 tests
├── news-feed.test.tsx                # 8 tests
├── prediction-market-card.test.tsx   # 8 tests
└── chat-interface.test.tsx           # 12 tests

Phase 5: E2E Test Expansion

Subagent: test-engineer Single Workstream

New E2E Tests

web/e2e/
├── trading-flow.spec.ts              # 8 tests
├── journal-crud.spec.ts              # 6 tests
├── settings-persistence.spec.ts      # 5 tests
├── market-data-refresh.spec.ts       # 6 tests
└── error-recovery.spec.ts            # 10 tests

Execution Strategy

Orchestration Pattern

┌─────────────────────────────────────────────────────────┐
│                    Claude (Orchestrator)                │
│  - Monitor agent progress                               │
│  - Verify test quality                                  │
│  - Run test suites after each phase                     │
│  - Fix integration issues                               │
└─────────────────────────────────────────────────────────┘
                           │
     ┌─────────────────────┼─────────────────────┐
     ▼                     ▼                     ▼
┌──────────┐         ┌──────────┐         ┌──────────┐
│ Agent 1  │         │ Agent 2  │         │ Agent 3  │
│ (tests)  │         │ (tests)  │         │ (tests)  │
└──────────┘         └──────────┘         └──────────┘

Verification After Each Phase

  1. Run npm run test:all to verify all tests pass
  2. Check coverage with npm run test:coverage
  3. Fix any integration issues before proceeding

Agent Prompts Template

You are implementing [WORKSTREAM_NAME] tests for DeepStack.

Context:
- Existing test patterns: [FILES]
- Mock infrastructure: [MOCK_FILES]
- API route being tested: [ROUTE_FILE]

Requirements:
1. Create [TEST_FILE] with [N] tests
2. Cover: validation, success cases, error handling, edge cases
3. Use existing mock patterns from handlers.ts
4. Follow Vitest + MSW patterns established in the codebase

Test categories to cover:
- Input validation (400 errors)
- Authentication (401 errors for protected routes)
- Successful responses with correct structure
- Backend fallback behavior
- Edge cases (empty data, null values, limits)

Critical Files

Existing Infrastructure (Reference)

  • web/src/__tests__/integration/setup.ts
  • web/src/__tests__/integration/test-utils.ts
  • web/src/__tests__/integration/mocks/handlers.ts
  • web/vitest.integration.config.ts

API Routes to Test

  • web/src/app/api/trades/route.ts
  • web/src/app/api/positions/route.ts
  • web/src/app/api/portfolio/route.ts
  • web/src/app/api/chat/route.ts
  • web/src/app/api/journal/route.ts
  • web/src/app/api/thesis/[id]/route.ts
  • web/src/app/api/calendar/route.ts
  • web/src/app/api/economic-data/route.ts

Stores to Test

  • web/src/stores/trade-store.ts
  • web/src/stores/portfolio-store.ts
  • web/src/stores/chat-store.ts

Hooks to Test

  • web/src/hooks/use-market-data.ts
  • web/src/hooks/use-bars.ts
  • web/src/hooks/use-quotes.ts

Summary

Phase Tests Agents Focus
0 0 1 Mocking infrastructure
1 ~130 4 parallel API route integration
2 ~100 2 parallel Store unit tests
3 ~75 2 parallel Hook unit tests
4 ~75 2 parallel Component tests
5 ~35 1 E2E expansion
Total ~415 12 total

Execution Order

  1. Phase 0 first (blocking - creates shared mocks)
  2. Phases 1-4 can overlap (non-blocking)
  3. Phase 5 last (depends on earlier phases)