# Testing `src/test/` — Test infrastructure, fixtures, and test suites. ## Framework **vitest** (Vite-native test runner) ## Test Categories ### Unit Tests Located alongside source files (`*.test.ts`): - `src/agent/*.test.ts` — Manager, output handler, completion detection, file I/O, process manager - `src/db/repositories/drizzle/*.test.ts` — Repository adapters - `src/dispatch/*.test.ts` — Dispatch manager - `src/git/manager.test.ts` — Worktree operations - `src/process/*.test.ts` — Process registry and manager - `src/logging/*.test.ts` — Log manager and writer ### E2E Tests (Mocked Agents) `src/test/e2e/`: | File | Scenarios | |------|-----------| | `happy-path.test.ts` | Single task, parallel, complex flows | | `architect-workflow.test.ts` | Discussion + plan agent workflows | | `detail-workflow.test.ts` | Task detail with child tasks | | `phase-dispatch.test.ts` | Phase-level dispatch with dependencies | | `recovery-scenarios.test.ts` | Crash recovery, agent resume | | `edge-cases.test.ts` | Boundary conditions | | `extended-scenarios.test.ts` | Advanced multi-phase workflows | ### Integration Tests (Real Providers) `src/test/integration/real-providers/` — **skipped by default** (cost real money): | File | Provider | Cost | |------|----------|------| | `claude-manager.test.ts` | Claude CLI | ~$0.10 | | `codex-manager.test.ts` | Codex | varies | | `schema-retry.test.ts` | Claude CLI | ~$0.10 | | `crash-recovery.test.ts` | Claude CLI | ~$0.10 | Enable with env vars: `REAL_CLAUDE_TESTS=1`, `REAL_CODEX_TESTS=1` ## Test Infrastructure ### TestHarness (`src/test/harness.ts`) Central test utility providing: - In-memory SQLite database with schema applied - All 10 repository instances - `MockAgentManager` — simulates agent behavior (done, questions, error) - `MockWorktreeManager` — in-memory worktree simulator - `CapturingEventBus` — captures events for assertions - `DefaultDispatchManager` and `DefaultPhaseDispatchManager` - 25+ helper methods for test scenarios ### Fixtures (`src/test/fixtures.ts`) Pre-built task hierarchies for testing: | Fixture | Structure | |---------|-----------| | `SIMPLE_FIXTURE` | 1 initiative → 1 phase → 1 group → 3 tasks (A→B, A→C deps) | | `PARALLEL_FIXTURE` | 1 initiative → 1 phase → 2 groups → 4 independent tasks | | `COMPLEX_FIXTURE` | 1 initiative → 2 phases → 4 groups → cross-phase dependencies | ### Real Provider Harness (`src/test/integration/real-providers/harness.ts`) - Creates real database, real agent manager with real CLI tools - Provides `describeRealClaude()` / `describeRealCodex()` that skip when env var not set - `MINIMAL_PROMPTS` — cheap prompts for testing output parsing ## Running Tests ```sh # Unit tests npm test # Specific test file npm test -- src/agent/manager.test.ts # Real provider tests (costs money!) REAL_CLAUDE_TESTS=1 npm test -- src/test/integration/real-providers/ --test-timeout=300000 ```