# Refactoring Plan for Firehose Blog Controller Tests

## Context
Based on context.md, we have a Phoenix blog controller with repetitive validation tests that need refactoring.

## Goals
1. Extract test helpers to reduce code duplication
2. Standardize test naming conventions
3. Reorganize tests to follow defensive programming flow
4. Add missing negative test coverage
5. Create separate contexts for different refactorings

## Recommended Planner Agents

### 1. TestHelperExtractor Agent
**Purpose**: Handle Smell 1 (Repetitive Validation Tests) and Smell 4 (Redundant Layout Assertions)

**Tasks**:
- Extract page validation test logic into `test_page_fallback/2` helper
- Create `assert_has_app_layout/1` helper for layout assertions
- Move helpers to support module or test case

**Context Isolation**: This can run in a separate test context without affecting controller logic.

### 2. TestOrganizer Agent  
**Purpose**: Handle Smell 5 (Test Order) and Smell 3 (Inconsistent Naming)

**Tasks**:
- Reorder test blocks: validation first, then success cases, then edge cases
- Standardize all test descriptions to follow pattern: "GET /blog/:type/:slug returns [result]"
- Rename describe blocks to follow semantic order

**Context Isolation**: Pure test organization, no production code changes.

### 3. CoverageExpander Agent
**Purpose**: Handle Smell 2 (Missing Negative Tests) and Smell 8 (Edge Cases)

**Tasks**:
- Add test for unknown blog_id (`/blog/invalid`)
- Add test for empty page parameter (`?page=`)
- Add test for very large page numbers
- Add test for invalid blog halt behavior (Smell 6)

**Context Isolation**: Adds new tests without modifying existing logic.

### 4. ResponseHelperCreator Agent
**Purpose**: Handle Smell 7 (Mixed Response Types)

**Tasks**:
- Create `assert_html/2` and `assert_json/2` helpers
- Ensure proper content-type verification
- Update existing tests to use new helpers

## Execution Strategy
Run each agent in isolated contexts:
1. TestHelperExtractor → creates helper functions
2. ResponseHelperCreator → builds response assertions  
3. TestOrganizer → reorganizes existing structure
4. CoverageExpander → adds new test cases

This keeps the main thread clean and allows focused changes per agent.