docs(phase-12): add validation strategy

This commit is contained in:
lorentz 2026-07-10 22:00:08 -04:00
parent b99f84ffa0
commit 6d8b2610bb

View file

@ -0,0 +1,79 @@
---
phase: 12
slug: orders-invoices-company-matching
status: draft
nyquist_compliant: false
wave_0_complete: false
created: 2026-07-11
---
# Phase 12 — Validation Strategy
> Per-phase validation contract for feedback sampling during execution.
---
## Test Infrastructure
| Property | Value |
|----------|-------|
| **Framework** | vitest 4.1.5 |
| **Config file** | `vitest.config.ts` (root) — `include: ['lib/**/*.test.ts']`, `environment: 'node'` |
| **Quick run command** | `npx vitest run lib/services/pax8-client.test.ts lib/services/pax8-company-matcher.test.ts` |
| **Full suite command** | `npm test` |
| **Estimated runtime** | ~15 seconds |
---
## Sampling Rate
- **After every task commit:** Run `npx vitest run lib/services/pax8-*.test.ts`
- **After every plan wave:** Run `npm test` (full suite)
- **Before `/gsd:verify-work`:** Full suite must be green
- **Max feedback latency:** 30 seconds
---
## Per-Task Verification Map
| Task ID | Plan | Wave | Requirement | Threat Ref | Secure Behavior | Test Type | Automated Command | File Exists | Status |
|---------|------|------|-------------|------------|-----------------|-----------|-------------------|-------------|--------|
| TBD | TBD | TBD | PAX8-06 | V5 | `listAllInvoices()` concatenates pages in order | unit | `npx vitest run lib/services/pax8-client.test.ts -t "listAllInvoices"` | ❌ W0 | ⬜ pending |
| TBD | TBD | TBD | PAX8-06 | V5 | `listAllInvoiceItems(invoiceId)` calls correct nested path and concatenates pages | unit | `npx vitest run lib/services/pax8-client.test.ts -t "listAllInvoiceItems"` | ❌ W0 | ⬜ pending |
| TBD | TBD | TBD | PAX8-06 | — | Sync upserts orders/items and tombstones missing rows | unit | `npx vitest run lib/services/pax8-sync-service.test.ts` | ❌ W0 | ⬜ pending |
| TBD | TBD | TBD | PAX8-10 | T-12-01 | Auto-link fires only when score ≥ 0.90 and no near-tie | unit | `npx vitest run lib/services/pax8-company-matcher.test.ts -t "auto-link"` | ❌ W0 | ⬜ pending |
| TBD | TBD | TBD | PAX8-10 | T-12-01 | Below-threshold or tied candidates produce a review row, not an auto-link | unit | `npx vitest run lib/services/pax8-company-matcher.test.ts -t "review"` | ❌ W0 | ⬜ pending |
| TBD | TBD | TBD | PAX8-11 | — | Zero-candidate case still creates a review row with empty `candidate_company_ids` | unit | `npx vitest run lib/services/pax8-company-matcher.test.ts -t "empty candidates"` | ❌ W0 | ⬜ pending |
| TBD | TBD | TBD | SC#4 | T-12-02 | Re-running matcher never overwrites a `resolved_at IS NOT NULL` row | unit | `npx vitest run lib/services/pax8-company-matcher.test.ts -t "idempotent"` | ❌ W0 | ⬜ pending |
*Status: ⬜ pending · ✅ green · ❌ red · ⚠️ flaky*
---
## Wave 0 Requirements
- [ ] `lib/services/pax8-company-matcher.test.ts` — covers PAX8-10, PAX8-11, SC#4. `pg_trgm`'s `similarity()` runs in Postgres — mock `postgresClient.query` (following `pax8-client.test.ts`'s `vi.fn` canned-row convention) to keep this DB-free and consistent with the rest of the suite.
- [ ] Extend `lib/services/pax8-client.test.ts` — add `listAllInvoices`/`listAllInvoiceItems` cases following the existing `makeMultiPageFetchMock` helper.
- [ ] Confirm whether `lib/services/pax8-sync-service.test.ts` exists yet (research did not find one — Phase 11 shipped with a live-verification script instead per `11-03-SUMMARY.md`). Planner decides whether Phase 12 introduces the first unit tests for `Pax8SyncService` or continues the live-verification-script pattern.
---
## Manual-Only Verifications
| Behavior | Requirement | Why Manual | Test Instructions |
|----------|-------------|------------|-------------------|
| Full sync against real PAX8 account produces plausible order/item counts and match rates | PAX8-06, PAX8-10, PAX8-11 | Live external API + live production-like company data; unit tests mock both | Run full sync against dev environment, spot-check `pax8_orders`/`pax8_order_items` row counts (~94 invoices, ~500-700 items each) and `pax8_company_match_review` queue size against expectations in RESEARCH.md |
| Exact `total`/`subTotal`/`amountDue` semantics for prorated/credited invoice items | PAX8-06 | Open question in RESEARCH.md not fully closed by static research — needs a live-API spot-check | Query a known prorated invoice via `/invoices/{id}/items` and confirm field mapping before finalizing the item-persistence logic |
---
## Validation Sign-Off
- [ ] All tasks have `<automated>` verify or Wave 0 dependencies
- [ ] Sampling continuity: no 3 consecutive tasks without automated verify
- [ ] Wave 0 covers all MISSING references
- [ ] No watch-mode flags
- [ ] Feedback latency < 30s
- [ ] `nyquist_compliant: true` set in frontmatter
**Approval:** pending