---
phase: 09-extended-scenarios
plan: 01
type: execute
wave: 1
depends_on: []
files_modified: [src/test/e2e/extended-scenarios.test.ts]
autonomous: true
phase_depends_on: [08.1-agent-output-schema]
---

<objective>
Create E2E tests proving conflict hand-back round-trip and multi-agent parallel completion work correctly.

Purpose: Validate the full conflict resolution cycle (conflict detected -> agent resolves -> merge succeeds) and multiple agents working/completing/merging in parallel.
Output: Extended E2E test file with conflict round-trip and parallel completion scenarios.
</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
@.planning/phases/09-extended-scenarios/09-CONTEXT.md
@.planning/phases/08-e2e-scenario-tests/08-01-SUMMARY.md
@.planning/phases/08-e2e-scenario-tests/08-02-SUMMARY.md
@.planning/phases/08.1-agent-output-schema/08.1-02-SUMMARY.md

@src/test/harness.ts
@src/test/fixtures.ts
@src/test/e2e/edge-cases.test.ts
@src/test/e2e/happy-path.test.ts
</context>

<tasks>

<task type="auto">
  <name>Task 1: Create conflict hand-back round-trip tests</name>
  <files>src/test/e2e/extended-scenarios.test.ts</files>
  <action>
Create new test file with describe block "Conflict hand-back round-trip". Test the full cycle:

1. **Test: conflict triggers resolution task, agent resolves, merge succeeds**
   - Seed SIMPLE_FIXTURE, complete Task A
   - Create agent in agentRepository with worktreeId
   - Create worktree via MockWorktreeManager
   - Set merge conflict result for first merge attempt
   - Queue and process merge (should fail with conflict)
   - Verify: merge:conflicted event, task marked blocked, resolution task created
   - Clear the merge conflict (setMergeResult to success)
   - Find the resolution task, dispatch it to an agent
   - Complete the resolution task
   - Queue original task for re-merge
   - Process merge again (should succeed)
   - Verify: merge:completed event for original task

2. **Test: conflict resolution preserves original task context**
   - Similar setup with conflict
   - Verify resolution task has correct parentTaskId linking back
   - Verify resolution task prompt contains conflict file info

3. **Test: multiple sequential conflicts resolved in order**
   - Set up 2 tasks (A and B) both with conflicts
   - Process merges, both fail
   - Resolve A's conflict, merge A succeeds
   - Resolve B's conflict, merge B succeeds
   - Verify merge order matches resolution order

Use same patterns as edge-cases.test.ts:
- vi.useFakeTimers() for async control
- Pre-seed idle agent before dispatch
- harness.setAgentScenario with new schema format: `{ status: 'done' | 'question' | 'unrecoverable_error', ... }`
- harness.worktreeManager.setMergeResult for conflict injection
- Manual agentRepository.create for coordination tests
  </action>
  <verify>npm test src/test/e2e/extended-scenarios.test.ts -- --run passes</verify>
  <done>3+ conflict round-trip tests passing, proving full cycle works</done>
</task>

<task type="auto">
  <name>Task 2: Create multi-agent parallel completion tests</name>
  <files>src/test/e2e/extended-scenarios.test.ts</files>
  <action>
Add describe block "Multi-agent parallel work" to the test file. Test scenarios:

1. **Test: multiple agents complete tasks in parallel**
   - Seed PARALLEL_FIXTURE (4 independent tasks)
   - Pre-seed 3 idle agents
   - Queue all 4 tasks
   - Dispatch 3 tasks in parallel (3 agents working)
   - Use vi.runAllTimersAsync() to complete all 3 agents
   - Verify: 3 agent:stopped events
   - Complete all 3 tasks
   - Dispatch remaining task
   - Verify: all 4 tasks completed

2. **Test: parallel merges process in correct dependency order**
   - Use COMPLEX_FIXTURE (has dependency structure)
   - Complete Task 1A and Task 1B (no dependencies)
   - Set up worktrees and agents for both
   - Queue both for merge
   - Process merges - both should succeed (no dependencies between them)
   - Verify: merge:completed for both in same batch
   - Complete Task 2A (depends on 1A) and Task 3A (depends on 1B)
   - Queue and merge - should succeed
   - Complete Task 4A (depends on 2A and 3A)
   - Queue and merge - should succeed
   - Verify: final merge order respects dependency graph

3. **Test: parallel dispatch with mixed outcomes**
   - Pre-seed 2 agents
   - Dispatch 2 tasks, one set to succeed, one set to crash
   - Verify: one agent:stopped, one agent:crashed
   - Verify: completed task can merge, crashed task stays in_progress

Use PARALLEL_FIXTURE for independent tasks, COMPLEX_FIXTURE for dependency scenarios.
  </action>
  <verify>npm test src/test/e2e/extended-scenarios.test.ts -- --run passes</verify>
  <done>3+ parallel work tests passing, proving multi-agent scenarios work</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] `npm test src/test/e2e/extended-scenarios.test.ts -- --run` passes
- [ ] At least 6 new tests (3 conflict + 3 parallel)
- [ ] No flaky tests (run twice to verify)
- [ ] Test file follows existing patterns from edge-cases.test.ts
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- Conflict round-trip fully tested (detect -> resolve -> re-merge)
- Multi-agent parallel scenarios validated
- No regressions in existing E2E tests
</success_criteria>

<output>
After completion, create `.planning/phases/09-extended-scenarios/09-01-SUMMARY.md`
</output>
