From 0a16df1cfec261a9161bfd7109d196304537b3c4 Mon Sep 17 00:00:00 2001 From: Adam Moussa Date: Sat, 26 Sep 2026 16:43:38 -0400 Subject: [PATCH] fix(cd): report the real health status when curl fails --- scripts/test-verify-api-health.sh | 17 ++++++++++++++++- scripts/verify-api-health.sh | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/test-verify-api-health.sh b/scripts/test-verify-api-health.sh index 092e457..b841ade 100755 --- a/scripts/test-verify-api-health.sh +++ b/scripts/test-verify-api-health.sh @@ -19,7 +19,7 @@ assert_exit() { } run_with_curl() { - local name="$1" expected="$2" curl_body="$3" + local name="$1" expected="$2" curl_body="$3" must="${4:-}" forbid="${5:-}" local dir dir="$(mktemp -d)" cat > "${dir}/curl" << CURL @@ -51,6 +51,16 @@ CURL local code=$? set -e assert_exit "${name}" "${expected}" "${code}" "${log}" + if [[ -n "${must}" ]] && ! grep -F "${must}" "${log}" >/dev/null; then + echo "FAIL: ${name}: log missing ${must}" >&2 + sed -n '1,80p' "${log}" >&2 + failures=$((failures + 1)) + fi + if [[ -n "${forbid}" ]] && grep -F "${forbid}" "${log}" >/dev/null; then + echo "FAIL: ${name}: log contains ${forbid}" >&2 + sed -n '1,80p' "${log}" >&2 + failures=$((failures + 1)) + fi rm -rf "${dir}" } @@ -72,6 +82,11 @@ run_with_curl "health-503" 1 ' exit 0 ' +run_with_curl "curl-failure" 1 ' +[[ -n "${write_out}" ]] && printf "000" +exit 1 +' 'http=000 sha=' 'http=000000' + if [[ "${failures}" -ne 0 ]]; then echo "FAIL: ${failures} verify-api-health cases failed" >&2 exit 1 diff --git a/scripts/verify-api-health.sh b/scripts/verify-api-health.sh index 8f8f633..de09b4f 100755 --- a/scripts/verify-api-health.sh +++ b/scripts/verify-api-health.sh @@ -20,7 +20,7 @@ attempt=0 while [[ "${attempt}" -lt "${BUDGET}" ]]; do attempt=$((attempt + 1)) tmp="$(mktemp)" - last_code="$(curl -sS --max-time 30 -o "${tmp}" -w '%{http_code}' "${SITE_URL}/api/health" || printf '000')" + last_code="$(curl -sS --max-time 30 -o "${tmp}" -w '%{http_code}' "${SITE_URL}/api/health" || true)" last_sha="$(python3 -c 'import json,sys try: print(json.load(open(sys.argv[1], encoding="utf-8")).get("sha") or "")