# Phase 06: Test Strategy Hooks

## Entry Gate

```bash
devforgeai-validate phase-check ${DEVARCH_ID} --workflow=development-architecture --from=05 --to=06 --project-root=. 2>&1
```

| Exit Code | Action |
|-----------|--------|
| 0 | Proceed to Phase 06 |
| 127 | CLI not installed — proceed without enforcement |
| Other | HALT — previous phase not complete |

---

## Contract

| Attribute | Value |
|-----------|-------|
| **PURPOSE** | Derive per-component test-strategy hooks that feed TDD inside `/dev` — for each feature component, the test approach, the coverage layer (which drives the 95% / 85% / 80% threshold), and the seams to mock. The hooks are derived IN-SKILL from the project test plan (`test-plan.ai.yaml`): applying the project-level test policy to this feature's components is the development architect's own deliverable. No subagent is invoked — `test-plan-architect` produces the project-level plan once, in the system-architecture phase, and is deliberately NOT used here. |
| **REFERENCE** | `.claude/skills/spec-driven-development-architecture/references/development-architecture-output.schema.json` |
| **STEP COUNT** | 4 mandatory steps |

## Phase Exit Criteria

Before this phase can complete, ALL of the following MUST be true:

- [ ] `devforgeai/specs/context/test-plan.ai.yaml` read from disk (the project test plan)
- [ ] `test_strategy_hooks` enumerated — one hook per feature component, each with an `approach`
- [ ] Every hook's `coverage_layer` is one of the 3 enum values, derived from the component's layer
- [ ] `mock_seams` aligned with the test plan's `mocking_strategy` and `integration_boundaries`

**IF any criterion is unmet: HALT. Do NOT proceed to Phase 07.**

---

## Reference Loading [MANDATORY]

```
Read(file_path=".claude/skills/spec-driven-development-architecture/references/development-architecture-output.schema.json")
Read(file_path="devforgeai/specs/context/test-plan.ai.yaml")
```

`test-plan.ai.yaml` is the constitutional project test plan this phase MUST load — it is
the sole input from which every `test_strategy_hook` is derived (Step 6.1, a HALT-if-missing
read). It is hook-enforced: `pre-phase-record-reference-check.sh` (ADR-091/ADR-135) blocks
`phase-record` for this phase if it was not Read(). The `.yaml` companion is gate-enforceable
because the producer logs constitutional `.yaml` reads and `manifest-parser.py` retains them
(gh#297/ADR-135); the output-schema `.json` above is informational (the parser excludes `.json`,
so `required[]` is exactly `[test-plan.ai.yaml]`). The `test_strategy_hooks` item shape
(`component_ref`, `approach`, `coverage_layer`, `mock_seams`) is what this phase produces.
IF any Read fails: HALT — "Phase 06 references not loaded."

Do NOT rely on memory of previous reads. Load fresh every time this phase executes.

---

## Mandatory Steps

### Step 6.1: Load the Project Test Plan

**EXECUTE:**
```
Glob(pattern="devforgeai/specs/context/test-plan.ai.yaml")
IF found:
  Read(file_path="devforgeai/specs/context/test-plan.ai.yaml")
ELSE:
  HALT — "test-plan.ai.yaml not found. The Development Architecture phase requires
  the project test plan, which the system-architecture phase produces (it is the
  7th constitutional AI-companion artifact, ADR-054). A missing test plan is a
  pipeline-integrity break — run /create-system-architecture first. Do NOT
  regenerate it here, and do NOT
  invoke test-plan-architect: that subagent's charter is the project-level plan in
  the system-architecture phase, not per-feature hooks."

Extract from the test plan:
  - mocking_strategy        — what is mocked vs. exercised for real
  - integration_boundaries  — where integration tests cross a seam
  - coverage_thresholds     — the business_logic / application / infrastructure targets
  - test_isolation_policy, fixture_management — supporting policy
```

`test-plan.ai.yaml` is constitutional and immutable — read it, never edit it. It is
the single source of truth for the project's test strategy; this phase APPLIES it
per-component, it does not redefine it.

**VERIFY:**
- `test-plan.ai.yaml` read with content length > 0 (a missing file HALTed above)
- `mocking_strategy`, `integration_boundaries`, and `coverage_thresholds` located in the plan

**RECORD:**
```bash
devforgeai-validate phase-record ${DEVARCH_ID} --workflow=development-architecture --phase=06 --step=6.1 --project-root=. 2>&1
```
```json
{ "phase": "06", "step": "6.1", "test_plan_read": true,
  "coverage_thresholds": { "business_logic": "...", "application": "...", "infrastructure": "..." } }
```

