fix(ci): E2E Health Check 診斷強化

2026-03-29 Claude Code:
- 清除舊快取檔案避免讀到 stale response
- 增加 TCP 連接測試 (/dev/tcp)
- curl verbose 模式輸出診斷資訊
- 簡化 HTTP code 取得方式
- 增加 nc 直接測試作為備用

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-29 21:30:48 +08:00
parent 4707102498
commit 5b6e23c49f

View File

@@ -99,15 +99,28 @@ jobs:
echo "🔗 檢查 API 健康狀態..."
echo "📍 Runner: $(hostname)"
echo "🌐 Target: $API_URL"
echo "📂 Working Dir: $(pwd)"
# 2026-03-29 Claude Code: 清除舊檔案避免讀到上次快取
rm -f /tmp/health_response.txt /tmp/fallback_response.txt 2>/dev/null || true
# 診斷網路連通性
VIP_IP=$(echo "$API_URL" | sed -E 's|https?://([^:]+).*|\1|')
echo "🔍 Ping VIP ($VIP_IP)..."
ping -c 2 "$VIP_IP" || echo "⚠️ Ping failed (may be blocked)"
# 2026-03-29 Claude Code: 增加 TCP 連接測試
echo "🔌 TCP 連接測試 ($VIP_IP:32334)..."
timeout 5 bash -c "cat < /dev/null > /dev/tcp/$VIP_IP/32334" && echo "✅ TCP 連接成功" || echo "⚠️ TCP 連接失敗"
# 嘗試連線 (正確路徑: /api/v1/health)
echo "🔗 Curl health endpoint..."
HTTP_CODE=$(curl -s -o /tmp/health_response.txt -w "%{http_code}" --connect-timeout 15 "$API_URL/api/v1/health" || echo "000")
echo "🔗 Curl health endpoint (verbose)..."
# 2026-03-29 Claude Code: 改用 verbose 模式輸出診斷資訊
curl -v --connect-timeout 15 "$API_URL/api/v1/health" -o /tmp/health_response.txt 2>&1 | head -30 || true
# 2026-03-29 Claude Code: 重新取得 HTTP code (簡化)
HTTP_CODE=$(curl -s -w "%{http_code}" -o /dev/null --connect-timeout 15 "$API_URL/api/v1/health" 2>/dev/null)
echo "📊 HTTP Code: [$HTTP_CODE]"
if [ "$HTTP_CODE" = "200" ]; then
echo "✅ API 可用: $API_URL (HTTP $HTTP_CODE)"
@@ -115,18 +128,22 @@ jobs:
echo "working_api_url=$API_URL" >> $GITHUB_OUTPUT
else
echo "❌ API 無法連線: $API_URL (HTTP $HTTP_CODE)"
echo "📋 Response:"
echo "📋 Response (如有):"
cat /tmp/health_response.txt 2>/dev/null || echo "(empty)"
# 2026-03-29 Claude Code: 使用 nc 直接測試
echo "🔧 使用 nc 直接測試..."
echo -e "GET /api/v1/health HTTP/1.1\r\nHost: $VIP_IP:32334\r\n\r\n" | nc -w5 $VIP_IP 32334 | head -5 || echo "nc 測試失敗"
# 嘗試備用端點 (node 121 直連)
FALLBACK_URL="http://192.168.0.121:32334"
echo "🔄 嘗試備用端點: $FALLBACK_URL"
FALLBACK_CODE=$(curl -s -o /tmp/fallback_response.txt -w "%{http_code}" --connect-timeout 10 "$FALLBACK_URL/api/v1/health" || echo "000")
FALLBACK_CODE=$(curl -s -w "%{http_code}" -o /dev/null --connect-timeout 10 "$FALLBACK_URL/api/v1/health" 2>/dev/null)
echo " 備用結果: HTTP $FALLBACK_CODE"
if [ "$FALLBACK_CODE" = "200" ]; then
echo "✅ 備用端點可用VIP 可能有問題"
cat /tmp/fallback_response.txt
curl -s "$FALLBACK_URL/api/v1/health"
echo "working_api_url=$FALLBACK_URL" >> $GITHUB_OUTPUT
exit 0 # 備用成功,不算失敗
fi