Repository navigation
Description
Why this audit exists
PR #72 introduced a second, private sandbox tenant for trusted prospects. Since then, live validation has already exposed multiple regressions that unit-level review did not catch, including broken quote actions and stale technician availability. PR #74 addresses some of those findings, but the demo tenant now touches enough of the product that it needs an end-to-end audit rather than another isolated patch review.
This issue is the umbrella Half-Shell Demo Tenant Audit. The goal is to verify that the private demo exercises the real SwiftDispatch product faithfully without creating demo-only mutation semantics, leaking synthetic load data into real tenants, or presenting UI that looks functional but is not.
Known related work:
- PR Private preview demo tenant: safer resets, seed-demo removal, first-launch tutorial #72 — private preview demo tenant groundwork and reset hardening
- PR Fix demo-tenant quote actions and stale technician availability #74 — demo quote/read visibility + seed/reset technician state fixes
- Eliminate duplicated sandbox demo allowlist between runtime and seed tooling #73 — remove duplicated sandbox allowlist
Audit principle
The demo should be real product behavior on disposable data, not a visually similar fork of the product.
Where possible, demo UI should call the same handlers and enforce the same business rules as the real dispatcher/admin/technician experience. Demo-specific code should be limited to tenant detection, safe reset/provisioning, framing/tutorial UX, and suppression of external side effects where necessary.
Half-Shell council findings
April O'Neil — contract / route map
The private preview currently spans:
- sandbox detection:
src/lib/demo.ts - provisioning:
scripts/seed-demo-tenant.mjs - destructive reset:
src/lib/resetDemoTenant.ts,/api/demo/reset,/api/internal/reset-demo - persistent demo framing:
DemoBanner,DemoTabNav,DemoTutorial,ResetDemoButton - dispatcher board + realtime refetch
- technician preview:
TechPhoneModal - job mutations:
/api/jobs,/api/jobs/[id] - quote create/edit/preview/send/accept/decline
- admin/analytics presentation
The legacy docs/demo-experience-design.md is now materially stale. It describes a shared /demo/tech experience and old auth assumptions that no longer match the implementation.
Donatello — architecture / contract consistency
P1 — demo tech preview has become a second mutation implementation
TechPhoneModal duplicates the real technician UI instead of reusing the production technician workflow.
Current divergence:
- real technician Build Quote links to
/tech/job/[jobId] - demo phone Build Quote directly PATCHes job status to
quote_pending - real technician completion requires an accepted quote
- demo phone completion only checks the generic state-machine transition
- real technician callers are restricted to
en_route,in_progress, andcompleted - demo phone borrows the dispatcher/admin session, so it inherits broader mutation authority
This allows the demo to create states the real technician product cannot, including quote_pending with no quote.
Required direction: remove demo-only business rules. Prefer extracting/reusing the actual technician job/action surface, or create a narrowly-scoped demo impersonation adapter that invokes the same technician rules server-side.
P2 — demo detection has two meanings and call sites must choose deliberately
isDemoCompany() is intentionally loose (demo_mode_enabled OR public demo slug).
isSandboxDemoCompany() is the destructive/synthetic allowlist.
Any code deciding whether is_demo=true rows are normal operational data must use the sandbox distinction, not globally remove filters or assume all is_demo rows belong to sandbox companies.
PR #74 currently has a blocker here: load-test scripts intentionally seed is_demo=true jobs into configurable non-sandbox companies to keep synthetic traffic out of operational views.
Raphael — correctness / security / mutation edges
P1 — quote workflow remains broken end-to-end for sandbox rows
PR #74 removes the demo-row filter from quote creation, line-item mutation, and preview, but POST /api/send-sms still requires:
.eq("is_demo", false)QuoteBuilder calls this route from its primary Send quote to customer CTA.
Result after the current #74 direction:
- sandbox user can create quote
- add/edit/delete line items
- preview quote
- click Send quote to customer
- route returns
404 Quote not found
The quote workflow needs an explicit sandbox policy through the complete chain, not piecemeal removal of filters.
P2 — status-only completion leaves technician runtime state stale
PATCH /api/jobs/[id] updates technician availability/current job for assignment, reassignment, and unassignment, but a status-only transition to completed does not release the technician.
The dispatcher demo code already compensates for this with a comment noting that current_job_id may remain stale. Quote acceptance does clear the technician correctly, which makes the behavior inconsistent by completion path.
This is pre-existing production behavior that the demo exposed, not a demo-only bug.
Expected invariant: once a job reaches a terminal status, the assigned technician must not remain on_job with that job as current_job_id unless another active assignment establishes that state.
P2 — preserve synthetic-load isolation for real tenants
Do not globally remove is_demo=false from operational reads. load-tech-actions.mjs and related harnesses deliberately seed is_demo=true rows into configurable companies.
Required behavior:
- purpose-built sandbox tenant: synthetic/demo rows are the product data and must be visible
- ordinary tenant: synthetic load rows remain hidden from operational boards and metrics
Michelangelo — UX / product fidelity
P1 — Tech view looks real but behaves differently from the real tech portal
This is more damaging than a cosmetic mismatch because the prospect is being shown a false interaction model.
Additional fidelity gaps:
- the phone mock renders Sign out as inert text
- address is not a Maps link like the real tech UI
- phone number is styled as actionable but is not a
tel:link - tech preview is only available as a floating control on Dispatch rather than as a consistent demo persona surface
If the point is to demonstrate the field-tech product, interaction fidelity matters more than recreating phone chrome.
P2 — Admin settings CTA is visible to a preview dispatcher who cannot use it
seed-demo-tenant.mjs provisions the demo user as dispatcher.
DemoBanner always renders an Admin settings link.
proxy.ts correctly rejects non-admin users and redirects them back to Dispatch.
So the preview exposes a CTA that visibly goes nowhere.
Choose one product contract:
- private prospect login is
adminso it can demonstrate Dispatch + Analytics + Admin in one session, or - keep it dispatcher and hide/admin-gate the admin CTA
The current mixed model is broken UX.
P2 — reset button fails silently
ResetDemoButton shows loading and refreshes on success, but surfaces no error on non-2xx/network failure.
For a prospect, a failed destructive reset simply looks like the button did nothing.
Add explicit success/error feedback. Confirmation is optional because the tenant is intentionally disposable.
Casey Jones — ugly operational paths
P2 — "Reset data" is not a full tenant reset
resetDemoTenant() resets job-centric state:
- jobs
- quotes / line items
- status events
- SMS outbox
- technician availability/current job
It does not restore arbitrary company settings, users, technician identity/config, templates, or other mutable admin state.
The UI/tutorial wording says things like "wipe it back to sample data," which implies a broader reset than the implementation guarantees.
This becomes especially important if the private prospect user is upgraded to admin.
Either:
- define/reset the complete mutable demo baseline, or
- explicitly constrain which surfaces are meant to be mutated and rename/copy the reset action to match that narrower contract
P2 — sandbox external-side-effect policy is implicit
The demo is intentionally interactive, but customer-facing actions can eventually reach SMS/payment/invoice paths. Synthetic phone numbers and manual payments reduce risk today, but the policy is accidental rather than encoded.
Audit each externally visible action and decide whether sandbox behavior should:
- execute against a safe test provider
- enqueue but suppress delivery
- simulate success
- be unavailable with an explicit demo explanation
Do not let individual routes decide this accidentally via stale is_demo filters.
Splinter — discipline / scope
Do not solve this by adding if (demo) branches throughout the app.
Preferred shape:
- one canonical sandbox predicate/config
- production handlers stay authoritative
- demo UX reuses production components/business rules
- external side-effect policy is centralized
- demo-only code handles framing, tutorial, reset, and provisioning
- regression coverage exercises complete prospect workflows, not just individual route functions
Issue #73 already tracks the duplicated sandbox allowlist and should remain separate but linked.
Shredder — adversarial challenge
For every demo-capable workflow, try both directions:
- What happens if an
is_demo=truerow exists in a normal company? - What happens if every row in a sandbox company is
is_demo=true? - Can a dispatcher-session demo control perform an action a real technician cannot?
- Can a sandbox action send SMS, create payment artifacts, or mutate an external provider unexpectedly?
- Does realtime refetch return the same population as initial SSR?
- Does reset restore the state necessary to repeat the full walkthrough?
- Can an admin setting change the sandbox slug and make future reset/provisioning behavior inconsistent?
- Do public quote/status token flows still work for sandbox-generated records?
Tests should make these questions executable.
Leonardo — audit plan / priority
Phase 1 — close workflow-breaking regressions
- Fix PR Fix demo-tenant quote actions and stale technician availability #74's normal-tenant synthetic-row regression with sandbox-aware visibility rules.
- Make sandbox quote Send quote to customer follow the chosen sandbox policy instead of 404ing on
is_demo=true. - Remove
TechPhoneModal's fakequote_pendingmutation and enforce the same Build Quote / Complete rules as the real technician experience. - Add end-to-end behavior coverage for the complete sandbox quote path: create → line items → preview → send/simulate send → accept/decline → resulting job/technician state. (
src/lib/__tests__/demoTenantQuoteLifecycle.test.ts; the quote/intake pages themselves aren't rendered, since this repo has no page-render test harness — see Phase 4 note below.)
Phase 2 — restore state invariants
- Release/reconcile technician
availability_status+current_job_idon every terminal job path, including direct status completion. (src/lib/technicianReconciliation.ts, shared byPATCH /api/jobs/[id]andPOST /api/quotes/[id]/accept, including multi-assignment promotion andis_demo/legacy-status-aware candidate selection.) - Verify initial SSR and realtime refetch use the same sandbox-aware visibility policy. (
dispatch/page.tsxSSR andKanbanBoard's realtime refetch both gate on the sameisSandboxDemoCompanyresult.) - Verify admin metrics/analytics use the intended sandbox-aware population without exposing load-test noise in ordinary tenants.
Phase 3 — UX fidelity and demo contract
- Decide whether private preview credential is dispatcher or admin and make navigation match. (Kept dispatcher;
DemoBanner's Admin settings link is now role-gated instead of dead-ending.) - Replace duplicated/fake tech preview behavior with shared production technician UI/business rules where practical. (
TechPhoneModalnow enforces the same business rules as the real technician UI — non-mutating Build Quote, Complete gated on an accepted quote, realtel:/Maps links — but still isn't wired into the actual shared component/route. Left open as an architecture decision; seedocs/demo-experience-design.md's follow-ups.) - Make Reset data failures visible.
- Define whether reset means job-state reset or full sandbox-baseline reset, then align copy and implementation. (Expanded to also restore technician identity and the canonical quote template.)
- Decide and centralize sandbox SMS/payment/external-side-effect behavior. (SMS centrally suppressed in
processSmsOutboxBatch; payment already made no external calls viaManualPaymentProvider.) - Refresh or replace
docs/demo-experience-design.mdso it describes the current architecture.
Phase 4 — regression gate
Add a dedicated demo-tenant regression suite that covers, at minimum:
- sandbox vs normal-company
is_demo=truevisibility - dispatcher board initial load + realtime refetch parity (verified by code inspection, not by an automated test — no component-render harness exists in this repo to assert
KanbanBoard's actual rendered output) - quote create/edit/delete/preview/send path (API/data level, via the E2E suite and existing per-route tests; the preview page itself isn't rendered — same test-infra gap as above)
- customer quote accept + decline
- technician En Route → Arrived → Build Quote → Complete behavior (rule-matching covered by code +
jobMutations/technicianAssignmenttests;TechPhoneModal's actual UI flow isn't component-tested for the same reason) - technician availability/current-job invariants
- reset and repeatability
- role-correct demo navigation (verified by code inspection —
DemoBanner's role gate — not by an automated render test) - no unintended external side effects
Completion criteria
The audit is complete when a trusted prospect can repeat the intended demo walkthrough from a clean reset without encountering:
- a 404/403 caused only by sandbox data flags
- a button that looks functional but is not
- a demo-only state transition that production users cannot perform
- stale technician state after completion
- synthetic load-test data in ordinary tenant operational views
- silent reset failures
- unplanned external side effects
At that point, the private demo can be treated as a regression-tested product surface rather than a collection of demo exceptions.
Status as of PR #77: every P1/P2 finding above and every Phase 1-3 checklist item is fixed except one deliberate open question (TechPhoneModal's shared-component wiring, tracked in docs/demo-experience-design.md). The two remaining Phase 4 gaps are about test infrastructure this repo doesn't have (component/page rendering), not about unverified behavior — see PRs #74/#76/#77 and their test suites for the executable coverage that does exist. Remaining work here is either the TechPhoneModal architecture decision, or standing up a render harness if page/component-level regression coverage becomes a priority.
Activity
#75 Phase 2/3: analytics sandbox scoping, terminal technician release…
#75 P1/P2: gate TechPhoneModal's Complete button, add real link fidelity
#75 Phase 3: non-mutating Build Quote, admin-gated CTA, centralized S…
#75 Phase 3: expand resetDemoTenant() to a full technician/template b…
Merge pull request #76 from diese-tech/claude/awesome-cray-d9djpp
#75: rewrite docs/demo-experience-design.md to match what actually sh…
#75 Phase 1/4: E2E sandbox quote lifecycle test; fix accept's same re…
#75 Phase 4: add reset-repeatability regression test
Address Codex findings on PR #77: is_demo scope, legacy status, previ…
Update demo-experience-design.md's open follow-ups now that the E2E s…
Merge pull request #77 from diese-tech/claude/awesome-cray-d9djpp