Repository navigation
Private preview demo tenant: safer resets, seed-demo removal, first-launch tutorial - #72
Conversation
demo_mode_enabled was ambiguously used both for purpose-built sandbox tenants (safe to fully wipe) and for seedDemoAction's additive opt-in on a real customer's own company. resetDemoTenant() did a full destructive wipe with no check against that ambiguity. Add SANDBOX_DEMO_SLUGS/isSandboxDemoCompany as the only valid resolution path for a destructive reset, verified both in the reset route and inside resetDemoTenant itself, and parameterize the seed script so a second sandbox tenant can be provisioned without technician auth identity collisions. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF
A real customer's company could flip demo_mode_enabled via seedDemoAction (gated behind ENABLE_SEED_DEMO) to additively seed sample jobs on their own live company, and resetCompanyDataAction that paired with it was dead code with no caller. Since companies can already write their own test tickets to try any flow, this whole mechanism was unnecessary risk surface rather than a feature worth keeping. Removes /admin/seed-demo, seedDemoAction, resetCompanyDataAction, ENABLE_SEED_DEMO, and featureFlags.ts, and updates the comments/docs that referenced seedDemoAction as the reason demo_mode_enabled alone isn't a safe reset target. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF
Trusted prospects sharing the private preview tenant (any sandbox slug other than the public demo) get a spotlight-style walkthrough of the sidebar nav and the reset-data control on their first visit. It's gated to desktop widths (anchored tooltips don't translate well to the mobile nav), stores its dismissal in localStorage per company slug so it only shows once per browser, and offers a "Skip tutorial" control on every step in addition to running through to the end. Verified interaction logic (step navigation, skip, backdrop-click dismiss, localStorage persistence across reload, narrow-viewport suppression) with an isolated Playwright harness driving the actual component, since this environment has no live Supabase credentials to log into the real app with. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF
Covers the safety-critical logic added this branch: an explicit targetCompanyId on a non-sandbox company is refused with no wipe performed, a no-arg (cron) call resets every SANDBOX_DEMO_SLUGS company and aggregates jobsSeeded, and a real company that merely has demo_mode_enabled=true but isn't on the slug allowlist is never touched either way. Confirmed red-before-green by temporarily removing the non-sandbox guard: the regression test failed and showed the wipe actually proceeding (jobsSeeded: 14) before the guard was restored. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 801c418e5d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… loop P1: PATCH /api/admin/settings let any admin set their own company's slug to an unclaimed SANDBOX_DEMO_SLUGS value (only uniqueness was checked). Since resetDemoTenant() resolves its destructive-wipe target by slug alone, a real company that grabbed "swiftdispatch-preview" before it's provisioned would get its jobs wiped by the next nightly cron run. Reserve SANDBOX_DEMO_SLUGS from self-service slug edits. Confirmed red-before-green: reverting the guard let the reserved slug through with a 200, and the new regression test caught it. P1: DemoTutorial recomputed its filtered `steps` array with .filter() on every render whenever hasAdminNav was false (dispatcher role, the role a trusted-preview login would actually use). Since `steps` is an effect dependency and that effect calls setRect() with a new DOMRect each time, this was an infinite render loop -- reproduced with an isolated Playwright harness (hasAdminNav: false) showing 333 "Maximum update depth exceeded" errors before the fix, 0 after. Memoized with useMemo keyed on hasAdminNav. P2: also addressed while in the file -- suspend (not dismiss-and- remember) the tutorial if the viewport narrows below the desktop breakpoint while it's open, and give the card real dialog semantics (role="dialog", aria-modal, focus on open, Tab focus trap, Escape to dismiss, focus restored on close). Re-verified the full interaction surface (step-through, skip, resize-suspend, Escape, focus trap) with the same Playwright harness -- all passing, zero console errors. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF
diese-tech
left a comment
There was a problem hiding this comment.
Half-Shell Council Review
April O'Neil
The PR's intent is coherent: make a second private demo tenant possible, harden destructive reset behavior, remove the old seed-demo admin surface, and add a scoped first-launch tutorial. The runtime reset story is materially safer now, and the docs are more accurate.
Donatello
The resetDemoTenant() hardening is the strongest part of this PR. The destructive helper now re-verifies targetCompanyId by slug, and the cron path resolves only companies whose slugs are in SANDBOX_DEMO_SLUGS. The route also independently gates with isSandboxDemoCompany(), so the dangerous wipe has defense in depth rather than trusting one caller.
The tutorial integration is also reasonably contained: private-sandbox-only, desktop-only, localStorage-persisted, and admin-aware.
Raphael
P1 — the parameterized seed script still has a destructive cross-tenant footgun.
The comments correctly warn that private tenants need unique credentials and technician handle suffixes, but the script does not enforce that contract.
If someone runs, for example, only:
DEMO_SLUG=swiftdispatch-preview node scripts/seed-demo-tenant.mjsthen the script still defaults to:
demo@swiftdispatch.app/demo- unsuffixed technician handles such as
miatorres
ensureAuthUser() finds those existing public-demo auth users, and ensureUserProfile() then updates their company_id to the newly selected company. That can steal the public demo's login identities. The same problem exists for technician auth users.
Separately, seedJobs() performs a full wipe of whichever company was resolved by DEMO_SLUG. If a real company's slug is supplied by mistake, the script will happily target and wipe that company because the new runtime sandbox allowlist is not consulted here.
For a service-role provisioning script, documentation is not enough protection.
Michelangelo
The UI work is fine from this review pass. The tour has keyboard escape, focus trapping, skip/done persistence, resize suppression, and it does not leak onto the public demo. No blocker there.
Casey Jones
This is exactly the kind of script somebody runs once at 11 PM with one env var missing. The failure mode should be "refuse to start," not "reassign existing auth users and then wipe a company." Put the guard before the first Supabase write.
Splinter
Keep the fix small. For any non-default demo slug, require explicit non-default demo credentials and a non-empty handle suffix before provisioning starts. Stronger still, refuse any DEMO_SLUG that is not one of the sandbox demo slugs so the seed script and runtime reset share the same destructive-data boundary.
Shredder
I would specifically test these cases red-before-green:
- custom slug + default demo email -> hard fail before writes
- custom slug + empty handle suffix -> hard fail before writes
- non-sandbox slug -> hard fail before writes
- canonical public demo defaults -> still allowed
- fully specified preview tenant -> allowed
Leonardo
Not ready from review perspective. The runtime reset hardening is good, but the provisioning path still allows the exact class of destructive/cross-tenant mistake this PR is trying to eliminate. Add an executable preflight guard to scripts/seed-demo-tenant.mjs, with regression coverage if practical, then this should be in much better shape.
Exact-head CI is green at a428853160db56c730760fe30bbd2931400da813.
…jack Review finding on PR #72: a custom DEMO_SLUG with default (or missing) DEMO_USER_EMAIL/DEMO_USER_PASSWORD/DEMO_HANDLE_SUFFIX would let the script's ensureAuthUser()/ensureUserProfile() reassign the public demo's login and technician auth users to the new company, and ensureCompany() + seedJobs() would happily wipe any company whose slug happened to match -- documentation warned about this but nothing enforced it. Extracted the check into scripts/lib/seedDemoGuard.mjs so it can run synchronously before any Supabase write and be unit-tested without a live database: refuses a slug outside SANDBOX_DEMO_SLUGS outright, and for any non-public slug requires non-default credentials and a non-empty handle suffix. Confirmed red-before-green (4 of 5 refusal tests failed with the guard's body stubbed to a bare return), and smoke-tested the real script -- a dangerous config throws before any network call, a fully-specified preview-tenant config passes through to the (unrelated, expected) network failure. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF
|
Addressed the Half-Shell Council's P1 (Raphael/Casey/Splinter/Shredder) in
Covered exactly Shredder's five cases in CI is green at Generated by Claude Code |
diese-tech
left a comment
There was a problem hiding this comment.
Half-Shell re-review — blocker resolved
April: The follow-up directly addresses the prior review finding instead of papering over it. The private-demo provisioning path now has an executable preflight contract, with dedicated tests, while the public demo keeps its existing default behavior.
Donatello: validateSeedConfig() now enforces the important invariants before provisioning begins: the target slug must be on the sandbox allowlist, non-public-demo tenants cannot reuse the public demo email or password, and they must provide a technician handle suffix. The guard is invoked before main() and before any Supabase call that could create/update a company, reassign auth-backed user profiles, or wipe jobs.
Raphael: This kills the P1 I raised. A typo like DEMO_SLUG=acme-hvac now dies before touching data, and DEMO_SLUG=swiftdispatch-preview with public-demo credentials or unsuffixed technician handles also dies before it can hijack those identities.
Michelangelo: The guard has focused tests for the public defaults, the valid preview config, each dangerous fallback, and a non-allowlisted slug. Nice and boring in the best way.
Casey: The ugly operator-error paths are covered now. This is exactly where a service-role provisioning script needs to be paranoid.
Splinter: Scope stayed disciplined. The fix is isolated into a small plain-ESM guard that the .mjs script can actually import, instead of dragging application runtime code into the provisioning path.
Shredder: The only architectural wart left is the duplicated sandbox slug list between TypeScript runtime and the plain .mjs guard. That can drift eventually, but this PR explicitly documents the duplication and the current tests cover the dangerous provisioning configuration. I would not block this PR on eliminating that duplication.
Leonardo: Prior blocker resolved. Exact-head CI is green on afaca53390e5e7ba11d253bc387a3237bd924ca5. Ready from review perspective.
Full audit of the demo-tenant branches (PR #72 + this PR) turned up one more instance of the bug this PR already fixes elsewhere: POST /api/send-sms still unconditionally filtered `is_demo = false` on the quote lookup, so "Send quote to customer" -- the button right next to Preview -- would fail on the sandbox tenant the same way Preview and Add-line did before this PR. Applied the identical isCompanySandboxDemo() scoping already used everywhere else in this PR. Verified this is safe to enable for the seeded demo jobs specifically: their phone numbers (e.g. +15550090009) have an NXX of "009", which starts with a digit NANP forbids for a real exchange code, so they can't route to an actual subscriber -- and SMS send here is outbox-queued (enqueueSms just inserts a row; delivery happens later, async, in a background worker), so the UI's immediate "quote sent" feedback is unaffected by whatever a background Twilio attempt against an invalid number does. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015m3No73eyqpRxGLXWbccVw
…ipped The doc described a proposal (a /demo/tech route reusing /tech/page.tsx JSX via a shared TechJobView extraction, company.slug === 'demo' detection, an admin-role demo login) that was never built. What actually shipped across PRs #72/#74/#76 took a different shape: a floating TechPhoneModal widget on /dispatch running under the viewer's own dispatcher session (not a separate tech route or auth), a three-predicate demo-detection scheme (isDemoCompany/isSandboxDemoCompany/ isPrivateSandboxDemoCompany) answering three different questions, a dispatcher-role (not admin) private preview login, per-route is_demo visibility scoping, and a centralized SMS-suppression choke point instead of per-route filters. Rewrote the doc to describe the current architecture as-built, so it's useful as a reference instead of a misleading roadmap. Flagged in the new doc's "Open follow-ups" section rather than treated as done: a dedicated E2E quote-lifecycle regression suite (added separately, this same session) and whether TechPhoneModal should eventually get a real shared-component/impersonation connection to the production technician UI instead of its current parallel implementation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015m3No73eyqpRxGLXWbccVw
Summary
Groundwork for sharing a second, private demo tenant with trusted prospects (separate credentials from the public
swiftdispatch-demologin), plus two follow-on asks that came up along the way.resetDemoTenant— it does a full destructive wipe (every job/quote/status_event, not justis_demo=truerows). Previously nothing stopped it from being pointed at a real company. AddedSANDBOX_DEMO_SLUGS/isSandboxDemoCompany()as the only valid resolution path for a destructive reset, re-verified insideresetDemoTenant()itself (not just at the caller), and thePOST /api/demo/resetroute now uses that check instead of the looserdemo_mode_enabledflag.scripts/seed-demo-tenant.mjs— env-var overrides (slug, company name, user creds, technician handle suffix) so a second sandbox tenant (swiftdispatch-preview) can be provisioned without colliding with the public demo's technician auth identities. Not yet run against the live project — needsSUPABASE_SERVICE_ROLE_KEY/TECH_TOKEN_SECRETin the environment first.seedDemoActionlet a real customer additively seed sample jobs onto their own live company viademo_mode_enabled, and its pairedresetCompanyDataActionwas dead code with no caller. Since a company can already write its own test tickets to try any flow, this was unnecessary risk surface. Removed/admin/seed-demo, both actions,ENABLE_SEED_DEMO, andfeatureFlags.ts.localStorageso it only shows once.docs/AUTHORIZATION.mdclaimedPOST /api/demo/reset"only ever mutatesis_demo=truetenant data," which was false against the actual code (no such filter). Corrected to describe the real (now-hardened) guard.Testing
src/lib/__tests__/demo.test.ts(new) —isDemoCompany/isSandboxDemoCompanycoverage.src/lib/__tests__/resetDemoTenant.test.ts(new) — the safety-critical routing logic: an explicittargetCompanyIdon a non-sandbox company is refused with no wipe performed, a no-arg (cron) call resets every sandbox-slug company and aggregatesjobsSeeded, and a real company withdemo_mode_enabled=truebut a non-sandbox slug is never touched. Confirmed red-before-green by temporarily removing the guard — the regression test failed and showed the wipe actually proceeding before the guard was restored.DemoTutorialhas no data dependency, so its interaction logic (step navigation, skip, backdrop-click dismiss, localStorage persistence, narrow-viewport suppression) was verified with an isolated Playwright harness driving the real component — this environment has no live Supabase credentials to log into the actual app with, so it hasn't been exercised in the real UI. Flagging that explicitly rather than claiming full UI verification.npx tsc --noEmit,npx vitest run(340 passed, 8 skipped, no regressions),npm run lint(0 errors, pre-existing warning baseline),npm run build— all clean.Follow-ups (not in this PR)
swiftdispatch-previewin the live project onceSUPABASE_SERVICE_ROLE_KEY/TECH_TOKEN_SECRETare available, and handing back the slug + login URL + credentials./api/demo/enterone-click login) — discussed but not yet confirmed, out of scope here.🤖 Generated with Claude Code
https://claude.ai/code/session_01MR2GnZw5BX1L6QgTabt5JF
Generated by Claude Code