#!/usr/bin/env bash # qihuaiflow CI gate - run bug-audit after deployment # Usage: bash scripts/ci_bug_audit.sh [--block-on-fail] set -uo pipefail CONTAINER="qihu-aiflow" BLOCK=${1:-} AUDIT_URL="http://localhost:18080/app/api/health/bug-audit" if ! docker ps --format '{{.Names}}' | grep -qx "$CONTAINER"; then echo "[CI aud] ERROR: container $CONTAINER not running" exit 2 fi AUDIT=$(curl -s --max-time 20 "$AUDIT_URL" 2>/dev/null) if [ -z "$AUDIT" ]; then echo "[CI aud] ERROR: bug-audit endpoint unreachable" [ "$BLOCK" = "--block-on-fail" ] && exit 1 || exit 0 fi HEALTHY=$(echo "$AUDIT" | python3 -c "import json,sys;d=json.load(sys.stdin);print(d.get('data',d).get('healthy',''))" 2>/dev/null) CHECKS=$(echo "$AUDIT" | python3 -c "import json,sys;d=json.load(sys.stdin);print(d.get('data',d).get('summary',{}).get('total_checks',0))" 2>/dev/null) ISSUES=$(echo "$AUDIT" | python3 -c "import json,sys;d=json.load(sys.stdin);print(len(d.get('data',d).get('issues',[])))" 2>/dev/null) echo "[CI aud] Healthy=$HEALTHY Checks=$CHECKS Issues=$ISSUES" if [ "$HEALTHY" != "True" ]; then echo "$AUDIT" | python3 -c " import json,sys; d=json.load(sys.stdin) dd=d.get('data',d) for i in dd.get('issues',[]): print(f' ISSUE: {i}') for w in dd.get('warnings',[]): print(f' WARN: {w}') " 2>/dev/null if [ "$BLOCK" = "--block-on-fail" ]; then echo "[CI aud] audit failed (--block-on-fail mode)" exit 1 fi fi echo "[CI aud] PASSED" exit 0