|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import json |
| 4 | + |
3 | 5 | import httpx |
4 | 6 | import pytest |
5 | 7 | from respx import MockRouter |
@@ -67,6 +69,45 @@ def test_sync_local_mode_starts_before_first_request(respx_mock: MockRouter, mon |
67 | 69 | assert dummy.closed == 1 |
68 | 70 |
|
69 | 71 |
|
| 72 | +@pytest.mark.respx(base_url="http://127.0.0.1:43127") |
| 73 | +def test_sync_local_mode_defaults_browser_type_local_when_omitted( |
| 74 | + respx_mock: MockRouter, monkeypatch: pytest.MonkeyPatch |
| 75 | +) -> None: |
| 76 | + _set_required_env(monkeypatch) |
| 77 | + |
| 78 | + dummy = _DummySeaServer("http://127.0.0.1:43127") |
| 79 | + request_body: dict[str, object] = {} |
| 80 | + |
| 81 | + def _capture_start_request(request: httpx.Request) -> httpx.Response: |
| 82 | + request_body["json"] = json.loads(request.content.decode("utf-8")) |
| 83 | + return httpx.Response( |
| 84 | + 200, |
| 85 | + json={ |
| 86 | + "success": True, |
| 87 | + "data": { |
| 88 | + "available": True, |
| 89 | + "connectUrl": "ws://example", |
| 90 | + "sessionId": "00000000-0000-0000-0000-000000000001", |
| 91 | + }, |
| 92 | + }, |
| 93 | + ) |
| 94 | + |
| 95 | + respx_mock.post("/v1/sessions/start").mock(side_effect=_capture_start_request) |
| 96 | + |
| 97 | + client = Stagehand(server="local", _local_stagehand_binary_path="/does/not/matter/in/test") |
| 98 | + client._sea_server = dummy # type: ignore[attr-defined] |
| 99 | + |
| 100 | + resp = client.sessions.start(model_name="openai/gpt-5-nano") |
| 101 | + assert resp.success is True |
| 102 | + assert request_body["json"] == { |
| 103 | + "modelName": "openai/gpt-5-nano", |
| 104 | + "browser": {"type": "local"}, |
| 105 | + } |
| 106 | + |
| 107 | + client.close() |
| 108 | + assert dummy.closed == 1 |
| 109 | + |
| 110 | + |
70 | 111 | @pytest.mark.respx(base_url="http://127.0.0.1:43124") |
71 | 112 | @pytest.mark.asyncio |
72 | 113 | async def test_async_local_mode_starts_before_first_request( |
|
0 commit comments