← back to Costa Rica
scripts/smoke-prod.sh
45 lines
#!/usr/bin/env bash
# smoke-prod.sh — READ-ONLY prod smoke test for the Costa Rica marketplace.
# Hits public (non-gated) endpoints on the live site and asserts they respond
# correctly. Makes NO writes (no register/login/booking) — safe to run anytime,
# e.g. after a deploy or as a canary. Exit 0 = all green, non-zero = a failure.
#
# Usage: scripts/smoke-prod.sh [BASE]
# BASE defaults to https://costarica.agentabrams.com
# Override for a local check: scripts/smoke-prod.sh http://127.0.0.1:9791
set -u
BASE="${1:-https://costarica.agentabrams.com}"
fail=0
check() { # name url expected_code [must_contain]
local name="$1" url="$2" want="$3" needle="${4:-}"
local body code
body=$(curl -s -w $'\n%{http_code}' --max-time 15 "$url" 2>/dev/null)
code=$(printf '%s' "$body" | tail -1)
body=$(printf '%s' "$body" | sed '$d')
if [ "$code" != "$want" ]; then
echo "FAIL $name — got HTTP $code, want $want ($url)"; fail=1; return
fi
if [ -n "$needle" ] && ! printf '%s' "$body" | grep -q "$needle"; then
echo "FAIL $name — HTTP $want but missing '$needle' ($url)"; fail=1; return
fi
echo "OK $name — HTTP $code${needle:+ (contains '$needle')}"
}
echo "== Costa Rica marketplace smoke — $BASE =="
# 1) Public health endpoint must be 200.
check "api health" "$BASE/api/app/health" 200
# 2) Public listings endpoint (optionalAuth) must serve JSON, not 5xx.
check "public listings" "$BASE/api/app/listings" 200
# 3) Front door is admin-gated → 401 with a Basic realm is the CORRECT healthy state.
# (The realm is in the WWW-Authenticate response header, not the body.)
gate_hdr=$(curl -sI --max-time 15 "$BASE/" 2>/dev/null)
if printf '%s' "$gate_hdr" | grep -qiE '^HTTP/.* 401' && printf '%s' "$gate_hdr" | grep -qi 'www-authenticate: *Basic'; then
echo "OK front-door gate — HTTP 401 + Basic realm (admin gate healthy)"
else
echo "FAIL front-door gate — expected 401 + WWW-Authenticate: Basic ($BASE/)"; fail=1
fi
if [ "$fail" -eq 0 ]; then echo "== ALL GREEN =="; else echo "== SMOKE FAILED =="; fi
exit "$fail"