test(hook): E2E 支持 Phantom 无 Agent WS + hook/execute 路由

probe 通过时不再因 devices_online=0 跳过;修正 unified/execute 404。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Manus AI
2026-05-24 10:45:40 +08:00
parent cf2a26dad9
commit 977925ca6e
2 changed files with 62 additions and 23 deletions

View File

@@ -41,20 +41,32 @@ def report(name: str, ok: bool, detail: str = ""):
async def check_health(client: httpx.AsyncClient) -> bool:
resp = await client.get(f"{BASE_URL}/health")
h = resp.json()
report("SDK 健康", resp.status_code == 200, f"devices_online={h.get('devices_online', 0)}")
return h.get("devices_online", 0) > 0
online = h.get("devices_online", 0)
report("SDK 健康", resp.status_code == 200, f"devices_online={online}")
if online > 0:
return True
# Phantom + 本地 ADB 路径Agent WS 未注册时 hook/probe 仍可能可用
probe = await client.get(f"{BASE_URL}/api/v3/hook/probe/{DEVICE_ID}", timeout=90)
if probe.status_code == 200 and probe.json().get("supports_hook"):
report("Hook 探针", True, "supports_hook无 Agent WS走本地 Frida")
return True
return False
async def check_device_hook_status(client: httpx.AsyncClient) -> bool:
probe = await client.get(f"{BASE_URL}/api/v3/hook/probe/{DEVICE_ID}", timeout=90)
if probe.status_code == 200 and probe.json().get("supports_hook"):
report("Frida 可用", True, "hook/probe supports_hook")
return True
resp = await client.get(f"{BASE_URL}/api/v3/devices/{DEVICE_ID}")
if resp.status_code != 200:
report("设备详情", False, f"HTTP {resp.status_code}")
return False
d = resp.json().get("data", {})
frida = d.get("frida_available") or d.get("supports_hook") or d.get("capabilities", {}).get("frida")
report("设备在线", d.get("status") == "online", f"status={d.get('status')}")
report("Frida 可用", bool(frida), f"frida={frida}")
return bool(frida)
if resp.status_code == 200:
d = resp.json().get("data", {})
frida = d.get("frida_available") or d.get("supports_hook") or d.get("capabilities", {}).get("frida")
report("设备在线", d.get("status") == "online", f"status={d.get('status')}")
report("Frida 可用", bool(frida), f"frida={frida}")
return bool(frida)
report("Frida 可用", False, "device + probe 均不可用")
return False
async def check_hook_send_message(client: httpx.AsyncClient) -> bool:
@@ -84,37 +96,44 @@ async def check_hook_get_contacts(client: httpx.AsyncClient) -> bool:
"device_id": DEVICE_ID,
"platform": "wechat",
"action": "get_contacts",
"channel": "hook",
"params": {"limit": 5},
"hook_only": True,
}
resp = await client.post(f"{BASE_URL}/api/v3/unified/execute", json=payload)
resp = await client.post(f"{BASE_URL}/api/v3/hook/execute", json=payload)
r = resp.json()
ok = resp.status_code == 200
ok = resp.status_code == 200 and r.get("code") == 200
report("Hook 获取联系人", ok, f"status={resp.status_code}")
return ok
async def check_hook_fallback(client: httpx.AsyncClient) -> bool:
"""测试 Hook 失败后降级到 u2"""
"""无 channel 时走 ChannelRouter 自动选路Phantom 下应落到 hook"""
payload = {
"device_id": DEVICE_ID,
"platform": "wechat",
"to_id": TO_ID,
"content": "[Hook E2E] 降级测试",
"content": "[Hook E2E] 自动路由测试",
"msg_type": "text",
"channel": "auto",
}
resp = await client.post(f"{BASE_URL}/api/v3/message/send", json=payload)
r = resp.json()
ch = r.get("channel_used", "unknown")
report("自动通道选择", resp.status_code == 200, f"channel_used={ch}")
return resp.status_code == 200
ok = resp.status_code == 200 and r.get("code") == 200
report("自动通道选择", ok, f"channel_used={ch}")
return ok
async def check_version_compat(client: httpx.AsyncClient) -> bool:
"""测试 H24 版本兼容查询"""
resp = await client.post(
f"{BASE_URL}/api/v3/unified/execute",
json={"device_id": DEVICE_ID, "platform": "wechat", "action": "get_version_compat", "channel": "hook"},
f"{BASE_URL}/api/v3/hook/execute",
json={
"device_id": DEVICE_ID,
"platform": "wechat",
"action": "get_version_compat",
"params": {},
"hook_only": True,
},
)
if resp.status_code == 200:
r = resp.json()
@@ -130,8 +149,14 @@ async def check_version_compat(client: httpx.AsyncClient) -> bool:
async def check_wechat_version(client: httpx.AsyncClient) -> bool:
"""获取微信版本"""
resp = await client.post(
f"{BASE_URL}/api/v3/unified/execute",
json={"device_id": DEVICE_ID, "platform": "wechat", "action": "get_wechat_version", "channel": "hook"},
f"{BASE_URL}/api/v3/hook/execute",
json={
"device_id": DEVICE_ID,
"platform": "wechat",
"action": "get_wechat_version",
"params": {},
"hook_only": True,
},
)
if resp.status_code == 200:
r = resp.json()

View File

@@ -1,3 +1,17 @@
---
tags:
- 工作手机
- 项目管理
- 进度
doc-type: 进度
layer: 10、项目管理
parent: [[10、项目管理/README|10、项目管理]]
related:
- "[[开发进度总表]]"
- "[[工作日志]]"
- "[[项目目录总览]]"
- "[[开发文档/README|开发文档总入口]]"
---
# 工作手机SDK v3.0 - 工作日志
> **管理Skill**: 工作手机/机擎/SKILL.md火炬+五人)
@@ -3420,4 +3434,4 @@ v3.1: Agent 内置 AI Brain → 心跳驱动自主决策 → Frida优先/u2兜
**进度**: 99.5%
---
---