#!/usr/bin/env bash # smoke-test.sh — OSVauco OPAX røyktest # Kjør fra Cloud Shell etter deploy: # bash scripts/smoke-test.sh # # Forutsetning: gcloud-innlogget med tilgang til prosjektet. set -euo pipefail URL="${OPAX_URL:-https://osvauco-agent-357036551735.europe-west1.run.app}" TOKEN=$(gcloud auth print-identity-token) H_AUTH="Authorization: Bearer $TOKEN" H_JSON="Content-Type: application/json" PASS=0 FAIL=0 check() { local label="$1" local expected_http="$2" local body="$3" local endpoint="$4" http_code=$(curl -s -o /tmp/smoke_resp.json -w "%{http_code}" \ -X POST \ -H "$H_AUTH" \ -H "$H_JSON" \ -d "$body" \ "${URL}${endpoint}") resp=$(cat /tmp/smoke_resp.json) if [[ "$http_code" == "$expected_http" ]]; then echo "✅ [$http_code] $label" echo " └ $(echo "$resp" | head -c 120)" PASS=$((PASS+1)) else echo "❌ [$http_code] $label (forventet $expected_http)" echo " └ $resp" FAIL=$((FAIL+1)) fi } check_get() { local label="$1" local expected_http="$2" local endpoint="$3" http_code=$(curl -s -o /tmp/smoke_resp.json -w "%{http_code}" \ -H "$H_AUTH" \ "${URL}${endpoint}") resp=$(cat /tmp/smoke_resp.json) if [[ "$http_code" == "$expected_http" ]]; then echo "✅ [$http_code] $label" echo " └ $(echo "$resp" | head -c 120)" PASS=$((PASS+1)) else echo "❌ [$http_code] $label (forventet $expected_http)" echo " └ $resp" FAIL=$((FAIL+1)) fi } echo "======================================" echo " OSVauco OPAX RØYKTEST" echo " URL: $URL" echo "======================================" echo "" # 1. Health check_get "GET /health" 200 "/health" # 2. Light mode check "POST /run light" 200 \ '{"message": "Hva er OPAX?", "user_id": "opax", "mode": "light"}' "/run" # 3. Heavy mode (autorisert) check "POST /run heavy (autorisert)" 200 \ '{"message": "Hva gjør heavy mode?", "user_id": "opax", "mode": "heavy"}' "/run" # 4. Legacy A → normalisert til light check "POST /run legacy A (bakoverkompatibel)" 200 \ '{"message": "Test legacy mode", "user_id": "opax", "mode": "A"}' "/run" # 5. Legacy A+ → normalisert til heavy check "POST /run legacy A+ (bakoverkompatibel)" 200 \ '{"message": "Test legacy A+", "user_id": "opax", "mode": "A+"}' "/run" # 6. Ugyldig mode → 400 check "POST /run ugyldig mode → 400" 400 \ '{"message": "Test ugyldig", "user_id": "opax", "mode": "turbo"}' "/run" # 7. Uautorisert bruker heavy → 403 check "POST /run heavy uautorisert → 403" 403 \ '{"message": "Hemmelig", "user_id": "guest", "mode": "heavy"}' "/run" # 8. DAG parallell check "POST /run/dag (2 meldinger parallelt)" 200 \ '{"messages": ["Hva er OSVauco?", "Hva koster light mode?"], "user_id": "opax", "mode": "light"}' "/run/dag" # 9. State snapshot check_get "GET /state" 200 "/state" # 10. Telemetri-historikk check_get "GET /telemetry/history" 200 "/telemetry/history?limit=5" echo "" echo "======================================" echo " RESULTAT: ✅ $PASS bestod | ❌ $FAIL feilet" echo "======================================" [[ $FAIL -eq 0 ]] && exit 0 || exit 1