#!/usr/bin/env bash
# D7 真机连通性快速自检（需在运行 SDK 的机器上执行，且手机已 USB/WiFi ADB）
set -euo pipefail
BASE="${WORKPHONE_BASE:-http://127.0.0.1:8899}"

echo "== 1) 本机 adb devices =="
adb devices -l || true

echo ""
echo "== 2) SDK 健康检查 =="
curl -sS "${BASE}/health" | head -c 500 || echo "FAIL: 无法连接 ${BASE}"

echo ""
echo "== 3) 融合设备列表 GET /api/v3/devices =="
curl -sS "${BASE}/api/v3/devices" | head -c 1200
echo ""

echo ""
echo "== 4) ADB 列表 GET /api/v3/adb/devices =="
curl -sS "${BASE}/api/v3/adb/devices" | head -c 1200
echo ""

echo ""
echo "== 5) 多机注册聚合 GET /api/v3/registry/fleet/aggregate =="
curl -sS "${BASE}/api/v3/registry/fleet/aggregate" | head -c 1200
echo ""

echo ""
echo "若 3) 中 data 为 []：请在手机端确认 USB 调试已授权，或执行 adb connect <ip>:5555"
echo "若仅远程 APK+Agent：请确保 Agent WebSocket 指向本机 ${BASE}"
