move registry into own files

This commit is contained in:
2026-05-01 19:30:09 +02:00
parent 7ee664153b
commit d904f4ca63
6 changed files with 158 additions and 22 deletions
+19
View File
@@ -141,6 +141,25 @@ def test_clients_exits_cleanly_when_registry_is_missing():
assert result.exit_code == 1
assert "No browser clients found" in result.output
def test_clients_reads_registry_with_trailing_garbage(tmp_path):
registry_path = tmp_path / "registry.json"
registry_path.write_text('{"main": "/tmp/.browser_cli/main.sock"}"}', encoding="utf-8")
def fake_send_command(command, args=None, profile=None):
assert command == "clients.list"
assert profile == "main"
return [{"profile": "main", "name": "Chrome", "version": "1", "extensionVersion": "0.8.2"}]
with patch("browser_cli.cli.REGISTRY_PATH", registry_path), patch(
"browser_cli.cli.send_command", side_effect=fake_send_command
):
result = CliRunner().invoke(main, ["clients"])
assert result.exit_code == 0
assert "main" in result.output
assert "0.8.2" in result.output
def test_clients_remote_uses_remote_endpoint_without_local_registry():
def fake_send_command(command, args=None, profile=None):
assert command == "clients.list"
+30
View File
@@ -0,0 +1,30 @@
import json
from browser_cli.registry import load_registry, save_registry, update_registry
def test_load_registry_tolerates_trailing_garbage_from_old_non_atomic_writes(tmp_path):
registry = tmp_path / "registry.json"
registry.write_text('{"main": "/tmp/.browser_cli/main.sock"}"}', encoding="utf-8")
assert load_registry(registry) == {"main": "/tmp/.browser_cli/main.sock"}
def test_update_registry_repairs_corrupted_registry_and_preserves_entries(tmp_path):
registry = tmp_path / "registry.json"
registry.write_text('{"main": "/tmp/.browser_cli/main.sock"}"}', encoding="utf-8")
update_registry("work", "/tmp/.browser_cli/work.sock", registry)
assert json.loads(registry.read_text(encoding="utf-8")) == {
"main": "/tmp/.browser_cli/main.sock",
"work": "/tmp/.browser_cli/work.sock",
}
def test_save_registry_writes_valid_json_atomically(tmp_path):
registry = tmp_path / "registry.json"
save_registry({"main": "/tmp/main.sock"}, registry)
assert json.loads(registry.read_text(encoding="utf-8")) == {"main": "/tmp/main.sock"}