# PROMPT.md — Ralph Loop: Singoa MVP E2E Full Test Suite (358 Tests)

## Ralph Loop Command

```bash
/ralph-loop:ralph-loop "Execute the Singoa MVP E2E test suite below. Fix all bugs found. Output <promise>CLEAN SWEEP</promise> when ALL 358 tests pass with zero failures." --completion-promise "CLEAN SWEEP" --max-iterations 50
```

## Quick Start

1. Ensure servers are running:
   ```bash
   curl -s http://localhost:8000/api/core/health/intelligent-ar/
   curl -s http://localhost:3004
   ```

2. Launch Ralph Loop:
   ```bash
   /ralph-loop:ralph-loop "$(cat PROMPT.md)" --completion-promise "CLEAN SWEEP" --max-iterations 50
   ```

---

## Mission

You are the Singoa MVP E2E Tester. Systematically test EVERY feature — frontend AND backend, all industries, all workflows. Find bugs, FIX THE CODE, retest, repeat until everything works perfectly.

## FIRST: Read State

Read `_extras/data/e2e-test-state.json`. This is your single source of truth.

- If `iteration` is 0: fresh run. Create new user, seed data, start Phase 1.
- If `iteration` > 0: pick up where you left off. Check `current_phase`.
- If `clean_sweep` is true: output `<promise>CLEAN SWEEP</promise>`.

## Server Management

Check servers every iteration:
```bash
curl -s http://localhost:8000/api/core/health/intelligent-ar/
curl -s http://localhost:3004
```

**If servers are down, START THEM YOURSELF:**
```bash
cd singoa-api && source venv/bin/activate && python manage.py runserver 0.0.0.0:8000 &
cd singoa-ui && npm run dev -- -p 3004 &
```

## Fresh User Setup (First Iteration)

1. Register via `POST /api/auth/register/` with fresh credentials
2. Check approval email sent to `shivam@singoa.com`
3. Test approval link — if broken, FIX THE CODE
4. After approval, login as new user
5. Seed data: `cd singoa-api && python manage.py seed_demo_accounts`
6. Save credentials to state file

## Frontend Testing (Chrome MCP)

For ALL frontend tests, use Chrome DevTools MCP tools:
- `take_snapshot` to read page content
- `click`, `fill`, `navigate_page` to interact
- `take_screenshot` to verify visual state
- Verify both UI rendering AND backend API responses

## Test Execution

Run `python3 _extras/scripts/tests/run_e2e_350.py` for API tests. Use Chrome MCP for frontend tests.

## Iteration Protocol — STRICT SEQUENTIAL

**DO NOT move to the next phase until the current phase is 100% passing.**

Each iteration:
1. Run tests for current phase
2. Track count: "Phase X: Y/Z passed"
3. For each failure: diagnose root cause → fix CODE (not just tests) → retest
4. Only when current phase = 100% pass, move to next phase
5. Update state file after every phase completion

## Failure Handling — FIX THE CODE

- **500 Server Error**: Read Django traceback, fix bug in singoa-api
- **Broken approval link**: Fix approval URL generation/handling
- **UI not rendering**: Fix React component in singoa-ui
- **Missing data**: Add seed data or fix data pipeline
- **405 Wrong method**: Check Django urls.py and views, fix routing
- **403 Permission**: Check permissions in views.py
- **429 Rate limit**: Add sleep between requests, retry
- **401 Token expired**: Refresh token and retry

**The goal is to make the APPLICATION work, not just make tests pass.**

## Key Paths

- Backend: `/mnt/c/Users/Shivam Bindal/Desktop/SINGOA Mvp/singoa-api/`
- Frontend: `/mnt/c/Users/Shivam Bindal/Desktop/SINGOA Mvp/singoa-ui/`
- Test runner: `_extras/scripts/tests/run_e2e_350.py`
- State file: `_extras/data/e2e-test-state.json`
- Test registry: `_extras/data/e2e-test-registry.json`

---

## FULL TEST INVENTORY (358 Tests, 8 Phases)

### PHASE 1: BACKEND HEALTH & AUTH (45 tests)

**Auth (13):**
| ID | Test | Method | Endpoint | Expected |
|----|------|--------|----------|----------|
| P1_AUTH_001 | Register POST | POST | /api/auth/register/ | 201,400 |
| P1_AUTH_002 | Login valid | POST | /api/auth/login/ | 200 |
| P1_AUTH_003 | Login wrong pw | POST | /api/auth/login/ | 401,400 |
| P1_AUTH_004 | Get profile | GET | /api/auth/profile/ | 200 |
| P1_AUTH_005 | Get me | GET | /api/auth/me/ | 200 |
| P1_AUTH_006 | Forgot password | POST | /api/auth/forgot-password/ | 200,429 |
| P1_AUTH_007 | Logout | POST | /api/auth/logout/ | 200,204 |
| P1_AUTH_008 | Token refresh | POST | /api/auth/token/refresh/ | 200,401,405 |
| P1_AUTH_009 | Login no email | POST | /api/auth/login/ | 400,429 |
| P1_AUTH_010 | Login no pw | POST | /api/auth/login/ | 400,429 |
| P1_AUTH_011 | Register dup email | POST | /api/auth/register/ | 400 |
| P1_AUTH_012 | Register weak pw | POST | /api/auth/register/ | 400,429 |
| P1_AUTH_013 | Notifications list | GET | /api/auth/notifications/ | 200 |

