**Organization**: Tasks are grouped by user story to enable independent implementation and testing of each story.
## Format: `[ID] [P?] [Story] Description`
-**[P]**: Can run in parallel (different files, no dependencies)
-**[Story]**: Which user story this task belongs to (e.g., US1, US2)
- Include exact file paths in descriptions
---
## Phase 1: Setup (Shared Infrastructure)
**Purpose**: Project initialization and basic structure
-[x] T001 [P] Initialize `FaultMode` enum in `src/main/java/com/banking/server/FaultInjector.java` with modes: `NONE`, `LOST_REQUEST`, `SERVER_CRASH`, `RESPONSE_LOSS`, `DELAY`
-[x] T002 [P] Create `FaultConfiguration` data record in `src/main/java/com/banking/server/FaultInjector.java` to hold `faultMode` and `injectionCount`
---
## Phase 2: Foundational (Blocking Prerequisites)
**Purpose**: Core infrastructure that MUST be complete before ANY user story can be implemented
-[] T003 Implement `FaultConfiguration` extractor in `src/main/java/com/banking/server/FaultInjector.java` to parse `X-Fault-Mode` and `X-Fault-Count` headers from `HttpExchange`
-[] T004 Implement `shouldInject(FaultConfiguration config)` logic in `src/main/java/com/banking/server/FaultInjector.java` based on the provided `injectionCount` from the header
**Checkpoint**: Foundation ready - user story implementation can now begin in parallel
---
## Phase 3: User Story 1 - Request Delivery Failure Simulation (Priority: P1) 🎯 MVP
**Goal**: Simulate a request that is lost before the server begins processing.
**Independent Test**: Trigger `LOST_REQUEST` for a specific transaction and verify zero balance/ledger changes until the retry succeeds.
### Implementation for User Story 1
-[] T005 [US1] Integrate `FaultInjector` check at the very start of `src/main/java/com/banking/server/RequestHandler.java`'s handle method (before reading the request body)
-[] T006 [US1] Implement "lost request" behavior in `src/main/java/com/banking/server/RequestHandler.java` by closing the connection immediately without sending a response
-[] T007 [US1] Verify that a subsequent retry with `X-Fault-Mode: NONE` (or count exhausted) results in exactly one successful withdrawal
**Checkpoint**: User Story 1 should be fully functional and testable independently
---
## Phase 4: User Story 2 - Server Crash Before Execution Simulation (Priority: P1) 🎯 MVP
**Goal**: Simulate a server crash after receiving a request but before committing the transaction.
**Independent Test**: Trigger `SERVER_CRASH`, restart server, and verify no partial state persists.
### Implementation for User Story 2
-[] T008 [US2] Integrate `FaultInjector` check in `src/main/java/com/banking/server/RequestHandler.java` immediately before the database commit call
-[] T009 [US2] Implement "server crash" behavior in `src/main/java/com/banking/server/RequestHandler.java` by triggering `System.exit(1)` or a fatal runtime exception to terminate the process
-[] T010 [US2] Verify that after server restart, a retry results in a successful transaction and the final balance is correct (initial - sum of unique successful withdrawals)
**Checkpoint**: User Story 2 should be fully functional and testable independently
---
## Phase N: Polish & Cross-Cutting Concerns
**Purpose**: Improvements that affect multiple user stories
-[] T011 [P] Ensure existing `RESPONSE_LOSS` and `DELAY` modes continue to behave exactly as they did before the redesign in `src/main/java/com/banking/server/FaultInjector.java`
-[] T012 [P] Refactor `FaultInjector` to ensure no new libraries were added per constraints
-[] T013 Run `quickstart.md` validation for all four fault modes (Lost, Crash, Response Loss, Delay)
-[] T014 Code cleanup and documentation updates in `specs/003-fault-simulator/`
---
## Dependencies & Execution Order
### Phase Dependencies
-**Setup (Phase 1)**: No dependencies - can start immediately
-**Foundational (Phase 2)**: Depends on Setup completion - BLOCKS all user stories
-**User Stories (Phase 3+)**: All depend on Foundational phase completion
-**Polish (Final Phase)**: Depends on all desired user stories being complete
### User Story Dependencies
-**User Story 1 (P1)**: Can start after Foundational (Phase 2)
-**User Story 2 (P1)**: Can start after Foundational (Phase 2)
### Parallel Opportunities
- T001 and T002 can be implemented in parallel.
- US1 and US2 can be implemented in parallel once Phase 2 is complete as they target different injection points in `RequestHandler`.
---
## Implementation Strategy
### MVP First (User Story 1 & 2)
1. Complete Phase 1: Setup
2. Complete Phase 2: Foundational
3. Complete Phase 3: User Story 1 (Lost Request)
4. Complete Phase 4: User Story 2 (Server Crash)
5.**STOP and VALIDATE**: Run `quickstart.md` tests for both modes.
### Incremental Delivery
1. Setup + Foundational $\rightarrow$ Foundation ready
2. User Story 1 $\rightarrow$ Test $\rightarrow$ Deliver
3. User Story 2 $\rightarrow$ Test $\rightarrow$ Deliver
4. Polish $\rightarrow$ Verify all modes $\rightarrow$ Final Delivery