82 lines
2.4 KiB
Bash
Executable File
82 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Universal resource activation — local smoke: JSON Schema validation (always) +
|
|
# optional HTTP GET to Phoenix (when --http or PHOENIX_BASE_URL is set).
|
|
#
|
|
# 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)"
|
|
trap 'rm -f "$body_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)"
|
|
exit 0
|