**Health (2):**
| P1_HEALTH_001 | Public health | GET | /api/core/health/intelligent-ar/ | 200,503 |
| P1_HEALTH_002 | Detailed health | GET | /api/core/health/intelligent-ar/detailed/ | 200,503 |

**Core Config (4):**
| P1_CONFIG_001 | Countries | GET | /api/core/countries/ | 200 |
| P1_CONFIG_002 | Regions | GET | /api/core/regions/ | 200 |
| P1_CONFIG_003 | Industries | GET | /api/core/industries/ | 200 |
| P1_CONFIG_004 | User config | GET | /api/core/user-config/ | 200 |

**Settings (18):**
| P1_SET_001 | Notif prefs GET | GET | /api/auth/settings/notification-preferences/ | 200 |
| P1_SET_002 | Notif channels GET | GET | /api/auth/settings/notification-channels/ | 200 |
| P1_SET_003 | Comm settings GET | GET | /api/auth/settings/communication/ | 200 |
| P1_SET_004 | Quiet hours GET | GET | /api/auth/settings/quiet-hours/ | 200 |
| P1_SET_005 | Digest GET | GET | /api/auth/settings/digest/ | 200 |
| P1_SET_006 | Notif prefs PUT | PUT | /api/auth/settings/notification-preferences/ | 200,400 |
| P1_SET_007 | Comm settings PUT | PUT | /api/auth/settings/communication/ | 200,400 |
| P1_SET_008 | Quiet hours PUT | PUT | /api/auth/settings/quiet-hours/ | 200,400 |
| P1_SET_009 | Digest PUT | PUT | /api/auth/settings/digest/ | 200,400 |
| P1_SET_010 | Test notif send | POST | /api/auth/settings/notification-preferences/test/ | 200,404,405 |
| P1_SET_011 | Invoice profile setup | GET | /api/invoices/generate/profile/ | 200 |
| P1_SET_012 | Invoice templates setup | GET | /api/invoices/generate/templates/ | 200 |
| P1_SET_013 | Automation rules config | GET | /api/automations/rules/ | 200 |
| P1_SET_014 | Rule templates config | GET | /api/automations/rules/templates/ | 200 |
| P1_SET_015 | Email templates config | GET | /api/automations/templates/ | 200 |
| P1_SET_016 | Comm effectiveness | GET | /api/automations/learning/communication-effectiveness/ | 200 |
| P1_SET_017 | Comm stats | GET | /api/automations/learning/communication-stats/ | 200 |
| P1_SET_018 | Industry defaults | POST | /api/automations/ar/business-rules/industry-defaults/ | 200,400,405 |

**Setup (8):**
| P1_SETUP_001 | Setup progress | GET | /api/auth/setup/progress/ | 200 |
| P1_SETUP_002 | Setup checklist | GET | /api/auth/setup/checklist/ | 200 |
| P1_SETUP_003 | Company info | GET | /api/auth/setup/company-info/ | 200 |
| P1_SETUP_004 | Subscription status | GET | /api/auth/subscription/status/ | 200,429 |
| P1_SETUP_005 | Branding | GET | /api/auth/setup/branding/ | 200 |
| P1_SETUP_006 | Pricing | GET | /api/auth/subscription/pricing/ | 200 |
| P1_SETUP_007 | Payment settings | GET | /api/auth/setup/payment-settings/ | 200 |
| P1_SETUP_008 | Invoice numbering | GET | /api/auth/setup/invoice-numbering/ | 200 |

### PHASE 2: CORE FEATURES (70 tests)

**Dashboard (9):**
| P2_DASH_001 | Dashboard metrics | GET | /api/dashboard/metrics/ | 200 |
| P2_DASH_002 | Aging analysis | GET | /api/dashboard/aging/ | 200 |
| P2_DASH_003 | Activity feed | GET | /api/dashboard/activity/ | 200 |
| P2_DASH_004 | Performance metrics | GET | /api/dashboard/performance/ | 200 |
| P2_DASH_005 | AI insights | GET | /api/dashboard/ai-insights/ | 200 |
| P2_DASH_006 | Scheduled actions | GET | /api/dashboard/scheduled-actions/ | 200 |
| P2_DASH_007 | AI activity log | GET | /api/dashboard/ai-activity/ | 200 |
| P2_DASH_008 | Collections forecast | GET | /api/dashboard/collections-forecast/ | 200 |
| P2_DASH_009 | Setup status | GET | /api/dashboard/setup/status/ | 200 |

**Invoices (15):**
| P2_INV_001 | List invoices | GET | /api/invoices/ | 200 |
| P2_INV_002 | Invoice stats | GET | /api/invoices/dashboard/stats/ | 200 |
| P2_INV_003 | Audit trail | GET | /api/invoices/audit-trail/ | 200 |
| P2_INV_004 | Invoice profile | GET | /api/invoices/generate/profile/ | 200 |
| P2_INV_005 | Templates list | GET | /api/invoices/generate/templates/ | 200 |
| P2_INV_006 | Generated invoices | GET | /api/invoices/generate/invoices/ | 200 |
| P2_INV_007 | Bulk template | GET | /api/invoices/bulk/template/ | 200 |
| P2_INV_008 | Review queue | GET | /api/invoices/generate/review-queue/ | 200 |
| P2_INV_009 | Pending PO count | GET | /api/invoices/purchase-orders/pending/count/ | 200 |
| P2_INV_010 | Email suggestions | GET | /api/invoices/suggestions/review-queue/ | 200 |
| P2_INV_011 | Create invoice | POST | /api/invoices/create/ | 201,400 |
| P2_INV_012 | Debug endpoint | GET | /api/invoices/debug/ | 200 |
| P2_INV_013 | Relink customers | POST | /api/invoices/relink-customers/ | 200,400,405 |
| P2_INV_014 | Collection plan | GET | /api/invoices/collection-plan/ | 200,404,500 |
| P2_INV_015 | Validate invoice | POST | /api/invoices/validate/ | 200,400 |

