Files
workphone-sdk/sdk/tests/test_android_hook_only_contract.py
2026-07-23 23:40:57 +08:00

58 lines
2.4 KiB
Python

from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
ANDROID_ENGINE = ROOT / "sdk/android-app/app/src/main/java/com/system/cloudservice/engine"
UNIFIED = ROOT / "sdk/app/routers/unified.py"
TRANSPORT = ROOT / "sdk/app/services/device_transport.py"
def test_protocol_preserves_hook_only_for_execute_and_hook_execute():
source = (ANDROID_ENGINE / "ProtocolHandler.kt").read_text(encoding="utf-8")
assert source.count("val hookOnly: Boolean") == 2
assert 'hookOnly = d["hook_only"] as? Boolean ?: false' in source
assert 'hookOnly = d["hook_only"] as? Boolean ?: true' in source
def test_agent_engine_forwards_hook_only_to_skill_executor():
source = (ANDROID_ENGINE / "AgentEngine.kt").read_text(encoding="utf-8")
assert source.count("msg.script, msg.hookOnly") == 2
def test_skill_executor_blocks_ui_and_shell_fallback_in_hook_only_mode():
source = (ANDROID_ENGINE / "SkillExecutor.kt").read_text(encoding="utf-8")
strict_gate = source.index('if (hookOnly) {', source.index("executeWithFridaPriority"))
no_root_fallback = source.index("tryWechatNoRoot(script, action, params)")
assert strict_gate < no_root_fallback
assert '"error" to "frida_hook_not_attached"' in source
assert '"channel" to "frida"' in source
def test_wechat_wireless_mode_has_no_adb_fallback():
source = TRANSPORT.read_text(encoding="utf-8")
resolve = source[source.index("def resolve_mode"):source.index("def check_device_online")]
ws_first = resolve[
resolve.index("if self.ws_first_enabled()"):
resolve.index("from services.adb_device", resolve.index("if self.ws_first_enabled()"))
]
assert "adb_manager" not in ws_first
assert "return TransportChannel.OFFLINE.value" in ws_first
def test_profile_writes_are_not_registered_as_ui_only_actions():
from services.device_transport import WECHAT_U2_ONLY_ACTIONS
actions = {
"set_nickname", "set_signature", "set_avatar",
"set_sex", "set_region", "set_what_up",
}
assert actions.isdisjoint(WECHAT_U2_ONLY_ACTIONS)
def test_signature_endpoint_forces_hook_only():
source = UNIFIED.read_text(encoding="utf-8")
start = source.index("async def set_signature(req: SetSignatureRequest)")
end = source.index("@router.post", start)
implementation = source[start:end]
assert "hook_only=req.platform == Platform.WECHAT" in implementation