diavola-88607: Phase 7 — Hardening for production - #8
Merged
Conversation
Add a real automated test suite, observability scaffolding, RLS harness, training mode, and production-readiness docs — all runnable now against the mock/pure logic with zero env vars. No live service wiring (final phase). Tests (Vitest, 106 tests / 15 files, zero env): - money/pricing incl. half-and-half (left+right==whole), size deltas, integer cents; platform fee (bps+flat, rounding, clamp, card-only) - payment idempotency/no-double-charge, settled-vs-covered, split → zero, crypto pending→confirm, refund/void - offline queue idempotent upsert-by-UUID (double-flush + reconnect retry) - delivery zone gating + below-minimum + pickProvider; scheduling hours/prep - entitlements/plan gating; reports aggregation (mix, tip de-dup, voids, rollup); inventory depletion + low-stock; drawer/Z-report + idempotent close - app-layer tenant isolation (driver-scoped reads) Observability: structured logger, request/trace ids, error seam (Sentry behind SENTRY_DSN, no-op otherwise), /api/health + new /api/ready; wired into /api/orders. Training/demo mode flag (TRAINING_MODE / mock driver). RLS: expanded supabase/tests/rls_isolation.sql (memberships/users/no-orphan write) + run-rls-isolation.sh harness + README; optional non-blocking Postgres CI job. Added required vitest CI job. Docs: docs/PRODUCTION_READINESS.md + docs/IDEMPOTENCY_REVIEW.md; env inventory in .env.example. No double-charge/dupe bugs found. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The optional RLS-isolation job ran against vanilla Postgres, which lacks Supabase's auth schema / auth.uid() the tenancy policies depend on. Apply the auth_shim.sql before migrations (CI job + harness, skippable via SKIP_AUTH_SHIM=1 for real Supabase) so the optional job exercises real RLS and goes green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The RLS isolation test does `set local role authenticated`; vanilla Postgres lacks Supabase's standard roles. Create them (no-login) in the shim so the optional Postgres RLS job can switch roles and exercise the policies. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
RLS gates rows but table GRANTs gate table access; the migration relied on Supabase's implicit default privileges, so `authenticated` was denied on vanilla Postgres. Grant the tenancy tables to `authenticated` (rows still restricted by the policies) and only schema usage to `anon` — explicit, portable, least-privilege. Makes the RLS isolation test pass off-platform. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 7 — Hardening for Production
Makes the codebase production-trustworthy: a real automated test suite over the risk areas, observability scaffolding, an RLS isolation harness, training mode, and documented production readiness — all runnable now against the mock/pure logic with zero env vars. No live Supabase/Stripe/crypto/DoorDash wiring (that's the separate final phase).
Automated test suite (Vitest — 106 tests / 15 files, zero env)
Added Vitest (+
fake-indexeddb,jsdom);npm test/npm run test:run.paidonly when settled covers total, split → zero balance, crypto pending counts to balance but not paid → confirm settles, refund/void (full + partial)pickProviderselectionRLS isolation harness
supabase/tests/rls_isolation.sql(no-orphan write, memberships + users isolation) +run-rls-isolation.shone-command harness + README.testjob (npm run test:run, zero env) + optional non-blockingrls-isolationPostgres job (a live DB is never a required gate).Observability (env-optional, no-op safe)
Structured JSON logger (
LOG_LEVEL), request/trace ids (reusex-request-id/traceparent, echoed on responses), error seam (captureError→ Sentry only whenSENTRY_DSNset, else log no-op). Wired into/api/orders;/api/health(liveness) + new/api/ready(readiness: probes driver, reports training mode, 503 on dep failure).Training/demo mode
TRAINING_MODEflag (also implied by the mock driver) + banner via/api/ready.Docs
docs/PRODUCTION_READINESS.md(tenant-isolation audit, idempotency guarantees, offline/store-and-forward risks, Connect/PCI posture — no PAN/SAQ-A, crypto finality, Supabase PITR, env inventory, go-live checklist) +docs/IDEMPOTENCY_REVIEW.md. No double-charge/dupe bugs found.Local results (zero env vars)
npm run test:run→ 106 passed / 15 filesnpm run typecheck→ clean ·npm run lint→ no warnings ·npm run build→ success (incl./api/ready)🤖 Generated with Claude Code