**Customers (8):**
| P2_CUST_001 | List customers | GET | /api/invoices/customers/ | 200 |
| P2_CUST_002 | Customer stats | GET | /api/invoices/customers/stats/ | 200 |
| P2_CUST_003 | Customer detail | GET | /api/invoices/customers/1/ | 200,404 |
| P2_CUST_004 | Customer notes | GET | /api/invoices/customers/1/notes/ | 200,404 |
| P2_CUST_005 | Customer risk profile | GET | /api/invoices/customers/1/risk-profile/ | 200,404 |
| P2_CUST_006 | Customer risk history | GET | /api/invoices/customers/1/risk-history/ | 200,404 |
| P2_CUST_007 | Customer activity | GET | /api/invoices/customers/1/activity/ | 200,404 |
| P2_CUST_008 | Customer search | GET | /api/invoices/customers/?search=test | 200 |

**Payments (13):**
| P2_PAY_001 | List payments | GET | /api/payments/list/ | 200 |
| P2_PAY_002 | Unmatched payments | GET | /api/payments/unmatched/ | 200 |
| P2_PAY_003 | Payment stats | GET | /api/payments/stats/ | 200 |
| P2_PAY_004 | Payment matches | GET | /api/payments/matches/ | 200 |
| P2_PAY_005 | Dashboard report | GET | /api/payments/reports/dashboard/ | 200 |
| P2_PAY_006 | Summary report | GET | /api/payments/reports/summary/ | 200 |
| P2_PAY_007 | Unmatched aging | GET | /api/payments/reports/unmatched-aging/ | 200 |
| P2_PAY_008 | Confidence dist | GET | /api/payments/reports/confidence/ | 200 |
| P2_PAY_009 | AI vs manual | GET | /api/payments/reports/ai-vs-manual/ | 200 |
| P2_PAY_010 | Cash reconciliation | GET | /api/payments/reports/reconciliation/ | 200 |
| P2_PAY_011 | Audit export | GET | /api/payments/reports/audit-export/ | 200 |
| P2_PAY_012 | Record payment | POST | /api/payments/ | 200,201,400,405 |
| P2_PAY_013 | Payment verify | POST | /api/payments/verify/ | 200,400 |

**Risk (7):**
| P2_RISK_001 | Risk clients | GET | /api/risk/clients/ | 200 |
| P2_RISK_002 | Risk alerts | GET | /api/risk/alerts/ | 200 |
| P2_RISK_003 | Risk stats | GET | /api/risk/stats/ | 200 |
| P2_RISK_004 | Top risks | GET | /api/risk/top-risks/ | 200,403 |
| P2_RISK_005 | Risk history | GET | /api/risk/history/ | 200 |
| P2_RISK_006 | Risk update | POST | /api/risk/update/ | 200,400,405 |
| P2_RISK_007 | Risk client detail | GET | /api/risk/clients/1/ | 200,404 |

**Reports (18):**
| P2_RPT_001 | Report overview | GET | /api/reports/overview/ | 200 |
| P2_RPT_002 | Aging report | GET | /api/reports/aging/ | 200 |
| P2_RPT_003 | Cashflow report | GET | /api/reports/cashflow/ | 200 |
| P2_RPT_004 | Bad debt report | GET | /api/reports/bad-debt/ | 200 |
| P2_RPT_005 | Collection perf | GET | /api/reports/collection-performance/ | 200 |
| P2_RPT_006 | Customer behavior | GET | /api/reports/customer-behavior/ | 200 |
| P2_RPT_007 | Singoa ROI | GET | /api/reports/singoa-roi/ | 200 |
| P2_RPT_008 | Report history | GET | /api/reports/history/ | 200 |
| P2_RPT_009 | Scheduled reports | GET | /api/reports/scheduled/ | 200 |
| P2_RPT_010 | Builder schema | GET | /api/reports/builder/schema/ | 200 |
| P2_RPT_011 | Saved reports | GET | /api/reports/builder/saved/ | 200 |
| P2_RPT_012 | Report templates | GET | /api/reports/builder/templates/ | 200 |
| P2_RPT_013 | Execute tabular | POST | /api/reports/builder/execute/ | 200,400 |
| P2_RPT_014 | Execute matrix | POST | /api/reports/builder/execute/matrix/ | 200,400 |
| P2_RPT_015 | AI generate config | POST | /api/reports/builder/ai/generate-config/ | 200,400 |
| P2_RPT_016 | AI report query | POST | /api/reports/ai/query/ | 200,400,405 |
| P2_RPT_017 | Export report | POST | /api/reports/builder/export/ | 200,400 |
| P2_RPT_018 | Notifications list | GET | /api/auth/notifications/ | 200 |

### PHASE 3: AUTOMATION & AI (70 tests)

