allow to rename the profile without a browser restart and remove old sockets and registry entry when browser closes
Build & Publish Package / publish (push) Successful in 27s
Package Extension / package-extension (push) Failing after 10m17s

This commit is contained in:
2026-04-10 12:02:14 +02:00
parent c9ecde9338
commit 6979f2ef30
9 changed files with 135 additions and 13 deletions
+1
View File
@@ -41,6 +41,7 @@ def test_rename_profile_uses_global_browser_target_when_set():
assert result.exit_code == 0
send_command.assert_called_once_with("clients.rename_profile", {"alias": "work"}, profile=None)
assert "Restart the browser" not in result.output
def test_install_help_lists_supported_browsers():
result = CliRunner().invoke(main, ["install", "--help"])
+73
View File
@@ -0,0 +1,73 @@
import json
from pathlib import Path
from types import SimpleNamespace
import pytest
import browser_cli.native_host as native_host
def _raise_system_exit(code: int):
raise SystemExit(code)
def test_cleanup_removes_socket_and_registry_entry(monkeypatch, tmp_path):
alias = "work"
socket_path = tmp_path / "work.sock"
socket_path.write_text("")
registry_path = tmp_path / "registry.json"
registry_path.write_text(json.dumps({alias: str(socket_path), "other": str(tmp_path / "other.sock")}))
monkeypatch.setattr(native_host, "SOCKET_DIR", tmp_path)
monkeypatch.setattr(native_host, "REGISTRY_PATH", registry_path)
native_host._cleanup(alias)
assert not socket_path.exists()
assert json.loads(registry_path.read_text()) == {"other": str(tmp_path / "other.sock")}
def test_stdin_reader_cleans_up_on_eof(monkeypatch):
cleaned = []
monkeypatch.setattr(native_host, "read_native_message", lambda stream: None)
monkeypatch.setattr(native_host, "_cleanup", cleaned.append)
monkeypatch.setattr(native_host.os, "_exit", _raise_system_exit)
monkeypatch.setattr(native_host.sys, "stdin", SimpleNamespace(buffer=object()))
with pytest.raises(SystemExit, match="0"):
native_host.stdin_reader("work")
assert cleaned == ["work"]
def test_stdin_reader_cleans_up_on_bye(monkeypatch):
cleaned = []
messages = iter([{"type": "bye"}])
monkeypatch.setattr(native_host, "read_native_message", lambda stream: next(messages))
monkeypatch.setattr(native_host, "_cleanup", cleaned.append)
monkeypatch.setattr(native_host.os, "_exit", _raise_system_exit)
monkeypatch.setattr(native_host.sys, "stdin", SimpleNamespace(buffer=object()))
with pytest.raises(SystemExit, match="0"):
native_host.stdin_reader("work")
assert cleaned == ["work"]
def test_stdin_reader_routes_response_messages(monkeypatch):
response_queue = native_host.queue.Queue()
native_host.PENDING["msg-1"] = response_queue
messages = iter([{"type": "hello"}, {"id": "msg-1", "success": True}, None])
monkeypatch.setattr(native_host, "read_native_message", lambda stream: next(messages))
monkeypatch.setattr(native_host, "_cleanup", lambda alias: None)
monkeypatch.setattr(native_host.os, "_exit", _raise_system_exit)
monkeypatch.setattr(native_host.sys, "stdin", SimpleNamespace(buffer=object()))
with pytest.raises(SystemExit, match="0"):
native_host.stdin_reader("work")
assert response_queue.get_nowait() == {"id": "msg-1", "success": True}
native_host.PENDING.clear()