---
phase: 11-architect-agent
plan: 08
type: execute
wave: 4
depends_on: ["11-05", "11-06", "11-07"]
files_modified:
  - src/test/harness.ts
  - src/test/e2e/architect-workflow.test.ts
autonomous: true
---

<objective>
Add TestHarness support for architect modes and E2E tests for the discuss→breakdown workflow.

Purpose: Validate the complete architect workflow from discussion through phase creation.

Output: E2E tests proving architect mode switching and phase persistence work.
</objective>

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

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md

# Test infrastructure
@src/test/harness.ts
@src/test/e2e/recovery-scenarios.test.ts

# Prior plan context
@.planning/phases/11-architect-agent/11-07-SUMMARY.md
</context>

<tasks>

<task type="auto">
  <name>Task 1: Add TestHarness helpers for architect modes</name>
  <files>src/test/harness.ts</files>
  <action>
Add convenience methods for architect mode scenarios:

```typescript
/**
 * Set up scenario where architect completes discussion with decisions
 */
setArchitectDiscussComplete(
  agentName: string,
  decisions: Array<{ topic: string; decision: string; reason: string }>,
  summary: string
): void {
  this.mockAgentManager.setScenario(agentName, {
    status: 'context_complete',
    delay: 0,
    decisions,
    summary,
  });
}

/**
 * Set up scenario where architect needs more questions in discuss mode
 */
setArchitectDiscussQuestions(
  agentName: string,
  questions: Array<{ id: string; question: string; options?: Array<{ label: string }> }>
): void {
  this.mockAgentManager.setScenario(agentName, {
    status: 'questions',
    delay: 0,
    questions,
  });
}

/**
 * Set up scenario where architect completes breakdown with phases
 */
setArchitectBreakdownComplete(
  agentName: string,
  phases: Array<{ number: number; name: string; description: string }>
): void {
  this.mockAgentManager.setScenario(agentName, {
    status: 'breakdown_complete',
    delay: 0,
    phases,
  });
}

/**
 * Get initiative by ID through tRPC
 */
async getInitiative(id: string): Promise<Initiative | null> {
  try {
    return await this.caller.getInitiative({ id });
  } catch {
    return null;
  }
}

/**
 * Get phases for initiative through tRPC
 */
async getPhases(initiativeId: string): Promise<Phase[]> {
  return this.caller.listPhases({ initiativeId });
}

/**
 * Create initiative through tRPC
 */
async createInitiative(name: string, description?: string): Promise<Initiative> {
  return this.caller.createInitiative({ name, description });
}

/**
 * Create phases from breakdown output through tRPC
 */
async createPhasesFromBreakdown(
  initiativeId: string,
  phases: Array<{ number: number; name: string; description: string }>
): Promise<Phase[]> {
  return this.caller.createPhasesFromBreakdown({ initiativeId, phases });
}
```

Update imports as needed for Initiative and Phase types.
  </action>
  <verify>npm run build passes</verify>
  <done>TestHarness has architect mode helpers</done>
</task>

<task type="auto">
  <name>Task 2: Add E2E test for discuss mode</name>
  <files>src/test/e2e/architect-workflow.test.ts</files>
  <action>
Create new E2E test file:

```typescript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { TestHarness } from '../harness.js';

describe('Architect Workflow E2E', () => {
  let harness: TestHarness;

  beforeEach(async () => {
    harness = await TestHarness.create();
  });

  afterEach(async () => {
    await harness.cleanup();
  });

  describe('discuss mode', () => {
    it('should spawn architect in discuss mode and complete with decisions', async () => {
      // Create initiative
      const initiative = await harness.createInitiative('Auth System', 'User authentication');

      // Set up discuss completion scenario
      harness.setArchitectDiscussComplete('auth-discuss', [
        { topic: 'Auth Method', decision: 'JWT', reason: 'Stateless, scalable' },
        { topic: 'Token Storage', decision: 'httpOnly cookie', reason: 'XSS protection' },
      ], 'Auth approach decided');

      // Spawn architect in discuss mode
      const agent = await harness.caller.spawnArchitectDiscuss({
        name: 'auth-discuss',
        initiativeId: initiative.id,
      });

      expect(agent.mode).toBe('discuss');

      // Wait for completion
      await harness.advanceTimers();

      // Verify agent stopped with context_complete
      const events = harness.getEmittedEvents('agent:stopped');
      expect(events).toHaveLength(1);
      expect(events[0].payload.reason).toBe('context_complete');
    });

    it('should pause on questions and resume with answers', async () => {
      const initiative = await harness.createInitiative('Auth System');

      // First, agent asks questions
      harness.setArchitectDiscussQuestions('auth-discuss', [
        { id: 'q1', question: 'JWT or Session?', options: [{ label: 'JWT' }, { label: 'Session' }] },
        { id: 'q2', question: 'OAuth providers?' },
      ]);

      const agent = await harness.caller.spawnArchitectDiscuss({
        name: 'auth-discuss',
        initiativeId: initiative.id,
      });

      await harness.advanceTimers();

      // Agent should be waiting
      const waitingAgent = await harness.caller.getAgent({ name: 'auth-discuss' });
      expect(waitingAgent?.status).toBe('waiting_for_input');

      // Get pending questions
      const pending = await harness.mockAgentManager.getPendingQuestions(agent.id);
      expect(pending?.questions).toHaveLength(2);

      // Now set up completion scenario for after resume
      harness.setArchitectDiscussComplete('auth-discuss', [
        { topic: 'Auth', decision: 'JWT', reason: 'User chose' },
      ], 'Complete');

      // Resume with answers
      await harness.caller.resumeAgent({
        name: 'auth-discuss',
        answers: { q1: 'JWT', q2: 'Google, GitHub' },
      });

      await harness.advanceTimers();

      // Should complete
      const finalAgent = await harness.caller.getAgent({ name: 'auth-discuss' });
      expect(finalAgent?.status).toBe('idle');
    });
  });
});
```
  </action>
  <verify>npm test src/test/e2e/architect-workflow.test.ts passes</verify>
  <done>Discuss mode E2E tests added</done>
