#!/usr/bin/env bash # Idempotent driver for docs/onboarding-walkthrough.md. # Replays the 90-second clone-to-logged-in onboarding flow against a fresh # repository checkout. Wrapped by `asciinema rec` to produce a stable cast. # # Safe to re-run: it operates on the working directory the script is launched # from, expects a .env.example present, and never overwrites a populated .env. set -euo pipefail REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" cd "$REPO_ROOT" step() { printf "\n\033[1;36m▶ %s\033[0m\n" "$1" } step "1/8 pnpm install (warm cache)" pnpm install --frozen-lockfile if [ ! -f .env ]; then step "2/8 copy .env.example -> .env (placeholder secrets)" cp .env.example .env # Replace empty SECRET keys with deterministic walkthrough values. # Real installs MUST replace these before any non-local use. sed -i.bak -E ' s|^SESSION_SECRET=.*|SESSION_SECRET=walkthrough-session-secret-replace-before-prod|; s|^CRYPTO_SECRET=.*|CRYPTO_SECRET=walkthrough-crypto-secret-replace-before-prod|; s|^API_ACCESS_TOKEN=.*|API_ACCESS_TOKEN=walkthrough-api-access-token|; s|^JWT_SECRET=.*|JWT_SECRET=walkthrough-jwt-secret|; ' .env rm -f .env.bak else step "2/8 .env exists, leaving as-is" fi step "3/8 prisma migrate dev (no seed)" pnpm exec prisma migrate dev --skip-seed --schema prisma/schema/schema.prisma step "4/8 seed demo data" SEED_DEMO_DATA=true pnpm seed step "5/8 permissions sync" pnpm run permissions:sync step "6/8 smoke gates" pnpm run verify:health-baseline pnpm run verify:test-density step "7/8 start dev server (background, 5s warm-up)" pnpm dev >/tmp/onboarding-dev.log 2>&1 & DEV_PID=$! sleep 5 if kill -0 "$DEV_PID" 2>/dev/null; then step "8/8 ✓ dev server running on http://app.localhost:3000" echo " admin@email.com / password" echo " luna.davis@company.com / password" kill "$DEV_PID" 2>/dev/null || true wait "$DEV_PID" 2>/dev/null || true else echo "FAIL dev server exited before warm-up; check /tmp/onboarding-dev.log" >&2 exit 1 fi step "✓ walkthrough complete"