#!/usr/bin/env bash # scripts/e2e/up.sh # # Boot the DocsGPT end-to-end test stack on this machine, natively. # See e2e-plan.md (Phase 0 / P0-A) for the contract. # # Happy path: # 1. Preflight shared services (Postgres, Redis). Fail loud if down. # 2. Reset state: Postgres template clone, Redis FLUSHDB 11/12/13, wipe .e2e-tmp. # 3. Export env. # 4. Start mock LLM (7899) → Flask (7099) → Celery → Vite (5179), each in # background, each with its own pidfile + log + readiness probe. # 5. Exit 0, leaving services running. Playwright (or the user) invokes # down.sh separately when done. # # On error before handoff: tear everything down, non-zero exit. # We explicitly DO NOT tear down on the happy-path exit — that would defeat # the purpose of "up". set -euo pipefail # ----------------------------------------------------------------------------- # Paths # ----------------------------------------------------------------------------- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" PG_BIN="/Users/Shared/DBngin/postgresql/16.2/bin" DBNGIN_REDIS_BIN="/Users/Shared/DBngin/redis/7.0.0/bin" # Resolve redis-cli — PATH first, then DBngin's bundled copy. if command -v redis-cli >/dev/null 2>&1; then REDIS_CLI="$(command -v redis-cli)" elif [[ -x "$DBNGIN_REDIS_BIN/redis-cli" ]]; then REDIS_CLI="$DBNGIN_REDIS_BIN/redis-cli" else REDIS_CLI="" fi PIDDIR="/tmp/docsgpt-e2e" E2E_TMP="$REPO_ROOT/.e2e-tmp" LOGDIR="$E2E_TMP/logs" BOOT_LOG="$LOGDIR/up.log" SVC_LOGDIR="$PIDDIR" # per-service logs live with the pidfiles per the brief MOCK_LLM_PORT=7899 FLASK_PORT=7099 VITE_PORT=5179 # ----------------------------------------------------------------------------- # Bookkeeping — track which services we successfully started so we can tear # them down if something later fails. # ----------------------------------------------------------------------------- HANDOFF_OK=0 STARTED_SERVICES=() log() { local msg="[up.sh] $*" # Goes to stderr so stdout stays clean; also mirrored to the boot log. echo "$msg" >&2 if [[ -n "${BOOT_LOG:-}" ]] && [[ -d "$(dirname "$BOOT_LOG")" ]]; then echo "$msg" >> "$BOOT_LOG" fi } die() { log "ERROR: $*" exit 1 } # Trap: if we exit before handoff (failure or Ctrl-C), clean up. The happy # path sets HANDOFF_OK=1 just before `exit 0`, so the trap becomes a no-op. cleanup_on_failure() { local rc=$? if [[ "$HANDOFF_OK" -eq 1 ]]; then return 0 fi log "aborting — tearing down any services that started (rc=$rc)" if [[ -x "$SCRIPT_DIR/down.sh" ]]; then "$SCRIPT_DIR/down.sh" || true fi } trap cleanup_on_failure EXIT INT TERM # ----------------------------------------------------------------------------- # Helpers # ----------------------------------------------------------------------------- # Wait for a shell predicate to succeed. Args: