fix remote clients command
This commit is contained in:
+33
-19
@@ -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,29 +213,41 @@ def clients_group(ctx):
|
|||||||
if ctx.invoked_subcommand is not None:
|
if ctx.invoked_subcommand is not None:
|
||||||
return
|
return
|
||||||
|
|
||||||
profiles: dict[str, str] = {}
|
|
||||||
if REGISTRY_PATH.exists():
|
|
||||||
try:
|
|
||||||
profiles = json.loads(REGISTRY_PATH.read_text())
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
all_clients = []
|
all_clients = []
|
||||||
for profile_name, sock_path in profiles.items():
|
|
||||||
display_profile = display_browser_name(profile_name, sock_path)
|
remote = (ctx.obj or {}).get("remote") or os.environ.get("BROWSER_CLI_REMOTE")
|
||||||
|
if remote:
|
||||||
try:
|
try:
|
||||||
result = send_command("clients.list", profile=profile_name)
|
result = send_command("clients.list", profile=(ctx.obj or {}).get("browser"))
|
||||||
for c in (result or []):
|
for c in (result or []):
|
||||||
c["profile"] = display_profile
|
c["profile"] = c.get("profile") or (ctx.obj or {}).get("browser") or "remote"
|
||||||
all_clients.append(c)
|
all_clients.append(c)
|
||||||
except (BrowserNotConnected, RuntimeError):
|
except (BrowserNotConnected, RuntimeError) as e:
|
||||||
# Socket registered but browser no longer connected
|
console.print(f"[red]Error:[/red] {e}")
|
||||||
all_clients.append({
|
sys.exit(1)
|
||||||
"profile": display_profile,
|
else:
|
||||||
"name": "—",
|
profiles: dict[str, str] = {}
|
||||||
"version": "—",
|
if REGISTRY_PATH.exists():
|
||||||
"extensionVersion": "disconnected",
|
try:
|
||||||
})
|
profiles = json.loads(REGISTRY_PATH.read_text())
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for profile_name, sock_path in profiles.items():
|
||||||
|
display_profile = display_browser_name(profile_name, sock_path)
|
||||||
|
try:
|
||||||
|
result = send_command("clients.list", profile=profile_name)
|
||||||
|
for c in (result or []):
|
||||||
|
c["profile"] = display_profile
|
||||||
|
all_clients.append(c)
|
||||||
|
except (BrowserNotConnected, RuntimeError):
|
||||||
|
# Socket registered but browser no longer connected
|
||||||
|
all_clients.append({
|
||||||
|
"profile": display_profile,
|
||||||
|
"name": "—",
|
||||||
|
"version": "—",
|
||||||
|
"extensionVersion": "disconnected",
|
||||||
|
})
|
||||||
|
|
||||||
if not all_clients:
|
if not all_clients:
|
||||||
console.print("[yellow]No browser clients found. Start a browser with the extension enabled first.[/yellow]")
|
console.print("[yellow]No browser clients found. Start a browser with the extension enabled first.[/yellow]")
|
||||||
|
|||||||
@@ -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
@@ -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 = [
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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" },
|
||||||
|
|||||||
Reference in New Issue
Block a user