**AI Agent (10):**
| P3_AI_001 | Conversations list | GET | /api/automations/agent/conversations/ | 200 |
| P3_AI_002 | Tools list | GET | /api/automations/agent/tools/ | 200 |
| P3_AI_003 | Direct chat | POST | /api/automations/agent/chat/ | 200,201 |
| P3_AI_004 | AI snapshot | GET | /api/automations/ai/snapshot/ | 200 |
| P3_AI_005 | AI memory | GET | /api/automations/ai/memory/ | 200 |
| P3_AI_006 | Stream chat | POST | /api/automations/agent/chat/stream/ | 200,400,405 |
| P3_AI_007 | New conversation | POST | /api/automations/agent/conversations/ | 200,201,405 |
| P3_AI_008 | Confirm action | POST | /api/automations/agent/confirm/ | 200,400,404,405 |
| P3_AI_009 | AI preferences | GET | /api/automations/ai/preferences/ | 200,404 |
| P3_AI_010 | AI context | GET | /api/automations/ai/context/ | 200,404 |

**Automation Templates & AR (16):**
| P3_AUTO_001 | Email templates | GET | /api/automations/templates/ | 200 |
| P3_AUTO_002 | Automation rules | GET | /api/automations/rules/ | 200 |
| P3_AUTO_003 | Automation logs | GET | /api/automations/logs/ | 200 |
| P3_AUTO_004 | Automation stats | GET | /api/automations/stats/ | 200 |
| P3_AUTO_005 | AR workflow status | GET | /api/automations/ar/workflow/status/ | 200 |
| P3_AUTO_006 | AR action queue | GET | /api/automations/ar/action-queue/ | 200 |
| P3_AUTO_007 | AR activity feed | GET | /api/automations/ar/activity-feed/ | 200 |
| P3_AUTO_008 | AR audit log | GET | /api/automations/ar/audit-log/ | 200 |
| P3_AUTO_009 | AR human tasks | GET | /api/automations/ar/human-tasks/ | 200 |
| P3_AUTO_010 | Run automation | POST | /api/automations/run/ | 200,400,405 |
| P3_AUTO_011 | Template preview | POST | /api/automations/templates/preview/ | 200,400,405 |
| P3_AUTO_012 | AR workflow run | POST | /api/automations/ar/workflow/run/ | 200,400,405 |
| P3_AUTO_013 | Scheduled tasks | GET | /api/automations/scheduled/ | 200 |
| P3_AUTO_014 | Allocator agents | GET | /api/automations/allocator/agents/ | 200 |
| P3_AUTO_015 | Execute scheduled | POST | /api/automations/scheduled/execute/ | 200,400,405 |
| P3_AUTO_016 | Automation reports | GET | /api/automations/reports/ | 200,429 |

**Rules & NL Engine (11):**
| P3_RULE_001 | Business rules | GET | /api/automations/ar/business-rules/ | 200 |
| P3_RULE_002 | Industry defaults | POST | /api/automations/ar/business-rules/industry-defaults/ | 200,400,405 |
| P3_RULE_003 | Collection stages | GET | /api/automations/ar/collection-stages/ | 200 |
| P3_RULE_004 | Customer segments | GET | /api/automations/ar/customers/segments/ | 200 |
| P3_RULE_005 | NL rules list | GET | /api/automations/rules/nl/ | 200 |
| P3_RULE_006 | Rule templates | GET | /api/automations/rules/templates/ | 200 |
| P3_RULE_007 | Rule chat sessions | GET | /api/automations/rules/chat/sessions/ | 200 |
| P3_RULE_008 | Parse NL rule | POST | /api/automations/rules/parse/ | 200,400 |
| P3_RULE_009 | Simulate rule | POST | /api/automations/rules/simulate/ | 200,400 |
| P3_RULE_010 | Rule chat | POST | /api/automations/rules/chat/ | 200,400,405 |
| P3_RULE_011 | Create rule from template | POST | /api/automations/rules/nl/ | 200,201,400,405 |

**Boundaries & Approvals (7):**
| P3_BOUND_001 | Boundaries list | GET | /api/automations/boundaries/ | 200 |
| P3_BOUND_002 | Boundary suggestions | GET | /api/automations/boundaries/suggestions/ | 200 |
| P3_BOUND_003 | Industry defaults | GET | /api/automations/boundaries/industry-defaults/ | 200,405 |
| P3_BOUND_004 | Parse boundary | POST | /api/automations/boundaries/parse/ | 200,400 |
| P3_BOUND_005 | Check boundary | POST | /api/automations/boundaries/check/ | 200,400 |
| P3_BOUND_006 | Approvals list | GET | /api/automations/approvals/ | 200 |
| P3_BOUND_007 | Approval stats | GET | /api/automations/approvals/stats/ | 200 |

**Strategy & Review (5):**
| P3_STRAT_001 | Strategy dashboard | GET | /api/automations/strategy/dashboard/ | 200 |
| P3_STRAT_002 | Planned actions | GET | /api/automations/strategy/planned-actions/ | 200 |
| P3_REVIEW_001 | Review queue | GET | /api/automations/review-queue/ | 200 |
| P3_REVIEW_002 | Pending count | GET | /api/automations/review-queue/pending-count/ | 200 |
| P3_REVIEW_003 | Review tasks | GET | /api/automations/review-tasks/ | 200 |

