127 lines
4.6 KiB
Bash
Executable File
127 lines
4.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Universal resource activation — local smoke: JSON Schema validation (always) +
|
|
# optional HTTP GETs to Phoenix (when --http or PHOENIX_BASE_URL is set):
|
|
# 1) GET /api/v1/universal-resource-activation/manifest (expect 200 + .schemaVersion)
|
|
# 2) GET /api/v1/universal-resource-activation/policy-profiles (expect 200 + .profiles array)
|
|
# 3) GET /api/v1/universal-resource-activation/server-funds-sidecar-probe
|
|
# — expect 200 (sidecar ok or probe JSON) or 503 with .configured == false (URL unset)
|
|
# — 502 = fail (URL set but sidecar paths not healthy)
|
|
#
|
|
# Usage (repo root):
|
|
# bash scripts/verify/smoke-universal-resource-activation.sh
|
|
# bash scripts/verify/smoke-universal-resource-activation.sh --http
|
|
# PHOENIX_BASE_URL=http://127.0.0.1:4001 bash scripts/verify/smoke-universal-resource-activation.sh --http
|
|
#
|
|
# Requires: node (for validate-universal-resource-activation.mjs). For --http: curl and jq.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
VALIDATOR="$PROJECT_ROOT/scripts/validate/validate-universal-resource-activation.mjs"
|
|
DO_HTTP=false
|
|
for a in "$@"; do
|
|
[[ "$a" == "--http" ]] && DO_HTTP=true && break
|
|
done
|
|
|
|
if [[ -n "${PHOENIX_BASE_URL:-}" ]]; then
|
|
DO_HTTP=true
|
|
fi
|
|
|
|
log() { echo "[smoke-ura] $*"; }
|
|
log_err() { echo "[smoke-ura] ERROR: $*" >&2; }
|
|
|
|
if [[ ! -f "$VALIDATOR" ]]; then
|
|
log_err "Missing $VALIDATOR"
|
|
exit 1
|
|
fi
|
|
if ! command -v node &>/dev/null; then
|
|
log_err "node not found (required for schema validation)"
|
|
exit 1
|
|
fi
|
|
|
|
log "Running JSON Schema validation (manifest + resources + evidence)…"
|
|
if ! node "$VALIDATOR"; then
|
|
log_err "Schema validation failed"
|
|
exit 1
|
|
fi
|
|
log "Schema validation OK"
|
|
|
|
if ! $DO_HTTP; then
|
|
log "HTTP smoke skipped (pass --http or set PHOENIX_BASE_URL to also curl Phoenix)"
|
|
exit 0
|
|
fi
|
|
|
|
BASE="${PHOENIX_BASE_URL:-http://127.0.0.1:4001}"
|
|
BASE="${BASE%/}"
|
|
URL="${BASE}/api/v1/universal-resource-activation/manifest"
|
|
|
|
if ! command -v curl &>/dev/null; then
|
|
log_err "--http requested but curl not installed"
|
|
exit 1
|
|
fi
|
|
if ! command -v jq &>/dev/null; then
|
|
log_err "--http requested but jq not installed"
|
|
exit 1
|
|
fi
|
|
|
|
log "GET $URL (expect 200, JSON with .schemaVersion)…"
|
|
body_file="$(mktemp)"
|
|
probe_file="$(mktemp)"
|
|
profiles_file="$(mktemp)"
|
|
trap 'rm -f "$body_file" "$probe_file" "$profiles_file"' EXIT
|
|
code=$(curl -sS -o "$body_file" -w '%{http_code}' --connect-timeout 5 --max-time 15 "$URL" || true)
|
|
|
|
if [[ "$code" != "200" ]]; then
|
|
log_err "HTTP $code (expected 200). Is phoenix-deploy-api running? BASE=$BASE"
|
|
if [[ -f "$body_file" ]] && [[ -s "$body_file" ]]; then
|
|
head -c 500 "$body_file" >&2 || true
|
|
fi
|
|
exit 1
|
|
fi
|
|
|
|
if ! jq -e '.schemaVersion | type == "string"' "$body_file" &>/dev/null; then
|
|
log_err "Response missing string .schemaVersion"
|
|
cat "$body_file" >&2
|
|
exit 1
|
|
fi
|
|
log "HTTP OK (.schemaVersion present; HTTP $code)"
|
|
|
|
PROFILES_URL="${BASE}/api/v1/universal-resource-activation/policy-profiles"
|
|
log "GET $PROFILES_URL (expect 200, JSON with .profiles array)…"
|
|
prcode=$(curl -sS -o "$profiles_file" -w '%{http_code}' --connect-timeout 5 --max-time 15 "$PROFILES_URL" || true)
|
|
if [[ "$prcode" != "200" ]]; then
|
|
log_err "policy-profiles HTTP $prcode (expected 200). BASE=$BASE"
|
|
exit 1
|
|
fi
|
|
if ! jq -e '(.profiles | type == "array")' "$profiles_file" &>/dev/null; then
|
|
log_err "policy-profiles response missing .profiles array"
|
|
cat "$profiles_file" >&2
|
|
exit 1
|
|
fi
|
|
log "policy-profiles HTTP OK"
|
|
|
|
PROBE_URL="${BASE}/api/v1/universal-resource-activation/server-funds-sidecar-probe"
|
|
log "GET $PROBE_URL (expect 200 OK response or 503 with configured not true when URL unset)…"
|
|
pcode=$(curl -sS -o "$probe_file" -w '%{http_code}' --connect-timeout 5 --max-time 20 "$PROBE_URL" || true)
|
|
|
|
if [[ "$pcode" == "200" ]]; then
|
|
if ! jq -e 'type == "object"' "$probe_file" &>/dev/null; then
|
|
log_err "Probe response is not a JSON object"
|
|
exit 1
|
|
fi
|
|
log "sidecar-probe HTTP 200 (JSON object returned)"
|
|
elif [[ "$pcode" == "503" ]]; then
|
|
if ! jq -e '.configured == false' "$probe_file" &>/dev/null; then
|
|
log_err "Probe expected 503 with .configured==false when SERVER_FUNDS_SIDECAR_URL unset; got: $(head -c 400 "$probe_file")"
|
|
exit 1
|
|
fi
|
|
log "sidecar-probe HTTP 503 (SERVER_FUNDS_SIDECAR_URL not set — expected in dev)"
|
|
elif [[ "$pcode" == "502" ]]; then
|
|
log_err "sidecar-probe HTTP 502 — SERVER_FUNDS_SIDECAR_URL is set but sidecar health paths failed. Fix env or sidecar. Body: $(head -c 400 "$probe_file")"
|
|
exit 1
|
|
else
|
|
log_err "sidecar-probe HTTP $pcode (expected 200, 503, or 502). Body: $(head -c 400 "$probe_file")"
|
|
exit 1
|
|
fi
|
|
exit 0
|