Files
browser-cli/tests/test_remote_registry.py
T
daniel156161 7b4d96845d
Testing / remote-protocol-compat (0.16.0) (push) Successful in 56s
Testing / remote-protocol-compat (0.15.0) (push) Successful in 1m7s
Testing / test (push) Successful in 1m27s
fix(remote): resolve remembered explicit-port endpoints
- Resolve bare remote hosts through the remote registry when one explicit port is stored.
- Preserve bare host behavior when no unique explicit-port registry match exists.
- Route requested remote targets through the new registry resolver.
- Add registry tests for unique and ambiguous explicit-port matches.
- Bump package and extension versions to 0.16.6.
2026-07-07 00:38:06 +02:00

60 lines
2.5 KiB
Python

import json
from click.testing import CliRunner
from browser_cli.commands.remote import remote_group
from browser_cli.remote import registry as remote_registry
def test_save_remote_persists_endpoint_without_key(monkeypatch, tmp_path):
path = tmp_path / "remotes.json"
monkeypatch.setattr(remote_registry, "REMOTE_REGISTRY_PATH", path)
remote_registry.save_remote("browser-host.example:443")
assert json.loads(path.read_text(encoding="utf-8")) == {"browser-host.example": {}}
def test_save_remote_with_key_and_remove(monkeypatch, tmp_path):
path = tmp_path / "remotes.json"
monkeypatch.setattr(remote_registry, "REMOTE_REGISTRY_PATH", path)
remote_registry.save_remote("browser-host.example", "agent")
assert remote_registry.load_remotes() == {"browser-host.example": {"key": "agent"}}
assert remote_registry.remove_remote("browser-host.example:443") is True
assert remote_registry.load_remotes() == {}
def test_resolve_remote_endpoint_prefers_remembered_explicit_port(monkeypatch, tmp_path):
path = tmp_path / "remotes.json"
monkeypatch.setattr(remote_registry, "REMOTE_REGISTRY_PATH", path)
path.write_text(json.dumps({"browser-host.example": {}, "browser-host.example:8765": {}}), encoding="utf-8")
assert remote_registry.resolve_remote_endpoint("browser-host.example") == "browser-host.example:8765"
def test_resolve_remote_endpoint_keeps_bare_domain_without_unique_port_match(monkeypatch, tmp_path):
path = tmp_path / "remotes.json"
monkeypatch.setattr(remote_registry, "REMOTE_REGISTRY_PATH", path)
path.write_text(
json.dumps({"browser-host.example:8765": {}, "browser-host.example:9000": {}}),
encoding="utf-8",
)
assert remote_registry.resolve_remote_endpoint("browser-host.example") == "browser-host.example"
def test_remote_add_list_remove_cli(monkeypatch, tmp_path):
path = tmp_path / "remotes.json"
monkeypatch.setattr(remote_registry, "REMOTE_REGISTRY_PATH", path)
runner = CliRunner()
add_result = runner.invoke(remote_group, ["add", "browser-host.example", "--key", "agent"])
list_result = runner.invoke(remote_group, ["list"])
remove_result = runner.invoke(remote_group, ["remove", "browser-host.example"])
assert add_result.exit_code == 0
assert "Added remote browser-host.example with key agent" in add_result.output
assert list_result.exit_code == 0
assert "browser-host.example" in list_result.output
assert "agent" in list_result.output
assert remove_result.exit_code == 0
assert "Removed browser-host.example" in remove_result.output
assert remote_registry.load_remotes() == {}