|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import os |
3 | 4 | import json |
4 | 5 | from pathlib import Path |
5 | 6 |
|
@@ -85,10 +86,27 @@ def _fake_popen( |
85 | 86 | captured_env.update(env) |
86 | 87 | return _DummyProcess() |
87 | 88 |
|
88 | | - monkeypatch.setattr(sea_server, "_pick_free_port", lambda _host: port) |
89 | | - monkeypatch.setattr(sea_server, "_terminate_process", lambda proc: setattr(proc, "_returncode", 0)) |
90 | | - monkeypatch.setattr(sea_server, "_wait_ready_sync", lambda **_kwargs: None) |
91 | | - monkeypatch.setattr(sea_server, "resolve_binary_path", lambda **_kwargs: binary_path) |
| 89 | + def _fake_pick_free_port(_host: str) -> int: |
| 90 | + return port |
| 91 | + |
| 92 | + def _fake_terminate_process(proc: _DummyProcess) -> None: |
| 93 | + proc._returncode = 0 |
| 94 | + |
| 95 | + def _fake_wait_ready_sync(*, base_url: str, timeout_s: float) -> None: |
| 96 | + del base_url, timeout_s |
| 97 | + |
| 98 | + def _fake_resolve_binary_path( |
| 99 | + *, |
| 100 | + _local_stagehand_binary_path: str | os.PathLike[str] | None = None, |
| 101 | + version: str | None = None, |
| 102 | + ) -> Path: |
| 103 | + del _local_stagehand_binary_path, version |
| 104 | + return binary_path |
| 105 | + |
| 106 | + monkeypatch.setattr(sea_server, "_pick_free_port", _fake_pick_free_port) |
| 107 | + monkeypatch.setattr(sea_server, "_terminate_process", _fake_terminate_process) |
| 108 | + monkeypatch.setattr(sea_server, "_wait_ready_sync", _fake_wait_ready_sync) |
| 109 | + monkeypatch.setattr(sea_server, "resolve_binary_path", _fake_resolve_binary_path) |
92 | 110 | monkeypatch.setattr(sea_server.subprocess, "Popen", _fake_popen) |
93 | 111 |
|
94 | 112 |
|
@@ -271,14 +289,17 @@ def test_local_mode_masks_inherited_model_api_key_envs_and_prefers_explicit_para |
271 | 289 | captured_env: dict[str, str] = {} |
272 | 290 | _install_fake_sea_runtime(monkeypatch, tmp_path, captured_env, port=43129) |
273 | 291 |
|
274 | | - client_kwargs: dict[str, object] = { |
275 | | - "server": "local", |
276 | | - "_local_stagehand_binary_path": "/does/not/matter/in/test", |
277 | | - } |
278 | | - if explicit_model_api_key is not None: |
279 | | - client_kwargs["model_api_key"] = explicit_model_api_key |
280 | | - |
281 | | - client = Stagehand(**client_kwargs) |
| 292 | + if explicit_model_api_key is None: |
| 293 | + client = Stagehand( |
| 294 | + server="local", |
| 295 | + _local_stagehand_binary_path="/does/not/matter/in/test", |
| 296 | + ) |
| 297 | + else: |
| 298 | + client = Stagehand( |
| 299 | + server="local", |
| 300 | + model_api_key=explicit_model_api_key, |
| 301 | + _local_stagehand_binary_path="/does/not/matter/in/test", |
| 302 | + ) |
282 | 303 | assert client._sea_server is not None |
283 | 304 |
|
284 | 305 | client._sea_server.ensure_running_sync() |
|
0 commit comments