**Privacy (4):**
| P3_PRIV_001 | Privacy stats | GET | /api/automations/privacy/stats/ | 200 |
| P3_PRIV_002 | Privacy audit log | GET | /api/automations/privacy/audit-log/ | 200 |
| P3_PRIV_003 | Privacy audit report | GET | /api/automations/privacy/audit-report/ | 200 |
| P3_PRIV_004 | Active sessions | GET | /api/automations/privacy/sessions/ | 200 |

**Learning (9):**
| P3_LEARN_001 | Learning dashboard | GET | /api/automations/learning/dashboard/ | 200 |
| P3_LEARN_002 | Suggestions list | GET | /api/automations/learning/suggestions/ | 200 |
| P3_LEARN_003 | Experiments list | GET | /api/automations/learning/experiments/ | 200 |
| P3_LEARN_004 | Approval patterns | GET | /api/automations/learning/patterns/ | 200 |
| P3_LEARN_005 | Approval history | GET | /api/automations/learning/approval-history/ | 200 |
| P3_LEARN_006 | Comm effectiveness | GET | /api/automations/learning/communication-effectiveness/ | 200 |
| P3_LEARN_007 | Comm stats | GET | /api/automations/learning/communication-stats/ | 200 |
| P3_LEARN_008 | Generate suggestions | POST | /api/automations/learning/suggestions/generate/ | 200,400,405 |
| P3_LEARN_009 | Bulk approve | POST | /api/automations/review-queue/bulk-approve/ | 200,400,405 |

**Audit (3):**
| P3_AUDIT_001 | Audit logs | GET | /api/automations/audit/logs/ | 200 |
| P3_AUDIT_002 | Audit export | GET | /api/automations/audit/export/ | 200 |
| P3_AUDIT_003 | Audit verify | POST | /api/automations/ar/audit-log/verify/ | 200,405 |

### PHASE 4: INDUSTRY FEATURES (50 tests)

**Integrations Status (10):**
| P4_INT_001 | Integration status | GET | /api/integrations/status/ | 200 |
| P4_INT_002 | Integration stats | GET | /api/integrations/stats/ | 200 |
| P4_INT_003 | Sync logs | GET | /api/integrations/logs/ | 200 |
| P4_INT_004 | ERP status | GET | /api/integrations/erp/status/ | 200 |
| P4_INT_005 | Import history | GET | /api/integrations/import-history/ | 200 |
| P4_INT_006 | Bank transactions | GET | /api/integrations/transactions/ | 200 |
| P4_INT_007 | Transaction stats | GET | /api/integrations/transactions/stats/ | 200 |
| P4_INT_008 | Matching suggestions | GET | /api/integrations/transactions/matching-suggestions/ | 200 |
| P4_INT_009 | Email accounts | GET | /api/integrations/email/accounts/ | 200 |
| P4_INT_010 | Emails list | GET | /api/integrations/emails/ | 200 |

**Data Extraction (2):**
| P4_DS_001 | Extraction history | GET | /api/integrations/extraction/history/ | 200 |
| P4_DS_002 | Extraction schedule | GET | /api/integrations/extraction/schedule/ | 200 |

**Communications (7):**
| P4_COMM_001 | Comm threads | GET | /api/communications/threads/ | 200 |
| P4_COMM_002 | Hub setup | GET | /api/communications/hub/setup/ | 200 |
| P4_COMM_003 | Hub messages | GET | /api/communications/hub/messages/ | 200 |
| P4_COMM_004 | Hub stats | GET | /api/communications/hub/stats/ | 200 |
| P4_COMM_005 | Hub flow stats | GET | /api/communications/hub/stats/flow/ | 200 |
| P4_COMM_006 | Send comm | POST | /api/communications/send/ | 200,400,405 |
| P4_COMM_007 | Comm history | GET | /api/communications/threads/?customer_id=1 | 200 |

**Reconciliation (3):**
| P4_RECON_001 | Recon status | GET | /api/integrations/reconciliation/ | 200 |
| P4_RECON_002 | Recon conflicts | GET | /api/integrations/reconciliation/conflicts/ | 200 |
| P4_RECON_003 | Recon history | GET | /api/integrations/reconciliation/history/ | 200 |

**Data Sources (4):**
| P4_SRC_001 | Data sources | GET | /api/integrations/data-sources/ | 200 |
| P4_SRC_002 | PDF schema | GET | /api/integrations/pdf/schema/ | 200 |
| P4_SRC_003 | SIS providers | GET | /api/integrations/sis/providers/ | 200 |
| P4_SRC_004 | Plaid health | GET | /api/integrations/plaid/health/ | 200 |

**Education (8):**
| P4_EDU_001 | Students list | GET | /api/education/students/ | 200 |
| P4_EDU_002 | Charges list | GET | /api/education/charges/ | 200 |
| P4_EDU_003 | Payment plans | GET | /api/education/payment-plans/ | 200 |
| P4_EDU_004 | Holds list | GET | /api/education/holds/ | 200 |
| P4_EDU_005 | Collections queue | GET | /api/education/collections/queue/ | 200 |
| P4_EDU_006 | Tax forms | GET | /api/education/tax-forms/ | 200 |
| P4_EDU_007 | Financial aid | GET | /api/education/financial-aid/ | 200,429 |
| P4_EDU_008 | Edu terms | GET | /api/education/terms/ | 200,404 |

