# Cursor Test Plan — Fitment & Ingestion (No CLI DB Access)

This document defines a comprehensive, Cursor-safe test plan for validating fitment extraction, confidence backfill, and distributor ingestion without CLI database access.

All tests are designed to run via:
- Web-accessible PHP scripts
- Browser execution
- Read-only verification endpoints

No direct DB CLI access is assumed or required.

---

## 🧭 Testing Principles (Locked)

- ❌ No DB CLI (mysql, psql, etc.)
- ✅ Tests must execute via HTTP or browser
- ✅ Scripts must self-report status and counts
- ❌ No schema inspection via CLI
- ✅ Read-only verification is authoritative
- ❌ No data mutation during verification tests

---

## 🧪 Test Categories

1. Phase 1 Fitment Extraction
2. Phase 1 Confidence Backfill
3. Phase 2 Product Description Ingestion
4. Phase Boundary Enforcement
5. Idempotency & Re-run Safety
6. Prompt Governance & Drift Detection
7. Distributor ↔ Product Identity Integrity

---

## 1️⃣ Phase 1 — Fitment Extraction Tests

### Test 1.1 — Extraction Endpoint Executes

**Method:** Browser / HTTP

- Invoke the Phase 1 extraction runner endpoint
- Confirm:
  - HTTP 200
  - JSON response
  - No PHP fatal errors

**Expected:**
- Extraction completes or reports controlled failure

---

### Test 1.2 — Confidence Enforcement

**Method:** Browser / HTTP

- Run extraction on a known product
- Confirm output includes:
  - `confidence` at root
  - numeric value between 0.0 and 1.0

**Failure Condition:**
- Script halts with `confidence_missing_or_invalid`

---

## 2️⃣ Phase 1 — Confidence Backfill Tests

### Test 2.1 — Backfill Runs Without Timeout

**Method:** Browser

- Visit:
  ```
  /genie/fitment/run_phase1_gpt_extract.php?backfill_confidence=1
  ```

**Expected:**
- Script runs for extended duration
- Reports batch progress
- No `max_execution_time` error

---

### Test 2.2 — Progress Is Monotonic

**Method:** Browser

- Refresh backfill endpoint multiple times
- Confirm:
  - Rows remaining decreases
  - Rows updated > 0 until completion

---

## 3️⃣ Phase 2 — Product Description Ingestion

### Test 3.1 — Turn14 Description Backfill

**Method:** Browser

- Run:
  ```
  /genie/turn14/backfill_product_description_gpt.php
  ```

**Expected Output:**
- Batch counts
- GPT success counts
- Rows updated > 0

---

### Test 3.2 — Motorstate Description Backfill

**Method:** Browser

- Run:
  ```
  /genie/motorstate/backfill_product_description_gpt.php
  ```

**Expected:**
- Identical behavior to Turn14 script

---

## 4️⃣ Phase Boundary Enforcement Tests

### Test 4.1 — Descriptions Not Used for Fitment

**Method:** Static inspection (Cursor)

- Search in fitment backfill scripts for:
  - `product_description_gpt`

**Expected:**
- No reads of description fields in fitment logic

---

### Test 4.2 — No Cross-Phase Writes

**Method:** Static inspection

- Confirm:
  - Ingestion scripts write only to distributor tables
  - Fitment scripts write only to fitment tables

---

## 5️⃣ Idempotency Tests

### Test 5.1 — Re-run Safety (Descriptions)

**Method:** Browser

- Re-run Turn14 + Motorstate backfills

**Expected:**
- Rows updated = 0
- No content overwritten

---

### Test 5.2 — Re-run Safety (Fitment Raw)

**Method:** Browser

- Re-run raw fitment backfill scripts

**Expected:**
- No duplicate insertions
- Script reports zero new rows or skips duplicates

---

## 6️⃣ Prompt Governance Tests

### Test 6.1 — Locked Prompt Presence

**Method:** Static inspection

- Confirm `$LOCKED_PROMPT` exists
- Confirm no `PASTE_` placeholders remain

---

### Test 6.2 — Deprecated Prompt Isolation

**Method:** Static inspection

- Confirm deprecated prompts are:
  - clearly marked, or
  - moved to `/deprecated/`

---

## 7️⃣ Distributor ↔ Product Identity Tests

### Test 7.1 — Join Verification

**Method:** Browser

- Run:
  ```
  /genie/fitment/verify_distributor_product_joins.php
  ```

**Expected Output:**
- Total products per distributor
- Unmatched count
- Pass/fail flag

Unmatched ≠ failure unless rising unexpectedly.

---

## 🚨 Known Limitations (Explicit)

- DB row-level inspection not possible
- Constraints must be inferred from behavior
- Duplicate protection validated by rerun safety

---

## 🟢 Exit Criteria (Phase 2 Freeze)

Phase 2 is considered complete and frozen when:
- All backfills run without error
- All verification scripts return expected output
- Re-running scripts produces no mutations
- No Phase boundary violations exist
- Global alignment check returns ON TRACK

---

## 🧭 If a Test Fails — What to Do

- ❌ Do NOT patch inline
- ✅ Generate a targeted Cursor Canvas remediation
- ✅ Re-run only the affected test category

---

## Final Note

This plan is intentionally boring, observable, and Cursor-compatible.

If it passes, you are safe to:
- Freeze Phase 2
- Enter Phase 3 (read-only reconciliation)
