<!-- LEGACY_READ -->
<!--
// LEGACY TABLE WARNING:
// product_fitment is deprecated and must not be used for
// fitment evaluation, confidence scoring, or reconciliation.
// Use fitment_resolved instead.
-->
# Phase 3 & Phase 4 — Cursor Test Cases (Locked)

These tests validate behavioral correctness, phase boundaries, and determinism.
They are written to be used by Cursor test agents or manually executed via CLI.

---

## Phase 3 — Evidence Emission Tests

### Test P3-01 — Zero Evidence Is Valid (Turn14)

**Setup**

- `turn14_items.item_json` contains no fitment arrays

**Execution**

- Run `turn14_evidence.php`

**Expected**

- `fitment_evidence`: 0 new rows
- Script exits SUCCESS

**Failure Conditions**

- Any emitted rows
- Any warnings or fallback behavior

---

### Test P3-02 — MotorState Evidence Emission

**Setup**

- `product_fitment_raw` contains ≥1 row with:
  - `extracted_json.fitments` array

**Execution**

- Run Phase 3 MotorState extractor

**Expected**

- One `fitment_evidence` row per vehicle tuple
- Columns populated:
  - `product_id`
  - `year`, `make`, `model`
  - `source = 'motorstate'`
  - `source_confidence = 1.000`

---

### Test P3-03 — Raw Confidence Archival (Optional)

**Setup**

- `extracted_json.confidence = 0.873`

**Execution**

- Run Phase 3 extractor

**Expected**

- `raw_source_confidence = 0.873`
- No change to row count
- No branching behavior

---

### Test P3-04 — Phase Boundary Enforcement

**Execution**

- Static scan Phase 3 code

**Expected**

- No writes to tables other than `fitment_evidence`
- No reads from Phase 4 tables

---

## Phase 4 — Validation Harness Tests

### Test P4-V01 — Validation PASS (Single Source)

**Setup**

- One `fitment_evidence` row per vehicle tuple

**Execution**

- Run `validate_reconciliation.php`

**Expected**

```json
{ "status": "PASS" }
```

---

### Test P4-V02 — Validation FAIL (Mixed Vehicle Tuple)

**Setup**

- Two evidence rows with same product_id but different model

**Execution**

- Run validation

**Expected**

```json
{
  "status": "FAIL",
  "error_code": "MIXED_VEHICLE_GROUP"
}
```

---

### Test P4-V03 — Validation FAIL (Invalid Confidence)

**Setup**

- `raw_source_confidence = 1.500`

**Expected**

- Validation FAIL
- No reconciliation run allowed

---

## Phase 4 — Reconciliation Runner Tests

### Test P4-R01 — Single Source Resolution

**Setup**

- One evidence row

**Execution**

- Run reconciliation

**Expected**

- One `fitment_resolved` row
- `final_confidence = source_multiplier`
- `confidence_band = HIGH`

---

### Test P4-R02 — Multi-Source Agreement Boost

**Setup**

- Two evidence rows from different sources

**Expected**

- Confidence boosted
- `confidence_band = CERTAIN` if ≥0.95

---

### Test P4-R03 — Vendor Confidence Modifier Applied

**Setup**

- Two evidence rows
- Vendor confidence values: 0.9 and 0.7

**Expected**

- Modifier uses min = 0.7
- Confidence reduced accordingly

---

### Test P4-R04 — Idempotency

**Execution**

- Run reconciliation twice

**Expected**

- Second run produces no net changes
- Same row hashes

---

## Phase Boundary Tests

### Test X-01 — No Backward Writes

**Execution**

- Run Phase 4

**Expected**

- `fitment_evidence` unchanged

---

### Test X-02 — Override Safety

**Setup**

- Insert `fitment_overrides` row

**Expected**

- Phase 4 does NOT overwrite override
- `override_flag = 1`

---

## Test Philosophy (Locked)

- Evidence is immutable
- Decisions are deterministic
- Overrides are explicit
- Tests fail fast

If any test fails, stop the pipeline immediately.