**Construction (6):**
| P4_CON_001 | Projects list | GET | /api/construction/projects/ | 200,403 |
| P4_CON_002 | AIA applications | GET | /api/construction/aia-applications/ | 200 |
| P4_CON_003 | Retainage | GET | /api/construction/retainage/ | 200,403 |
| P4_CON_004 | Lien waivers | GET | /api/construction/lien-waivers/ | 200,403 |
| P4_CON_005 | Con billing | GET | /api/construction/billing/ | 200,404 |
| P4_CON_006 | Con setup | GET | /api/construction/setup/ | 200,404 |

**Oil & Gas (5):**
| P4_OG_001 | OG billing | GET | /api/oilgas/billing/ | 200,404 |
| P4_OG_002 | OG setup | GET | /api/oilgas/setup/ | 200,404 |
| P4_OG_003 | OG partners | GET | /api/oilgas/partners/ | 200,404 |
| P4_OG_004 | OG overhead | GET | /api/oilgas/overhead/ | 200,404 |
| P4_OG_005 | OG JV | GET | /api/oilgas/jv/ | 200,404 |

**Cross-Industry (4):**
| P4_RECON_004 | Recon export | POST | /api/integrations/reconciliation/export/ | 200,400,405 |
| P4_CROSS_001 | Switch to education | POST | /api/core/user-config/switch-industry/ | 200,400,404,405 |
| P4_CROSS_002 | Switch to construction | POST | /api/core/user-config/switch-industry/ | 200,400,404,405 |
| P4_CROSS_003 | Switch to oil_gas | POST | /api/core/user-config/switch-industry/ | 200,400,404,405 |

### PHASE 5: INTEGRATIONS & COMMUNICATIONS (28 tests)

**Email (4):**
| P5_EMAIL_001 | Email threads | GET | /api/integrations/emails/threads/ | 200 |
| P5_EMAIL_002 | Email stats | GET | /api/integrations/emails/stats/ | 200 |
| P5_EMAIL_003 | Comm center | GET | /api/integrations/communications/ | 200 |
| P5_EMAIL_004 | Comm profiles | GET | /api/integrations/communication-profiles/ | 200 |

**Slack (3):**
| P5_SLACK_001 | Slack channels | GET | /api/integrations/slack/channels/ | 200,400,404 |
| P5_SLACK_002 | Slack config | GET | /api/communications/hub/slack/config/ | 200,404 |
| P5_SLACK_003 | Slack disconnect | POST | /api/integrations/slack/disconnect/ | 200,400,404,405 |

**Import (2):**
| P5_IMP_001 | Import entity types | GET | /api/core/import/entity-types/default/ | 200,400,404 |
| P5_IMP_002 | Import review | GET | /api/core/import/review/ | 200 |

**QuickBooks (3):**
| P5_QB_001 | QB export | POST | /api/integrations/quickbooks/export/ | 200,400,404 |
| P5_QB_002 | QB status | GET | /api/integrations/erp/status/ | 200 |
| P5_QB_003 | QB import history | GET | /api/integrations/import-history/ | 200,429 |

**PDF & Sheets (3):**
| P5_PDF_001 | PDF upload | POST | /api/integrations/pdf/upload/ | 200,400,405 |
| P5_PDF_002 | PDF schema | GET | /api/integrations/pdf/schema/ | 200 |
| P5_SHEETS_001 | Sheets preview | GET | /api/integrations/sheets/preview/ | 200,404 |

**SIS (2):**
| P5_SIS_001 | SIS providers | GET | /api/integrations/sis/providers/ | 200 |
| P5_SIS_002 | SIS connect | POST | /api/integrations/sis/connect/ | 200,400,405 |

**Hub (4):**
| P5_HUB_001 | Hub setup wizard | GET | /api/communications/hub/setup/ | 200 |
| P5_HUB_002 | Hub messages | GET | /api/communications/hub/messages/ | 200 |
| P5_HUB_003 | Hub stats | GET | /api/communications/hub/stats/ | 200 |
| P5_HUB_004 | Hub flow | GET | /api/communications/hub/stats/flow/ | 200 |

**Notifications (4):**
| P5_NOTIF_001 | Notif prefs | GET | /api/auth/settings/notification-preferences/ | 200 |
| P5_NOTIF_002 | Notif channels | GET | /api/auth/settings/notification-channels/ | 200 |
| P5_NOTIF_003 | Digest prefs | GET | /api/auth/settings/digest/ | 200 |
| P5_NOTIF_004 | Notifications list | GET | /api/auth/notifications/ | 200 |

**Recon Sync/Export (3):**
| P5_RECON_001 | Recon sync | POST | /api/integrations/reconciliation/sync/ | 200,400,405,500 |
| P5_RECON_002 | Recon conflicts | GET | /api/integrations/reconciliation/conflicts/ | 200 |
| P5_RECON_003 | Recon export | POST | /api/integrations/reconciliation/export/ | 200,400,405 |

### PHASE 6: SETTINGS & CONFIGURATION (30 tests)

**Security (7):**
| P6_SEC_001 | Unauth blocked | GET | /api/invoices/ | 401,403 |
| P6_SEC_002 | Invalid token rejected | GET | /api/invoices/ | 401,200 |
| P6_SEC_003 | Privacy stats | GET | /api/automations/privacy/stats/ | 200 |
| P6_SEC_004 | Privacy audit | GET | /api/automations/privacy/audit-log/ | 200 |
| P6_SEC_005 | Active sessions | GET | /api/automations/privacy/sessions/ | 200 |
| P6_SEC_006 | Audit integrity | GET | /api/automations/audit/logs/ | 200 |
| P6_SEC_007 | Audit export | GET | /api/automations/audit/export/ | 200 |