</task>

<task type="auto">
  <name>Task 3: Add E2E test for breakdown mode and phase persistence</name>
  <files>src/test/e2e/architect-workflow.test.ts</files>
  <action>
Add breakdown tests to the same file:

```typescript
describe('breakdown mode', () => {
  it('should spawn architect in breakdown mode and create phases', async () => {
    const initiative = await harness.createInitiative('Auth System');

    // Set up breakdown completion
    harness.setArchitectBreakdownComplete('auth-breakdown', [
      { number: 1, name: 'Database Setup', description: 'User table and auth schema' },
      { number: 2, name: 'JWT Implementation', description: 'Token generation and validation' },
      { number: 3, name: 'Protected Routes', description: 'Middleware and route guards' },
    ]);

    const agent = await harness.caller.spawnArchitectBreakdown({
      name: 'auth-breakdown',
      initiativeId: initiative.id,
    });

    expect(agent.mode).toBe('breakdown');

    await harness.advanceTimers();

    // Verify stopped with breakdown_complete
    const events = harness.getEmittedEvents('agent:stopped');
    expect(events).toHaveLength(1);
    expect(events[0].payload.reason).toBe('breakdown_complete');
  });

  it('should persist phases from breakdown output', async () => {
    const initiative = await harness.createInitiative('Auth System');

    const phasesData = [
      { number: 1, name: 'Foundation', description: 'Core setup' },
      { number: 2, name: 'Features', description: 'Main features' },
    ];

    // Persist phases (simulating what would happen after breakdown)
    const created = await harness.createPhasesFromBreakdown(initiative.id, phasesData);

    expect(created).toHaveLength(2);
    expect(created[0].number).toBe(1);
    expect(created[1].number).toBe(2);

    // Verify retrieval
    const phases = await harness.getPhases(initiative.id);
    expect(phases).toHaveLength(2);
    expect(phases[0].name).toBe('Foundation');
    expect(phases[1].name).toBe('Features');
  });
});

describe('full workflow', () => {
  it('should complete discuss → breakdown → phases workflow', async () => {
    // 1. Create initiative
    const initiative = await harness.createInitiative('Full Workflow Test');

    // 2. Discuss phase
    harness.setArchitectDiscussComplete('discuss-agent', [
      { topic: 'Scope', decision: 'MVP only', reason: 'Time constraint' },
    ], 'Scope defined');

    await harness.caller.spawnArchitectDiscuss({
      name: 'discuss-agent',
      initiativeId: initiative.id,
    });
    await harness.advanceTimers();

    // 3. Breakdown phase
    harness.setArchitectBreakdownComplete('breakdown-agent', [
      { number: 1, name: 'Core', description: 'Core functionality' },
      { number: 2, name: 'Polish', description: 'UI and UX' },
    ]);

    await harness.caller.spawnArchitectBreakdown({
      name: 'breakdown-agent',
      initiativeId: initiative.id,
      contextSummary: 'MVP scope defined',
    });
    await harness.advanceTimers();

    // 4. Persist phases
    await harness.createPhasesFromBreakdown(initiative.id, [
      { number: 1, name: 'Core', description: 'Core functionality' },
      { number: 2, name: 'Polish', description: 'UI and UX' },
    ]);

    // 5. Verify final state
    const phases = await harness.getPhases(initiative.id);
    expect(phases).toHaveLength(2);

    // Both agents should be idle
    const agents = await harness.caller.listAgents();
    expect(agents.filter(a => a.status === 'idle')).toHaveLength(2);
  });
});
```
  </action>
  <verify>npm test src/test/e2e/architect-workflow.test.ts passes</verify>
  <done>Full architect workflow E2E tests added</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] npm run build succeeds
- [ ] npm test passes all tests including new E2E tests
- [ ] Discuss mode completion tested
- [ ] Discuss Q&A flow tested
- [ ] Breakdown mode completion tested
- [ ] Phase persistence tested
- [ ] Full workflow tested
</verification>

<success_criteria>

- All tasks completed
- TestHarness has architect-specific helpers
- E2E tests cover discuss → breakdown → persist workflow
- All existing tests still pass
</success_criteria>

<output>
After completion, create `.planning/phases/11-architect-agent/11-08-SUMMARY.md`
</output>