---

### Step 6.2: Derive the Per-Component Test Approach

**EXECUTE:**

For each feature component (Phase 02 `feature_components`, with its layer from
Phase 03), derive the test hook:

```
test_strategy_hook = {
  component_ref: "COMP-NNN",
  approach: "<the unit / integration / contract test approach for this component —
             grounded in the test plan's testing_philosophy and test_data_strategy>",
  coverage_layer: "<business_logic | application | infrastructure>",
  mock_seams: [ "<filled in Step 6.3>" ]
}
```

Map the component's architectural `layer` (Phase 03) to the `coverage_layer` enum,
which selects the threshold from the test plan's `coverage_thresholds`:
- `domain`         → `business_logic`   (the 95% threshold — pure logic, highest bar)
- `application`    → `application`      (the 85% threshold — orchestration)
- `infrastructure` → `infrastructure`   (the 80% threshold — adapters / persistence)
- `presentation`   → `infrastructure`   (treated under the 80% threshold — thin edge code)

Cite the threshold from `test-plan.ai.yaml` — do not invent percentages.

**VERIFY:**
- One `test_strategy_hook` per feature component
- Every hook has a non-empty `approach`
- Every `coverage_layer` is one of `business_logic` / `application` / `infrastructure`

**RECORD:**
```bash
devforgeai-validate phase-record ${DEVARCH_ID} --workflow=development-architecture --phase=06 --step=6.2 --project-root=. 2>&1
```
```json
{ "step": "6.2", "test_strategy_hooks": [ { "component_ref": "COMP-NNN",
  "approach": "...", "coverage_layer": "..." } ] }
```

---

### Step 6.3: Identify the Mock Seams

**EXECUTE:**

For each component, identify the seams its tests will mock — grounded in the test
plan's `mocking_strategy` and `integration_boundaries`:

```
mock_seams = [ "<collaborator, port, or external system this component's unit
                 tests replace with a test double>", ... ]
```

Guidance:
- A domain component is usually tested with NO mocks — it is pure logic. An empty
  `mock_seams` is the correct answer here; record it explicitly.
- An application component mocks the infrastructure ports it consumes (per the
  Phase 05 `dependency_wiring`).
- An infrastructure component's tests cross an `integration_boundary` — the test
  plan says whether that seam is mocked or exercised for real; follow it, do not
  override it.
- `mock_seams` MUST be consistent with `mocking_strategy` — if the test plan says a
  given collaborator is never mocked, do not list it as a mock seam.

**VERIFY:**
- Every hook has a `mock_seams` array (may be empty for pure-logic components)
- No `mock_seams` entry contradicts the test plan's `mocking_strategy`

**RECORD:**
```bash
devforgeai-validate phase-record ${DEVARCH_ID} --workflow=development-architecture --phase=06 --step=6.3 --project-root=. 2>&1
```
```json
{ "step": "6.3", "mock_seams_assigned": true }
```

---

### Step 6.4: Record the Test Strategy Hooks

**EXECUTE:**
```
Assemble the test_strategy_hooks array — one entry per feature component, each a
full hook with component_ref, approach, coverage_layer, and mock_seams.
```

**VERIFY:**
- `test_strategy_hooks` has one entry per feature component
- Every entry has `component_ref` and `approach`

**RECORD:**
```bash
devforgeai-validate phase-record ${DEVARCH_ID} --workflow=development-architecture --phase=06 --step=6.4 --project-root=. 2>&1
```
```json
checkpoint.phases["06"] = {
  "status": "completed",
  "test_plan_source": "devforgeai/specs/context/test-plan.ai.yaml",
  "test_strategy_hooks": [
    { "component_ref": "COMP-001", "approach": "...",
      "coverage_layer": "business_logic", "mock_seams": [ ... ] }, ...
  ]
}
```

---

## Exit Gate

```bash
devforgeai-validate phase-complete ${DEVARCH_ID} --workflow=development-architecture --phase=06 --checkpoint-passed --project-root=. 2>&1
```

| Exit Code | Action |
|-----------|--------|
| 0 | Phase 06 complete — proceed to next phase |
| 127 | CLI not installed — proceed without enforcement |
| Other | HALT — checkpoint/step validation failed |

---

## Phase Transition Display

```
Display:
  "Phase 06 Complete: Test Strategy Hooks"
  "Test hooks: {count}  |  Coverage layers: {list}"
  "Derived from test-plan.ai.yaml (project test plan)"
  "Proceeding to Phase 07: Story Seed Generation"
```