**Settings Tabs (12):**
| P6_SET_001 | Profile settings | GET | /api/auth/profile/ | 200 |
| P6_SET_002 | Industry config | GET | /api/core/user-config/ | 200 |
| P6_SET_003 | Comm settings | GET | /api/auth/settings/communication/ | 200 |
| P6_SET_004 | Automation stats | GET | /api/automations/stats/ | 200 |
| P6_SET_005 | Notif prefs | GET | /api/auth/settings/notification-preferences/ | 200 |
| P6_SET_006 | Subscription | GET | /api/auth/subscription/status/ | 200 |
| P6_SET_007 | Privacy sessions | GET | /api/automations/privacy/sessions/ | 200 |
| P6_SET_008 | Invoice profile | GET | /api/invoices/generate/profile/ | 200 |
| P6_SET_009 | AI settings | GET | /api/automations/ai/snapshot/ | 200 |
| P6_SET_010 | Email accounts | GET | /api/integrations/email/accounts/ | 200 |
| P6_SET_011 | Boundaries | GET | /api/automations/boundaries/ | 200 |
| P6_SET_012 | Comm preview | GET | /api/communications/threads/ | 200 |

**Settings PUT/POST (11):**
| P6_SET_013 | Update profile | PUT | /api/auth/profile/ | 200,400 |
| P6_SET_014 | Update company | PUT | /api/auth/setup/company-info/ | 200,400,405 |
| P6_SET_015 | Update branding | PUT | /api/auth/setup/branding/ | 200,400,405 |
| P6_SET_016 | Update payment settings | PUT | /api/auth/setup/payment-settings/ | 200,400,405 |
| P6_SET_017 | Update invoice numbering | PUT | /api/auth/setup/invoice-numbering/ | 200,400,405 |
| P6_SET_018 | Setup progress | GET | /api/auth/setup/progress/ | 200 |
| P6_SET_019 | Setup checklist | GET | /api/auth/setup/checklist/ | 200 |
| P6_SET_020 | Pricing info | GET | /api/auth/subscription/pricing/ | 200 |
| P6_SET_021 | Countries list | GET | /api/core/countries/ | 200 |
| P6_SET_022 | Regions list | GET | /api/core/regions/ | 200 |
| P6_SET_023 | Industries list | GET | /api/core/industries/ | 200 |

### PHASE 7: EDGE CASES & ERROR HANDLING (30 tests)

**404 Tests (5):**
| P7_EDGE_001 | Invalid invoice 404 | GET | /api/invoices/99999/ | 404 |
| P7_EDGE_002 | Invalid customer 404 | GET | /api/invoices/customers/99999/ | 404 |
| P7_EDGE_003 | Nonexistent path 404 | GET | /api/nonexistent/ | 404 |
| P7_EDGE_004 | Invalid risk client 404 | GET | /api/risk/clients/99999/ | 404 |
| P7_EDGE_005 | Invalid payment 404 | GET | /api/payments/99999/ | 404 |

**Empty Body / Bad Input (5):**
| P7_EDGE_006 | Empty create invoice | POST | /api/invoices/create/ | 400 |
| P7_EDGE_007 | Empty register | POST | /api/auth/register/ | 400 |
| P7_EDGE_008 | Bad login body | POST | /api/auth/login/ | 400 |
| P7_EDGE_009 | Risk update empty | POST | /api/risk/update/ | 200,400,405 |
| P7_EDGE_010 | Payment verify empty | POST | /api/payments/verify/ | 200,400 |

**Auth Edge Cases (5):**
| P7_EDGE_011 | Expired token | GET | /api/invoices/ | 401,200 |
| P7_EDGE_012 | Missing auth header | GET | /api/dashboard/metrics/ | 401,403 |
| P7_EDGE_013 | Invalid email format | POST | /api/auth/register/ | 400,429 |
| P7_EDGE_014 | Empty name register | POST | /api/auth/register/ | 400,429 |
| P7_EDGE_015 | Contact form public | POST | /api/core/contact/ | 200,201,400,404 |

**Pagination & Search (5):**
| P7_EDGE_016 | Invoices page 9999 | GET | /api/invoices/?page=9999 | 200,404 |
| P7_EDGE_017 | Customers page 9999 | GET | /api/invoices/customers/?page=9999 | 200,404 |
| P7_EDGE_018 | Special chars search | GET | /api/invoices/customers/?search=%3Cscript%3E | 200 |
| P7_EDGE_019 | Negative page | GET | /api/invoices/?page=-1 | 200,400,404 |
| P7_EDGE_020 | Zero limit | GET | /api/invoices/?limit=0 | 200,400 |

**Method Edge Cases (5):**
| P7_EDGE_021 | DELETE on list | DELETE | /api/invoices/ | 405,404 |
| P7_EDGE_022 | PUT on list | PUT | /api/invoices/ | 405,404 |
| P7_EDGE_023 | PATCH on list | PATCH | /api/payments/list/ | 405,404 |
| P7_EDGE_024 | GET on POST-only | GET | /api/invoices/create/ | 405,404 |
| P7_EDGE_025 | Bulk validate empty | POST | /api/invoices/bulk/validate/ | 400,415 |

