#!/usr/bin/env bash
# 微信 128 action 全量验收：等 WS Agent → 静态审计 → Hook catalog → 业务冒烟
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
DEVICE="${SDK_DEVICE_ID:-xgfe65eimrrofyws}"
BASE="${SDK_BASE_URL:-http://127.0.0.1:8899}"
WAIT="${WAIT_SEC:-3600}"

echo "== 1/4 等待 WS Agent (${DEVICE}) 最长 ${WAIT}s =="
bash "$ROOT/sdk/scripts/wait_ws_agent.sh" "$DEVICE" "$BASE" "$WAIT" || {
  echo "❌ Agent 未上线。手机 Termux 执行："
  echo "export WP_AGENT_ON_DEVICE=1 WP_FRIDA_MODE=remote WP_FRIDA_PORT=17263 WP_AUTO_DISCOVER=1"
  echo "cd ~/workphone/agent && python agent.py -d $DEVICE --heartbeat 10"
  exit 1
}

echo "== 2/4 静态三方对齐 =="
python3 "$ROOT/sdk/scripts/wechat_interface_audit.py" --probe -d "$DEVICE" --base "$BASE"

echo "== 3/4 Hook catalog 全 action 探针 =="
python3 "$ROOT/sdk/scripts/matrix_hook_catalog_verify.py" -d "$DEVICE"

echo "== 4/4 业务冒烟：发消息 + 朋友圈 =="
bash "$ROOT/sdk/scripts/run_kaluo_msg_moments.sh"

echo "✅ 全量验收流水线完成"
