AkurAI Build
Menu

Public repository / 23447341749e267e6dbb85b2c02caa6b9d729c52

AkurAI-Monitor / scripts/validate.sh

Latest change 05f7eaa8a37d808c0eeeae096b5811ff79c8c580 - validate: expect rust-monitor ops-contract health shape (app rename + framework fields) by Ólafur Búi Ólafsson

#!/usr/bin/env bash
# Post-deploy validation for AkurAI Monitor. Runs from Titan/Build workers.
set -u

DOMAIN="${MONITOR_DOMAIN:-monitor.olibuijr.com}"
PORT="${MONITOR_PORT:-8800}"
EC2="${AKURAI_EC2:-$HOME/.local/bin/akurai-ec2}"
pass=0
fail=0

pass_() { printf '  PASS %s\n' "$*"; pass=$((pass + 1)); }
fail_() { printf '  FAIL %s\n' "$*"; fail=$((fail + 1)); }
remote() { "$EC2" ssh "$1"; }
health_json_ok() {
  python3 -c 'import json,sys; d=json.load(sys.stdin); assert d["app"]=="rust-monitor" and d["status"]=="ok" and d["version"] and d["framework"]=="AkurAI-Framework" and d["framework_version"]' >/dev/null
}
ingestion_json_ok() {
  python3 -c 'import json,sys; d=json.load(sys.stdin); configured=d["configured"]; expected=len(configured["journald_units"])+len(configured["log_files"]); assert d["status"]!="degraded" and expected>0 and len(d["sources"])>=expected' >/dev/null
}
recent_logs_ok() {
  python3 -c 'import json,sys; d=json.load(sys.stdin); assert d["count"]>0 and d["logs"]' >/dev/null
}

echo "=== Post-deploy validation: rust-monitor ==="

if [ -x "$EC2" ] && remote "systemctl is-active --quiet rust-monitor.service"; then
  pass_ "systemd active"
else
  fail_ "systemd not active or EC2 CLI unavailable"
fi

loopback_health="$(remote "curl -fsS --max-time 5 http://127.0.0.1:${PORT}/api/health" 2>/dev/null || true)"
if printf '%s' "$loopback_health" | health_json_ok; then
  pass_ "loopback health contract"
else
  fail_ "loopback health contract"
fi

public_health="$(curl -fsS --max-time 10 "https://${DOMAIN}/api/health" 2>/dev/null || true)"
if printf '%s' "$public_health" | health_json_ok; then
  pass_ "public health contract"
else
  fail_ "public health contract"
fi

asset_status="$(curl -sS -o /dev/null -w '%{http_code}:%{size_download}' --max-time 10 "https://${DOMAIN}/theme.js" 2>/dev/null || true)"
asset_code="${asset_status%%:*}"
asset_size="${asset_status#*:}"
if [ "$asset_code" = 200 ] && [ "${asset_size:-0}" -gt 100 ]; then
  pass_ "public frontend asset"
else
  fail_ "public frontend asset (${asset_status:-unreachable})"
fi

login_status="$(curl -sS -o /dev/null -w '%{http_code}' --max-time 10 "https://${DOMAIN}/" 2>/dev/null || true)"
login_target="$(curl -sS -o /dev/null -w '%{redirect_url}' --max-time 10 "https://${DOMAIN}/" 2>/dev/null || true)"
case "$login_status:$login_target" in
  307:https://auth.olibuijr.com/authorize\?*) pass_ "OIDC authorization redirect" ;;
  *) fail_ "OIDC authorization redirect (${login_status:-unreachable})" ;;
esac

callback_status="$(curl -sS -o /dev/null -w '%{http_code}' --max-time 10 "https://${DOMAIN}/auth/callback" 2>/dev/null || true)"
if [ "$callback_status" = 400 ]; then
  pass_ "OIDC callback route"
else
  fail_ "OIDC callback route (${callback_status:-unreachable})"
fi

ingestion_health="$(remote "/usr/local/bin/akurai-monitorctl ingestion health" 2>/dev/null || true)"
if printf '%s' "$ingestion_health" | ingestion_json_ok; then
  pass_ "ingestion health contract"
else
  fail_ "ingestion health contract"
fi

recent_logs="$(remote "/usr/local/bin/akurai-monitorctl logs recent --hours 24 --limit 1" 2>/dev/null || true)"
if printf '%s' "$recent_logs" | recent_logs_ok; then
  pass_ "recent log ingestion"
else
  fail_ "recent log ingestion"
fi

printf '%s\n' "------------------------------"
printf 'Pass: %s  Fail: %s\n' "$pass" "$fail"
[ "$fail" -eq 0 ]