Files
Codewalkers/.planning/phases/07-mock-agent-test-harness/07-02-PLAN.md
Lukas May d0e9acf512 docs(07): create phase plan
Phase 07: Mock Agent & Test Harness
- 2 plans in 2 waves
- 1 parallel (07-01), 1 sequential (07-02)
- Ready for execution
2026-01-31 08:15:02 +01:00

6.1 KiB

phase, plan, type, wave, depends_on, files_modified, autonomous
phase plan type wave depends_on files_modified autonomous
07-mock-agent-test-harness 02 execute 2
07-01
src/test/harness.ts
src/test/fixtures.ts
src/test/index.ts
src/test/harness.test.ts
true
Create test harness with database fixtures and full system wiring.

Purpose: Provide reusable E2E test setup that wires MockAgentManager with real DispatchManager and CoordinationManager, plus helpers for seeding database hierarchies (initiative → phase → plan → task with dependencies).

Output: Test harness module (src/test/) with fixtures and system factory.

<execution_context> @/.claude/get-shit-done/workflows/execute-plan.md @/.claude/get-shit-done/templates/summary.md </execution_context>

@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md

@.planning/phases/07-mock-agent-test-harness/07-01-SUMMARY.md

@src/agent/types.ts @src/dispatch/types.ts @src/coordination/types.ts @src/db/repositories/drizzle/test-helpers.ts

Task 1: Create fixture helpers for database seeding src/test/fixtures.ts Create fixture helpers that seed complete task hierarchies.

Fixture interface:

interface TaskFixture {
  id: string;
  name: string;
  priority?: 'low' | 'medium' | 'high';
  dependsOn?: string[];  // names of other tasks in same fixture
}

interface PlanFixture {
  name: string;
  tasks: TaskFixture[];
}

interface PhaseFixture {
  name: string;
  plans: PlanFixture[];
}

interface InitiativeFixture {
  name: string;
  phases: PhaseFixture[];
}

seedFixture(db: DrizzleDatabase, fixture: InitiativeFixture): Promise

  • Creates initiative, phases, plans, tasks in correct order
  • Resolves task dependencies by name → ID mapping
  • Returns SeededFixture with all created IDs:
interface SeededFixture {
  initiativeId: string;
  phases: Map<string, string>;  // name → id
  plans: Map<string, string>;   // name → id
  tasks: Map<string, string>;   // name → id
}

Convenience fixtures:

  • SIMPLE_FIXTURE: 1 initiative → 1 phase → 1 plan → 3 tasks (A, B depends on A, C depends on A)
  • PARALLEL_FIXTURE: 1 initiative → 1 phase → 2 plans (each with 2 independent tasks)
  • COMPLEX_FIXTURE: 1 initiative → 2 phases → 4 plans with cross-plan dependencies TypeScript compiles, fixtures are valid data structures Fixture helpers create complete task hierarchies with dependency resolution
Task 2: Create test harness with full system wiring src/test/harness.ts, src/test/index.ts Create TestHarness class that wires up the full system for E2E testing.

TestHarness interface:

interface TestHarness {
  // Core components
  db: DrizzleDatabase;
  eventBus: EventBus & { emittedEvents: DomainEvent[] };
  agentManager: MockAgentManager;
  dispatchManager: DispatchManager;
  coordinationManager: CoordinationManager;

  // Repositories
  taskRepository: TaskRepository;
  messageRepository: MessageRepository;
  agentRepository: AgentRepository;

  // Helpers
  seedFixture(fixture: InitiativeFixture): Promise<SeededFixture>;
  setAgentScenario(agentName: string, scenario: MockAgentScenario): void;
  getEventsByType(type: string): DomainEvent[];
  clearEvents(): void;
}

createTestHarness(): TestHarness

  • Creates in-memory SQLite database (createTestDatabase)
  • Creates EventEmitterBus (real event bus for event verification)
  • Creates MockAgentManager (with eventBus)
  • Creates MockWorktreeManager (simple in-memory, creates fake worktrees)
  • Creates real DefaultDispatchManager (with mock agent manager)
  • Creates real DefaultCoordinationManager (with mock worktree manager)
  • Wires all repositories

MockWorktreeManager (inline in harness.ts):

  • Simple Map<string, WorktreeInfo> for worktree storage
  • create(): returns fake worktree with random path
  • get(): lookup by ID
  • remove(): delete from map
  • merge(): returns success (no actual git operations) npm run build succeeds TestHarness wires full system with mocks for E2E scenarios
Task 3: Write tests proving harness works src/test/harness.test.ts Write tests that prove the test harness enables E2E scenarios.

Test cases:

  1. createTestHarness() returns all components
  2. seedFixture() creates task hierarchy, returns correct IDs
  3. Task dependencies resolved correctly (dependsOn contains actual task IDs)
  4. dispatchManager.queue() + dispatchNext() uses MockAgentManager
  5. Event capture works (getEventsByType returns filtered events)
  6. Agent completion triggers expected events
  7. Full dispatch → complete → merge flow works end-to-end

Key verification: The test should prove this flow works:

const harness = createTestHarness();
const fixture = await harness.seedFixture(SIMPLE_FIXTURE);
await harness.dispatchManager.queue(fixture.tasks.get('Task A')!);
const result = await harness.dispatchManager.dispatchNext();
// Agent completes (mock scenario)
await harness.dispatchManager.completeTask(fixture.tasks.get('Task A')!);
// Verify events
const events = harness.getEventsByType('task:completed');
expect(events.length).toBe(1);
npm test passes harness tests Test harness proven to work for E2E scenarios Before declaring plan complete: - [ ] `npm run build` succeeds without errors - [ ] `npm test` passes all tests - [ ] createTestHarness() returns fully wired system - [ ] seedFixture() creates complete hierarchies - [ ] Task dependencies resolved by name - [ ] MockWorktreeManager integrated - [ ] At least one E2E flow test passes

<success_criteria>

  • All tasks completed
  • Test harness enables E2E testing without real Claude agents
  • Fixtures seed complex task hierarchies
  • Full dispatch → coordination flow works with mocks </success_criteria>
After completion, create `.planning/phases/07-mock-agent-test-harness/07-02-SUMMARY.md`