# Checkpoint 035 — Sales Demo Zero-Hardcoding, Dynamic Backend Integration & Side-Effect Free Teardown - **Checkpoint ID:** `CKPT-035` - **Date:** 2026-10-15 - **Active Stage:** Phase IV — Transition & Commercial Demo Governance (Steps 1 & 2 Complete) - **Active Track:** Greenfield, India-first, multi-tenant Agriculture Trading Backoffice (ATB) - **Active Skills:** `up-code-generate`, `up-defect-fix`, `up-context-checkpoint` - **Governed Standard:** UP-AI v1.5 Standard Enterprise Tier (SEI-CMMI Level 3) ## Completed Work This Session 1. **Mock Authentication & Navigation RBAC Gating:** - Fixed single-click authentication in [`LoginView.tsx`](file:///home/ps-ch/w/prj/mandi/project_code/frontend/src/features/auth/LoginView.tsx) by removing hard `window.location.href = '/'` and replacing with history state navigation, preventing `SESSION_EXPIRED` token race conditions. - Enforced role-based navigation gating in [`App.tsx`](file:///home/ps-ch/w/prj/mandi/project_code/frontend/src/App.tsx) based on [`ROLE_PERMISSIONS`](file:///home/ps-ch/w/prj/mandi/project_code/backend/app/auth/rbac.py): Mandi Buyer (`buyer@malwa-agri.demo`) automatically lands on `Market Desk` (`market`) and sees only authorized operational tabs; administrative tabs (`tenants`, `members`, `audit`) are hidden. 2. **Step 1 — Zero-Hardcoding UI Dynamic API Loading:** - Refactored [`MarketDeskView.tsx`](file:///home/ps-ch/w/prj/mandi/project_code/frontend/src/features/market/MarketDeskView.tsx) (`SCREEN-MKT-001`): - Completely removed `DEFAULT_RATES` static array; initial state `rates = []`, `isLoading = true`. - Queries `GET /api/v1/market/observations?mandi_id=...&date=...`. - When observations exist (seeded), displays live APMC clearing ticker (₹4,800/Qtl, 620 MT arrivals) and daily rate blotters. - When zero observations exist (purged), displays clean production empty state (*"No Market Observations Recorded"* with `+ Record Observation` CTA). - Live form submission via `POST /api/v1/market/observations` re-fetches from backend automatically. - Refactored [`SaudaProcurementView.tsx`](file:///home/ps-ch/w/prj/mandi/project_code/frontend/src/features/procurement/SaudaProcurementView.tsx) (`SCREEN-PROC-001`): - Completely removed `DEFAULT_SAUDAS` static array; initial state `saudas = []`, `isLoading = true`. - Queries `GET /api/v1/procurement/sauda` with status filters. - When contracts exist (seeded), displays live contract statuses (`ACTIVE`, `PARTIALLY_RECEIVED`, `CLOSED`), open balance positions, and landed cost breakdowns. - When zero contracts exist (purged), displays clean production empty state (*"No Purchase Contracts Booked"* with `+ Book New Sauda` CTA) with all KPIs zeroed. - Added `Mandi Buyer` to `allowed_roles` in [`procurement.py`](file:///home/ps-ch/w/prj/mandi/project_code/backend/app/api/procurement.py#L79), aligning with [`rbac.py`](file:///home/ps-ch/w/prj/mandi/project_code/backend/app/auth/rbac.py#L45-L48). - Rebuilt frontend with `tsc && vite build` (zero TypeScript errors) and deployed to `atb-local-frontend-1:/usr/share/nginx/html/`. 3. **Step 2 — Backend Demo Seeding & Side-Effect Free Teardown Engine:** - Created [`backend/app/db/demo_seed.py`](file:///home/ps-ch/w/prj/mandi/project_code/backend/app/db/demo_seed.py): - `seed_demo_dataset(store, tenant_id)`: Seeds tenant, 8 persona memberships, master commodities (SOY, CHN, WHT, MST), varieties, godowns, counterparties, fleet, operating policy, 4 daily market rate observations for Indore APMC (Soybean ₹4,800/Qtl, Chana ₹6,000/Qtl, Wheat ₹2,450/Qtl, Mustard ₹5,400/Qtl), connected storyboard transactions (`SDA-2026-001` through `BLT-2026-089`), subledgers, payables, cess voucher, operational alerts, and 20 days of historical trading snapshots. - `purge_demo_dataset(store, tenant_id, purge_tenant=False)`: Cascades deletion across all 24 relational collections with zero residue while preserving the tenant shell and operator memberships so the logged-in application can immediately be used in a clean, empty production state. - Configured [`backend/app/db/session.py`](file:///home/ps-ch/w/prj/mandi/project_code/backend/app/db/session.py) to automatically invoke `seed_demo_dataset` during container boot in mock identity mode. - Exposed `POST /api/v1/demo/seed` and `POST /api/v1/demo/cleanup` in [`backend/app/main.py`](file:///home/ps-ch/w/prj/mandi/project_code/backend/app/main.py). - Updated [`process/scripts/demo/seed_demo_data.py`](file:///home/ps-ch/w/prj/mandi/process/scripts/demo/seed_demo_data.py) and [`cleanup_demo_data.py`](file:///home/ps-ch/w/prj/mandi/process/scripts/demo/cleanup_demo_data.py) to synchronize running backend server at `http://localhost:8000`. - Deployed updated backend to `atb-local-backend-1` and restarted container. 4. **Verification & Testing Evidence:** - Full regression suite: `./scripts/run_tests.sh --scope project` ran 197 tests in 0.868s. **197/197 passed** with **98.2% statement coverage**. - Purge cycle verified: `cleanup_demo_data.py --confirm-purge` removes all 65 demo records; counts drop to 0; UI renders clean empty states. - Seed cycle verified: `seed_demo_data.py` seeds 4 observations and 4 saudas; UI immediately reflects live data. - Live form submission verified: `POST /api/v1/market/observations` (HTTP 201) and `POST /api/v1/procurement/sauda` (HTTP 201) persist and reflect dynamically. ## Mid-Flight / Open Diagnoses 1. **Root Cause of Issue 2 (Gate 14.1 passed with only 8 screens):** - In [`scripts/verify_traceability_gates.py`](file:///home/ps-ch/w/prj/mandi/scripts/verify_traceability_gates.py), Gate 14.1 validated surface matrix markdown presence but never checked whether the declared React `.tsx` files actually existed in `project_code/frontend/src/`. - Iterations 03–07 prematurely recorded delivery rows as `Delivered (E2E Verified)` instead of `Implemented (Domain/Schema)`. 2. **Root Cause of Issue 3 (Identical QA workbooks in generator):** - In [`scripts/generate_manual_qa_workbook.py`](file:///home/ps-ch/w/prj/mandi/scripts/generate_manual_qa_workbook.py), `get_default_iteration_cases()` hardcoded `UC-001`, `FR-AUTH-001..003`, and 32 authentication test cases as a fallback. When executed across iterations 02–07, it merely replaced the `TC-01-` ID prefix, emitting identical Auth tests. - Gate 14.1 only checked row counts ($\ge 20$) without asserting semantic alignment against the iteration's in-scope use cases. ## Exact Next Action Upon Resumption 1. **Step 4 — Process & Quality Gate Hardening:** - Update [`scripts/verify_traceability_gates.py`](file:///home/ps-ch/w/prj/mandi/scripts/verify_traceability_gates.py): - In Gate 14.1, verify physical existence of all declared frontend `.tsx` components in `project_code/frontend/src/` for any row marked `Delivered (E2E Verified)`. - In Gate 14.1, assert that QA workbook test cases semantically match in-scope use cases/FRs ($\ge 80\%$ matching). - Update [`scripts/generate_manual_qa_workbook.py`](file:///home/ps-ch/w/prj/mandi/scripts/generate_manual_qa_workbook.py): - Dynamically parse the iteration backlog use cases and functional test models rather than falling back to static Auth templates. 2. **Step 3 — Production Frontend Expansion:** - Implement the remaining 7 production React views for Journeys 2–8 (`GateEntryView`, `QualityLabView`, `StockLedgerView`, `SalesOrderView`, `DispatchBoardView`, `FinanceLedgerView`, `ExecutiveDashboardView`) with zero hardcoding, connecting them to existing backend APIs and demo data.