fix that the cli still used the DEFAULT_SOCKET Const, give better error message when no browser found adding test for client and update cli test, and update version and readme
Package Extension / package-extension (push) Failing after 53s
Build & Publish Package / publish (push) Successful in 39s

This commit is contained in:
2026-04-10 02:14:59 +02:00
parent 147d1d4ca3
commit f18d2d5536
6 changed files with 59 additions and 11 deletions
+40
View File
@@ -0,0 +1,40 @@
import json
from pathlib import Path
import pytest
from browser_cli.client import BrowserNotConnected, _resolve_socket
def test_resolve_socket_raises_when_registry_missing(monkeypatch):
monkeypatch.delenv("BROWSER_CLI_PROFILE", raising=False)
monkeypatch.setattr("browser_cli.client.REGISTRY_PATH", Path("/nonexistent/browser-cli-registry.json"))
with pytest.raises(BrowserNotConnected, match="Cannot resolve a browser socket automatically"):
_resolve_socket()
def test_resolve_socket_uses_only_active_registry_entry(monkeypatch, tmp_path):
monkeypatch.delenv("BROWSER_CLI_PROFILE", raising=False)
socket_path = tmp_path / "browser.sock"
socket_path.write_text("")
registry_path = tmp_path / "registry.json"
registry_path.write_text(json.dumps({"abc-uuid": str(socket_path)}))
monkeypatch.setattr("browser_cli.client.REGISTRY_PATH", registry_path)
assert _resolve_socket() == str(socket_path)
def test_resolve_socket_raises_when_multiple_active_entries(monkeypatch, tmp_path):
monkeypatch.delenv("BROWSER_CLI_PROFILE", raising=False)
first_socket = tmp_path / "one.sock"
second_socket = tmp_path / "two.sock"
first_socket.write_text("")
second_socket.write_text("")
registry_path = tmp_path / "registry.json"
registry_path.write_text(json.dumps({"uuid-1": str(first_socket), "uuid-2": str(second_socket)}))
monkeypatch.setattr("browser_cli.client.REGISTRY_PATH", registry_path)
with pytest.raises(BrowserNotConnected, match="Multiple browser instances are active: uuid-1, uuid-2"):
_resolve_socket()