|
8 | 8 | from hud.tools.computer.anthropic import AnthropicComputerTool |
9 | 9 | from hud.tools.computer.gemini import GeminiComputerTool |
10 | 10 | from hud.tools.computer.glm import GLMComputerTool |
11 | | -from hud.tools.computer.hud import HudComputerTool |
| 11 | +from hud.tools.computer.hud import AgentCoordinate, HudComputerTool |
12 | 12 | from hud.tools.computer.openai import OpenAIComputerTool |
13 | 13 | from hud.tools.computer.qwen import QwenComputerTool |
14 | 14 | from hud.tools.executors.base import BaseExecutor |
@@ -75,12 +75,28 @@ async def test_anthropic_computer_screenshot(): |
75 | 75 |
|
76 | 76 |
|
77 | 77 | @pytest.mark.asyncio |
78 | | -async def test_gemini_computer_click_reports_agent_coordinates(): |
| 78 | +async def test_gemini_computer_scaling_preserves_model_coordinates(): |
79 | 79 | comp = GeminiComputerTool() |
| 80 | + x, y = comp._scale_coordinates(214, 420) |
| 81 | + |
| 82 | + assert x is not None |
| 83 | + assert y is not None |
| 84 | + assert int(x) != 214 |
| 85 | + assert int(y) != 420 |
| 86 | + assert getattr(x, "agent_value") == 214 |
| 87 | + assert getattr(y, "agent_value") == 420 |
| 88 | + |
| 89 | + |
| 90 | +@pytest.mark.asyncio |
| 91 | +async def test_gemini_computer_click_reports_model_coordinates(): |
| 92 | + comp = GeminiComputerTool(executor=BaseExecutor()) |
| 93 | + |
80 | 94 | blocks = await comp(action="click_at", x=214, y=420) |
81 | 95 |
|
82 | 96 | assert any( |
83 | | - "(214, 420)" in content.text for content in blocks if isinstance(content, TextContent) |
| 97 | + "Clicked at (214, 420)" in content.text |
| 98 | + for content in blocks |
| 99 | + if isinstance(content, TextContent) |
84 | 100 | ) |
85 | 101 |
|
86 | 102 |
|
@@ -125,40 +141,44 @@ async def test_anthropic_computer_zoom(): |
125 | 141 |
|
126 | 142 | @pytest.mark.asyncio |
127 | 143 | async def test_openai_computer_click(): |
128 | | - comp = OpenAIComputerTool() |
| 144 | + comp = OpenAIComputerTool(executor=BaseExecutor()) |
129 | 145 | blocks = await comp(type="click", x=5, y=5) |
130 | 146 | assert blocks |
131 | | - assert any("(5, 5)" in content.text for content in blocks if isinstance(content, TextContent)) |
132 | 147 |
|
133 | 148 |
|
134 | 149 | @pytest.mark.asyncio |
135 | | -async def test_anthropic_computer_click_reports_agent_coordinates(): |
136 | | - comp = AnthropicComputerTool() |
137 | | - blocks = await comp(action="left_click", coordinate=[123, 456], text=None) |
| 150 | +async def test_anthropic_computer_scaling_preserves_agent_coordinates(): |
| 151 | + comp = AnthropicComputerTool(executor=BaseExecutor()) |
| 152 | + x, y = comp._scale_coordinates(123, 456) |
138 | 153 |
|
139 | | - assert any( |
140 | | - "(123, 456)" in content.text for content in blocks if isinstance(content, TextContent) |
141 | | - ) |
| 154 | + assert x is not None |
| 155 | + assert y is not None |
| 156 | + assert getattr(x, "agent_value") == 123 |
| 157 | + assert getattr(y, "agent_value") == 456 |
142 | 158 |
|
143 | 159 |
|
144 | 160 | @pytest.mark.asyncio |
145 | | -async def test_qwen_computer_click_reports_agent_coordinates(): |
146 | | - comp = QwenComputerTool() |
147 | | - blocks = await comp(action="left_click", coordinate=[123, 456]) |
| 161 | +async def test_qwen_computer_scaling_preserves_agent_coordinates(): |
| 162 | + comp = QwenComputerTool(executor=BaseExecutor()) |
| 163 | + x, y = comp._scale_coordinates(123, 456) |
148 | 164 |
|
149 | | - assert any( |
150 | | - "(123, 456)" in content.text for content in blocks if isinstance(content, TextContent) |
151 | | - ) |
| 165 | + assert x is not None |
| 166 | + assert y is not None |
| 167 | + assert getattr(x, "agent_value") == 123 |
| 168 | + assert getattr(y, "agent_value") == 456 |
152 | 169 |
|
153 | 170 |
|
154 | 171 | @pytest.mark.asyncio |
155 | | -async def test_glm_computer_click_reports_agent_coordinates(): |
156 | | - comp = GLMComputerTool() |
157 | | - blocks = await comp(action="left_click", start_box="[123,456]") |
| 172 | +async def test_glm_computer_scaling_preserves_model_coordinates(): |
| 173 | + comp = GLMComputerTool(executor=BaseExecutor()) |
| 174 | + x, y = comp._scale_coordinates(123, 456) |
158 | 175 |
|
159 | | - assert any( |
160 | | - "(123, 456)" in content.text for content in blocks if isinstance(content, TextContent) |
161 | | - ) |
| 176 | + assert x is not None |
| 177 | + assert y is not None |
| 178 | + assert int(x) != 123 |
| 179 | + assert int(y) != 456 |
| 180 | + assert getattr(x, "agent_value") == 123 |
| 181 | + assert getattr(y, "agent_value") == 456 |
162 | 182 |
|
163 | 183 |
|
164 | 184 | def test_normalized_coordinate_max_stays_in_display_bounds(): |
@@ -217,6 +237,15 @@ async def test_xdo_drag_executes_interpolated_mouse_moves(): |
217 | 237 | assert mouse_moves[-1] == "mousemove 120 0" |
218 | 238 |
|
219 | 239 |
|
| 240 | +@pytest.mark.asyncio |
| 241 | +async def test_xdo_commands_use_execution_pixels_for_agent_coordinates(): |
| 242 | + executor = RecordingXDOExecutor() |
| 243 | + |
| 244 | + await executor.click(x=AgentCoordinate(309, 214), y=AgentCoordinate(396, 420)) |
| 245 | + |
| 246 | + assert executor.commands[-1] == "mousemove 309 396 click 1" |
| 247 | + |
| 248 | + |
220 | 249 | class TestHudComputerToolExtended: |
221 | 250 | """Extended tests for HudComputerTool covering edge cases and platform logic.""" |
222 | 251 |
|
|
0 commit comments