fix remote clients command
Testing / test (push) Successful in 25s
Package Extension / package-extension (push) Successful in 9s
Build & Publish Package / publish (push) Successful in 21s

This commit is contained in:
2026-04-30 13:49:32 +02:00
parent 6785b9f70c
commit 2f982fa714
5 changed files with 63 additions and 22 deletions
+15 -1
View File
@@ -181,6 +181,8 @@ def main(ctx, browser, remote, token):
ctx.obj["browser_explicit"] = browser is not None ctx.obj["browser_explicit"] = browser is not None
if browser: if browser:
os.environ["BROWSER_CLI_PROFILE"] = browser os.environ["BROWSER_CLI_PROFILE"] = browser
ctx.obj["remote"] = remote
ctx.obj["token"] = token
if remote: if remote:
os.environ["BROWSER_CLI_REMOTE"] = remote os.environ["BROWSER_CLI_REMOTE"] = remote
if token: if token:
@@ -211,6 +213,19 @@ def clients_group(ctx):
if ctx.invoked_subcommand is not None: if ctx.invoked_subcommand is not None:
return return
all_clients = []
remote = (ctx.obj or {}).get("remote") or os.environ.get("BROWSER_CLI_REMOTE")
if remote:
try:
result = send_command("clients.list", profile=(ctx.obj or {}).get("browser"))
for c in (result or []):
c["profile"] = c.get("profile") or (ctx.obj or {}).get("browser") or "remote"
all_clients.append(c)
except (BrowserNotConnected, RuntimeError) as e:
console.print(f"[red]Error:[/red] {e}")
sys.exit(1)
else:
profiles: dict[str, str] = {} profiles: dict[str, str] = {}
if REGISTRY_PATH.exists(): if REGISTRY_PATH.exists():
try: try:
@@ -218,7 +233,6 @@ def clients_group(ctx):
except Exception: except Exception:
pass pass
all_clients = []
for profile_name, sock_path in profiles.items(): for profile_name, sock_path in profiles.items():
display_profile = display_browser_name(profile_name, sock_path) display_profile = display_browser_name(profile_name, sock_path)
try: try:
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "browser-cli", "name": "browser-cli",
"version": "0.7.1", "version": "0.8.1",
"description": "Control your browser from the terminal via browser-cli", "description": "Control your browser from the terminal via browser-cli",
"permissions": [ "permissions": [
"tabs", "tabs",
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "browser-cli" name = "browser-cli"
version = "0.8.0" version = "0.8.1"
description = "Control your real running browser from the terminal via a browser extension" description = "Control your real running browser from the terminal via a browser extension"
requires-python = ">=3.10" requires-python = ">=3.10"
dependencies = [ dependencies = [
+27
View File
@@ -1,5 +1,6 @@
from pathlib import Path from pathlib import Path
from types import SimpleNamespace from types import SimpleNamespace
import os
import sys import sys
from click.testing import CliRunner from click.testing import CliRunner
@@ -140,6 +141,32 @@ def test_clients_exits_cleanly_when_registry_is_missing():
assert result.exit_code == 1 assert result.exit_code == 1
assert "No browser clients found" in result.output assert "No browser clients found" 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"
assert profile is None
return [{"name": "Chrome", "version": "1", "extensionVersion": "2.3.4"}]
with patch.dict(os.environ, {}, clear=True), patch(
"browser_cli.cli.REGISTRY_PATH", Path("/nonexistent/browser-cli-registry.json")
), patch("browser_cli.cli.send_command", side_effect=fake_send_command) as send_command:
result = CliRunner().invoke(main, ["--remote", "127.0.0.1:8765", "--token", "test", "clients"])
assert result.exit_code == 0
send_command.assert_called_once()
assert "remote" in result.output
assert "Chrome" in result.output
assert "2.3.4" in result.output
def test_clients_remote_respects_global_browser_route():
with patch.dict(os.environ, {}, clear=True), patch("browser_cli.cli.send_command", return_value=[]) as send_command:
result = CliRunner().invoke(main, ["--remote", "127.0.0.1:8765", "--browser", "work", "clients"])
assert result.exit_code == 1
send_command.assert_called_once_with("clients.list", profile="work")
def test_clients_shows_named_profile_and_uses_socket_uuid_for_default(tmp_path): def test_clients_shows_named_profile_and_uses_socket_uuid_for_default(tmp_path):
registry_path = tmp_path / "registry.json" registry_path = tmp_path / "registry.json"
default_socket = tmp_path / "550e8400-e29b-41d4-a716-446655440000.sock" default_socket = tmp_path / "550e8400-e29b-41d4-a716-446655440000.sock"
Generated
+1 -1
View File
@@ -4,7 +4,7 @@ requires-python = ">=3.10"
[[package]] [[package]]
name = "browser-cli" name = "browser-cli"
version = "0.8.0" version = "0.8.1"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "click" }, { name = "click" },