from __future__ import annotations from api.mcp import tool_handlers from core.models import ActiveApp from device.manager import DeviceManager from tests.fakes import FakeDriver def test_mcp_handlers_are_semantic_and_hide_driver_terms() -> None: manager = DeviceManager() manager.register_device("iphone-1", lambda: FakeDriver()) manager.connect("iphone-1", max_retries=1) handlers = tool_handlers(manager=manager) responses = [ handlers["take_screenshot"](device_id="iphone-1"), handlers["tap"](x=1, y=2, device_id="iphone-1"), handlers["swipe"]( start_x=1, start_y=2, end_x=3, end_y=4, device_id="iphone-1", ), handlers["input_text"](text="hello", device_id="iphone-1"), handlers["launch_app"](app_id="com.example.app", device_id="iphone-1"), handlers["find_text"](query="Search", device_id="iphone-1"), handlers["find_icon"](name="Settings", device_id="iphone-1"), handlers["get_ui_tree"](device_id="iphone-1"), handlers["describe_screen"](device_id="iphone-1"), handlers["list_devices"](), handlers["device_status"](device_id="iphone-1"), ] serialized = repr(responses) assert "WDA" not in serialized assert "Appium" not in serialized assert "XCUI" not in serialized assert all(response is not None for response in responses) def test_mcp_ui_tree_can_include_active_app_info() -> None: manager = DeviceManager() manager.register_device( "android-1", lambda: FakeDriver( active_app=ActiveApp( platform="android", package="com.example.mobile", activity=".MainActivity", ) ), ) manager.connect("android-1", max_retries=1) response = tool_handlers(manager=manager)["get_ui_tree"]( device_id="android-1", include_app_info=True, ) assert response["app"] == { "platform": "android", "package": "com.example.mobile", "activity": ".MainActivity", } assert isinstance(response["nodes"], list) def test_tool_handlers_requires_manager() -> None: """D12: tool_handlers must not silently fall back to DEFAULT_MANAGER.""" from api.mcp import tool_handlers import pytest with pytest.raises(TypeError): tool_handlers() # type: ignore[call-arg]