--- phase: 05-visibility-and-client-portal plan: 07 type: execute wave: 1 depends_on: [] files_modified: - src/lib/__tests__/integration/e2e-workflows.test.ts - .planning/phases/02-subscriber-and-billing-core/02-VERIFICATION.md autonomous: true gap_closure: true must_haves: truths: - "E2E tests exercise the inventory receiving and expense recording workflows end-to-end with balanced journal entries" - "E2E tests exercise the portal ticket creation flow from subscriber to staff ticket queue" - "Phase 2 VERIFICATION.md reflects the actual fixed state (passed, 5/5)" artifacts: - path: "src/lib/__tests__/integration/e2e-workflows.test.ts" provides: "E2E tests for inventory/expense and portal ticket workflows" contains: "Inventory.*Expense|Portal.*Ticket" - path: ".planning/phases/02-subscriber-and-billing-core/02-VERIFICATION.md" provides: "Corrected verification status" contains: "status: passed" key_links: - from: "e2e-workflows.test.ts" to: "inventory-service.ts" via: "service import and call" pattern: "receiveStock|recordMovement" - from: "e2e-workflows.test.ts" to: "expense-service.ts" via: "service import and call" pattern: "createExpense|recordExpense" - from: "e2e-workflows.test.ts" to: "portal-ticket-service.ts" via: "service import and call" pattern: "createPortalTicket" --- Add E2E test coverage for Phase 4 inventory/expense workflows and Phase 5 portal ticket flow, and correct the Phase 2 VERIFICATION.md status. Purpose: Close the E2E test coverage gaps identified in the milestone audit and fix the outdated verification document that still shows a gap that was resolved. Output: Two new E2E workflow test suites and a corrected Phase 2 VERIFICATION.md. @C:\Users\KevinAsprec\.claude/get-shit-done/workflows/execute-plan.md @C:\Users\KevinAsprec\.claude/get-shit-done/templates/summary.md @.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/v1-MILESTONE-AUDIT.md @src/lib/__tests__/integration/e2e-workflows.test.ts @src/lib/services/inventory-service.ts @src/lib/services/asset-service.ts @src/lib/services/expense-service.ts @src/lib/services/portal-ticket-service.ts @.planning/phases/02-subscriber-and-billing-core/02-VERIFICATION.md Task 1: Add inventory/expense and portal ticket E2E workflows src/lib/__tests__/integration/e2e-workflows.test.ts Add two new describe blocks to the existing e2e-workflows.test.ts file. Follow the exact patterns established by the existing 3 workflows (same test helpers, same tenant setup, same cleanup approach, same trial balance verification pattern). **Workflow 4: Inventory Receiving -> Expense Recording -> Trial Balance** Add a describe block "Workflow 4: Inventory Receiving and Expense Recording" with these tests: 1. "receives inventory items and creates balanced journal entries" - Import and call inventory-service to receive stock (e.g., receiveStock or the appropriate function that creates an INBOUND/RECEIVED stock movement) - Verify the stock movement was created - Verify a journal entry was posted (DR Inventory asset account / CR Cash or AP) - Verify the JE is balanced (debits === credits) 2. "records an expense with automatic journal entry" - Import and call expense-service to create an expense (with category and vendor) - Need to create an expense category and vendor first (use the appropriate service functions or direct prisma calls matching existing test patterns) - Verify the expense was created - Verify a journal entry was posted (DR Expense account / CR Cash or AP) - Verify the JE is balanced 3. "trial balance remains balanced after inventory and expense transactions" - Use JournalEntryService.getTrialBalance (same pattern as existing workflows) - Assert total debits === total credits > 0 **Workflow 5: Portal Ticket Creation -> Staff Queue** Add a describe block "Workflow 5: Portal Ticket Submission to Staff Queue" with these tests: 1. "subscriber creates portal ticket and it appears in staff ticket queue" - Create a subscriber (use existing createSubscriber helper or the pattern from existing tests) - Import and call portal-ticket-service's createPortalTicket (or equivalent function) to create a ticket as the subscriber - This should trigger ensurePortalUser internally (creating a shadow User with CLIENT role) - Verify the ticket was created with source=SUBSCRIBER - Query tickets via ticket-service's list/search function (staff perspective) and verify the portal ticket appears in the results 2. "portal ticket has correct subscriber association" - Verify the ticket's createdById links to the shadow portal user - Verify the shadow user exists with role CLIENT IMPORTANT: - Reuse the existing test's tenant, users, and cleanup infrastructure. The existing beforeAll creates a tenant and users — extend it to also create any additional data needed (expense categories, vendors, inventory items). - Add cleanup for new records in the existing afterAll block (expense categories, expenses, vendors, inventory items, stock movements, plus any portal-created users and tickets). - Follow the existing import pattern at the top of the file. - Check the actual function signatures in inventory-service.ts, expense-service.ts, and portal-ticket-service.ts before writing calls — use the exact parameter shapes those functions expect. 1. Run: npx jest --testPathPattern="e2e-workflows" --verbose — all workflows pass (existing 3 + new 2) 2. Run: npx jest --testPathPattern="e2e-workflows" --verbose 2>&1 | grep -c "PASS\|FAIL" — should show PASS 3. Verify new test count: npx jest --testPathPattern="e2e-workflows" --verbose 2>&1 | grep "Tests:" — should be more than the previous 16 E2E test file has 5 workflow suites. Inventory receiving and expense recording produce balanced JEs. Portal ticket appears in staff queue. All tests pass. Task 2: Correct Phase 2 VERIFICATION.md status .planning/phases/02-subscriber-and-billing-core/02-VERIFICATION.md Update the Phase 2 VERIFICATION.md to reflect the actual current state: 1. In the YAML frontmatter: - Change `status: gaps_found` to `status: passed` - Change `score: 4/5 must-haves verified` to `score: 5/5 must-haves verified` - Remove or update the `gaps:` section — change the truth #3 status from `failed` to `fixed` and add a note that the fix was applied in billing-service.ts (status: InvoiceStatus.SENT, issuedAt: new Date()) and validated by Phase 5 E2E tests 2. In the body: - Update Truth #3 status from "FAILED" to "VERIFIED (fixed post-verification)" in the Observable Truths table - Add a brief note in the Evidence column: "Fixed: billing-service.ts now sets status=SENT and issuedAt on invoice creation. Validated by Phase 5 E2E billing workflow test." - Update the Key Link "billing-service.ts -> Invoice (status=SENT)" from "NOT WIRED" to "WIRED" with note "Fixed post-initial-verification" - Update BILL-03 requirement from "BLOCKED" to "SATISFIED" with note "Fixed: invoices now created as SENT" - Update the Anti-Patterns section to mark the billing-service.ts issue as resolved - Update the Gaps Summary section to note that the gap was resolved - Add a re-verification note: "Re-verified: 2026-03-05 — gap closure confirmed" 3. Update the Score line in the body from "4/5" to "5/5". Keep all other content intact. This is a documentation correction, not a rewrite. 1. grep "status: passed" .planning/phases/02-subscriber-and-billing-core/02-VERIFICATION.md — should match 2. grep "5/5" .planning/phases/02-subscriber-and-billing-core/02-VERIFICATION.md — should match 3. grep "BLOCKED" .planning/phases/02-subscriber-and-billing-core/02-VERIFICATION.md — should return ZERO matches Phase 2 VERIFICATION.md shows status: passed, score: 5/5, truth #3 marked as verified/fixed, BILL-03 satisfied, key link wired. Document accurately reflects the actual system state. 1. All E2E tests pass: npx jest --testPathPattern="e2e-workflows" --verbose 2. Full test suite passes: npx jest 3. Phase 2 VERIFICATION.md shows passed status with 5/5 score 4. New E2E workflows cover inventory receiving, expense recording, and portal ticket creation - E2E test coverage now includes Phase 4 inventory/expense workflows - E2E test coverage now includes portal ticket creation flow - Phase 2 VERIFICATION.md accurately reflects the fixed state - All existing tests continue to pass After completion, create `.planning/phases/05-visibility-and-client-portal/05-07-SUMMARY.md`