fix: prefer active local browser profiles
Testing / remote-protocol-compat (0.9.3) (push) Successful in 30s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 29s
Package Extension / package-extension (push) Successful in 29s
Build & Publish Package / publish (push) Successful in 33s
Testing / test (push) Successful in 25s
Testing / remote-protocol-compat (0.9.3) (push) Successful in 30s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 29s
Package Extension / package-extension (push) Successful in 29s
Build & Publish Package / publish (push) Successful in 33s
Testing / test (push) Successful in 25s
- Avoid resolving a saved remote alias when the requested profile is currently reachable as a local endpoint. - Add a helper that checks the registry and local socket path before remote alias discovery. - Cover the routing precedence with a client unit test. - Bump package and extension versions to 0.10.1.
This commit is contained in:
@@ -117,6 +117,50 @@ def test_send_command_auto_routes_single_remote_target(monkeypatch):
|
||||
assert "token" not in sent
|
||||
|
||||
|
||||
def test_send_command_prefers_active_local_profile_over_saved_remote_alias(monkeypatch, tmp_path):
|
||||
monkeypatch.delenv("BROWSER_CLI_REMOTE", raising=False)
|
||||
monkeypatch.delenv("BROWSER_CLI_PROFILE", raising=False)
|
||||
socket_path = tmp_path / "work.sock"
|
||||
socket_path.write_text("")
|
||||
registry_path = tmp_path / "registry.json"
|
||||
registry_path.write_text(json.dumps({"work": str(socket_path)}), encoding="utf-8")
|
||||
monkeypatch.setattr("browser_cli.client.REGISTRY_PATH", registry_path)
|
||||
monkeypatch.setattr(
|
||||
"browser_cli.client.remote_target_for_alias",
|
||||
lambda alias: pytest.fail("active local profile must not trigger remote alias discovery"),
|
||||
)
|
||||
|
||||
payload = json.dumps({"success": True, "data": "local-ok"}).encode("utf-8")
|
||||
framed = len(payload).to_bytes(4, "little") + payload
|
||||
|
||||
class FakeSocket:
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.sent = b""
|
||||
self._response = bytearray(framed)
|
||||
self.connected_to = None
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc):
|
||||
return False
|
||||
|
||||
def connect(self, path):
|
||||
self.connected_to = path
|
||||
|
||||
def sendall(self, data):
|
||||
self.sent += data
|
||||
|
||||
def recv(self, n):
|
||||
chunk = bytes(self._response[:n])
|
||||
del self._response[:n]
|
||||
return chunk
|
||||
|
||||
monkeypatch.setattr("browser_cli.client.socket.socket", lambda *args, **kwargs: FakeSocket())
|
||||
|
||||
assert send_command("tabs.list", profile="work") == "local-ok"
|
||||
|
||||
|
||||
def test_send_command_resolves_browser_alias_to_remote_target(monkeypatch):
|
||||
monkeypatch.delenv("BROWSER_CLI_REMOTE", raising=False)
|
||||
monkeypatch.setenv("BROWSER_CLI_PROFILE", "host:work")
|
||||
|
||||
Reference in New Issue
Block a user