**Data Edge Cases (5):**
| P7_EDGE_026 | Zero amount invoice | POST | /api/invoices/create/ | 400 |
| P7_EDGE_027 | Future date invoice | POST | /api/invoices/create/ | 201,400 |
| P7_EDGE_028 | Negative amount | POST | /api/invoices/create/ | 400 |
| P7_EDGE_029 | Very long name | POST | /api/invoices/validate/ | 200,400 |
| P7_EDGE_030 | SQL injection attempt | GET | /api/invoices/customers/?search='; DROP TABLE-- | 200 |

### PHASE 8: FRONTEND & PRODUCTION VALIDATION (35 tests)

**Login & Auth UI (5):**
| P8_UI_001 | Login page loads | Chrome MCP | http://localhost:3004/login | Page renders |
| P8_UI_002 | Login form works | Chrome MCP | Fill email/pw, submit | Redirects to dashboard |
| P8_UI_003 | Register page loads | Chrome MCP | http://localhost:3004/register | Page renders |
| P8_UI_004 | Forgot password page | Chrome MCP | http://localhost:3004/forgot-password | Page renders |
| P8_UI_005 | Logout button works | Chrome MCP | Click logout | Redirects to login |

**Dashboard UI (5):**
| P8_UI_006 | Dashboard loads | Chrome MCP | http://localhost:3004/dashboard | Metrics visible |
| P8_UI_007 | Sidebar navigation | Chrome MCP | Click each nav item | Pages load |
| P8_UI_008 | Aging chart renders | Chrome MCP | Dashboard aging section | Chart visible |
| P8_UI_009 | Activity feed shows | Chrome MCP | Dashboard activity | Feed items visible |
| P8_UI_010 | AI insights panel | Chrome MCP | Dashboard AI section | Insights visible |

**Invoices UI (5):**
| P8_UI_011 | Invoices list loads | Chrome MCP | http://localhost:3004/invoices | Table renders |
| P8_UI_012 | Create invoice form | Chrome MCP | Click create, fill form | Form works |
| P8_UI_013 | Invoice detail view | Chrome MCP | Click an invoice | Detail page loads |
| P8_UI_014 | Invoice search | Chrome MCP | Type in search box | Results filter |
| P8_UI_015 | Invoice pagination | Chrome MCP | Click next page | Page changes |

**Customers UI (5):**
| P8_UI_016 | Customers list | Chrome MCP | http://localhost:3004/customers | Table renders |
| P8_UI_017 | Customer detail | Chrome MCP | Click a customer | Detail loads |
| P8_UI_018 | Customer search | Chrome MCP | Search box | Results filter |
| P8_UI_019 | Risk profile tab | Chrome MCP | Customer risk tab | Risk data shows |
| P8_UI_020 | Customer notes | Chrome MCP | Notes tab | Notes visible |

**Payments UI (3):**
| P8_UI_021 | Payments list | Chrome MCP | http://localhost:3004/payments | Table renders |
| P8_UI_022 | Record payment | Chrome MCP | Click record, fill form | Form works |
| P8_UI_023 | Payment matching | Chrome MCP | Matching tab | Suggestions show |

**Reports UI (3):**
| P8_UI_024 | Reports page | Chrome MCP | http://localhost:3004/reports | Page loads |
| P8_UI_025 | Report builder | Chrome MCP | Click builder | Builder UI loads |
| P8_UI_026 | Export report | Chrome MCP | Click export | Download starts |

**AI Agent UI (3):**
| P8_UI_027 | AI chat opens | Chrome MCP | Click AI chat | Chat panel opens |
| P8_UI_028 | Send message | Chrome MCP | Type and send | Response appears |
| P8_UI_029 | Chat history | Chrome MCP | Previous conversations | History loads |

**Settings UI (3):**
| P8_UI_030 | Settings page | Chrome MCP | http://localhost:3004/settings | Page loads |
| P8_UI_031 | Profile edit | Chrome MCP | Edit profile fields | Saves correctly |
| P8_UI_032 | Industry switch | Chrome MCP | Switch industry dropdown | UI updates |

**Responsive & Performance (3):**
| P8_UI_033 | Mobile viewport | Chrome MCP | Resize to 375px | Layout adapts |
| P8_UI_034 | Page load < 3s | Chrome MCP | Dashboard load time | Under 3 seconds |
| P8_UI_035 | No console errors | Chrome MCP | Check console | No red errors |

---

## State File Schema

After each phase, update `_extras/data/e2e-test-state.json`:
```json
{
  "version": 2,
  "started_at": "ISO timestamp",
  "iteration": N,
  "current_phase": N,
  "total_tests": 358,
  "phases": {
    "1": {"name": "Backend Health & Auth", "total": 45, "passed": N, "failed": N, "status": "passed|failed|pending"},
    "2": {"name": "Core Features", "total": 70, "passed": N, "failed": N, "status": "..."},
    ...
  },
  "issues": [{"id": "ISS-001", "phase": 1, "test": "P1_AUTH_003", "desc": "...", "fix": "...", "status": "fixed"}],
  "clean_sweep": false
}
```

## Completion

When ALL 8 phases pass with zero failures:
1. Set `clean_sweep: true` in state file
2. Update `_extras/docs/references/e2e-test-report.md` with final results
3. Output: `<promise>CLEAN SWEEP</promise>`
