|
2 | 2 | from types import SimpleNamespace |
3 | 3 |
|
4 | 4 | import pytest |
| 5 | +from pydantic import BaseModel |
5 | 6 |
|
6 | 7 | from hyperbrowser.client.managers.async_manager.computer_action import ( |
7 | 8 | ComputerActionManager as AsyncComputerActionManager, |
@@ -160,3 +161,79 @@ async def run() -> None: |
160 | 161 | await manager.screenshot(_SessionId("sess_123")) |
161 | 162 |
|
162 | 163 | asyncio.run(run()) |
| 164 | + |
| 165 | + |
| 166 | +def test_sync_computer_action_manager_wraps_param_serialization_errors(): |
| 167 | + class _BrokenParams(BaseModel): |
| 168 | + def model_dump(self, *args, **kwargs): # type: ignore[override] |
| 169 | + _ = args |
| 170 | + _ = kwargs |
| 171 | + raise RuntimeError("broken model_dump") |
| 172 | + |
| 173 | + manager = SyncComputerActionManager(_DummyClient()) |
| 174 | + session = SimpleNamespace(computer_action_endpoint="https://example.com/cua") |
| 175 | + |
| 176 | + with pytest.raises( |
| 177 | + HyperbrowserError, match="Failed to serialize computer action params" |
| 178 | + ) as exc_info: |
| 179 | + manager._execute_request(session, _BrokenParams()) # type: ignore[arg-type] |
| 180 | + |
| 181 | + assert isinstance(exc_info.value.original_error, RuntimeError) |
| 182 | + |
| 183 | + |
| 184 | +def test_sync_computer_action_manager_preserves_hyperbrowser_param_serialization_errors(): |
| 185 | + class _BrokenParams(BaseModel): |
| 186 | + def model_dump(self, *args, **kwargs): # type: ignore[override] |
| 187 | + _ = args |
| 188 | + _ = kwargs |
| 189 | + raise HyperbrowserError("custom model_dump failure") |
| 190 | + |
| 191 | + manager = SyncComputerActionManager(_DummyClient()) |
| 192 | + session = SimpleNamespace(computer_action_endpoint="https://example.com/cua") |
| 193 | + |
| 194 | + with pytest.raises( |
| 195 | + HyperbrowserError, match="custom model_dump failure" |
| 196 | + ) as exc_info: |
| 197 | + manager._execute_request(session, _BrokenParams()) # type: ignore[arg-type] |
| 198 | + |
| 199 | + assert exc_info.value.original_error is None |
| 200 | + |
| 201 | + |
| 202 | +def test_async_computer_action_manager_wraps_param_serialization_errors(): |
| 203 | + class _BrokenParams(BaseModel): |
| 204 | + def model_dump(self, *args, **kwargs): # type: ignore[override] |
| 205 | + _ = args |
| 206 | + _ = kwargs |
| 207 | + raise RuntimeError("broken model_dump") |
| 208 | + |
| 209 | + manager = AsyncComputerActionManager(_DummyClient()) |
| 210 | + session = SimpleNamespace(computer_action_endpoint="https://example.com/cua") |
| 211 | + |
| 212 | + async def run() -> None: |
| 213 | + with pytest.raises( |
| 214 | + HyperbrowserError, match="Failed to serialize computer action params" |
| 215 | + ) as exc_info: |
| 216 | + await manager._execute_request(session, _BrokenParams()) # type: ignore[arg-type] |
| 217 | + assert isinstance(exc_info.value.original_error, RuntimeError) |
| 218 | + |
| 219 | + asyncio.run(run()) |
| 220 | + |
| 221 | + |
| 222 | +def test_async_computer_action_manager_preserves_hyperbrowser_param_serialization_errors(): |
| 223 | + class _BrokenParams(BaseModel): |
| 224 | + def model_dump(self, *args, **kwargs): # type: ignore[override] |
| 225 | + _ = args |
| 226 | + _ = kwargs |
| 227 | + raise HyperbrowserError("custom model_dump failure") |
| 228 | + |
| 229 | + manager = AsyncComputerActionManager(_DummyClient()) |
| 230 | + session = SimpleNamespace(computer_action_endpoint="https://example.com/cua") |
| 231 | + |
| 232 | + async def run() -> None: |
| 233 | + with pytest.raises( |
| 234 | + HyperbrowserError, match="custom model_dump failure" |
| 235 | + ) as exc_info: |
| 236 | + await manager._execute_request(session, _BrokenParams()) # type: ignore[arg-type] |
| 237 | + assert exc_info.value.original_error is None |
| 238 | + |
| 239 | + asyncio.run(run()) |
0 commit comments