make remote browser listing more simpler when giving --browser ip only shows remote browsers
Testing / test (push) Successful in 22s
Testing / test (push) Successful in 22s
This commit is contained in:
+27
-3
@@ -31,6 +31,8 @@ from browser_cli.client import (
|
|||||||
active_browser_targets,
|
active_browser_targets,
|
||||||
display_browser_name,
|
display_browser_name,
|
||||||
save_remote_token,
|
save_remote_token,
|
||||||
|
remote_target_for_alias,
|
||||||
|
remote_browser_targets,
|
||||||
)
|
)
|
||||||
from browser_cli.platform import install_base_dir, is_windows
|
from browser_cli.platform import install_base_dir, is_windows
|
||||||
from browser_cli.registry import load_registry
|
from browser_cli.registry import load_registry
|
||||||
@@ -242,12 +244,34 @@ def clients_group(ctx):
|
|||||||
|
|
||||||
all_clients = []
|
all_clients = []
|
||||||
|
|
||||||
|
browser_alias = (ctx.obj or {}).get("browser")
|
||||||
remote = (ctx.obj or {}).get("remote") or os.environ.get("BROWSER_CLI_REMOTE")
|
remote = (ctx.obj or {}).get("remote") or os.environ.get("BROWSER_CLI_REMOTE")
|
||||||
if remote:
|
token = (ctx.obj or {}).get("token") or os.environ.get("BROWSER_CLI_TOKEN")
|
||||||
|
|
||||||
|
if not remote and browser_alias:
|
||||||
|
# --browser <host> without --remote: resolve host alias to a remote endpoint,
|
||||||
|
# then show ALL clients from that remote (not just the one resolved profile).
|
||||||
|
resolved = remote_target_for_alias(browser_alias)
|
||||||
|
if resolved:
|
||||||
|
resolved_token = token or resolved.token
|
||||||
|
try:
|
||||||
|
targets = remote_browser_targets(resolved.remote, resolved_token)
|
||||||
|
except (BrowserNotConnected, RuntimeError) as e:
|
||||||
|
console.print(f"[red]Error:[/red] {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
for target in targets:
|
||||||
|
try:
|
||||||
|
result = send_command("clients.list", profile=target.profile, remote=resolved.remote, token=resolved_token)
|
||||||
|
for c in (result or []):
|
||||||
|
c["profile"] = target.display_name
|
||||||
|
all_clients.append(c)
|
||||||
|
except (BrowserNotConnected, RuntimeError):
|
||||||
|
continue
|
||||||
|
elif remote:
|
||||||
try:
|
try:
|
||||||
result = send_command("clients.list", profile=(ctx.obj or {}).get("browser"))
|
result = send_command("clients.list", profile=browser_alias, remote=remote, token=token)
|
||||||
for c in (result or []):
|
for c in (result or []):
|
||||||
c["profile"] = c.get("profile") or (ctx.obj or {}).get("browser") or "remote"
|
c["profile"] = c.get("profile") or browser_alias or "remote"
|
||||||
all_clients.append(c)
|
all_clients.append(c)
|
||||||
except (BrowserNotConnected, RuntimeError) as e:
|
except (BrowserNotConnected, RuntimeError) as e:
|
||||||
console.print(f"[red]Error:[/red] {e}")
|
console.print(f"[red]Error:[/red] {e}")
|
||||||
|
|||||||
+38
-2
@@ -168,9 +168,11 @@ def test_clients_reads_registry_with_trailing_garbage(tmp_path):
|
|||||||
assert "0.8.2" in result.output
|
assert "0.8.2" in result.output
|
||||||
|
|
||||||
def test_clients_remote_uses_remote_endpoint_without_local_registry():
|
def test_clients_remote_uses_remote_endpoint_without_local_registry():
|
||||||
def fake_send_command(command, args=None, profile=None):
|
def fake_send_command(command, args=None, profile=None, remote=None, token=None):
|
||||||
assert command == "clients.list"
|
assert command == "clients.list"
|
||||||
assert profile is None
|
assert profile is None
|
||||||
|
assert remote == "127.0.0.1:8765"
|
||||||
|
assert token == "test"
|
||||||
return [{"name": "Chrome", "version": "1", "extensionVersion": "2.3.4"}]
|
return [{"name": "Chrome", "version": "1", "extensionVersion": "2.3.4"}]
|
||||||
|
|
||||||
with patch.dict(os.environ, {}, clear=True), patch(
|
with patch.dict(os.environ, {}, clear=True), patch(
|
||||||
@@ -192,7 +194,41 @@ def test_clients_remote_respects_global_browser_route():
|
|||||||
result = CliRunner().invoke(main, ["--remote", "127.0.0.1:8765", "--browser", "work", "clients"])
|
result = CliRunner().invoke(main, ["--remote", "127.0.0.1:8765", "--browser", "work", "clients"])
|
||||||
|
|
||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
send_command.assert_called_once_with("clients.list", profile="work")
|
send_command.assert_called_once_with("clients.list", profile="work", remote="127.0.0.1:8765", token=None)
|
||||||
|
|
||||||
|
|
||||||
|
def test_clients_browser_alias_resolves_to_remote():
|
||||||
|
"""--browser <host> without --remote resolves the alias, fetches all targets from that remote,
|
||||||
|
and shows only clients from that host (not local profiles)."""
|
||||||
|
from browser_cli.client import BrowserTarget
|
||||||
|
|
||||||
|
resolved_target = BrowserTarget(
|
||||||
|
profile="automatisation",
|
||||||
|
display_name="192.168.188.104:automatisation",
|
||||||
|
socket_path="",
|
||||||
|
remote="192.168.188.104:8765",
|
||||||
|
token="tok",
|
||||||
|
)
|
||||||
|
all_remote_targets = [resolved_target]
|
||||||
|
|
||||||
|
def fake_send_command(command, args=None, profile=None, remote=None, token=None):
|
||||||
|
assert command == "clients.list"
|
||||||
|
assert profile == "automatisation"
|
||||||
|
assert remote == "192.168.188.104:8765"
|
||||||
|
assert token == "tok"
|
||||||
|
return [{"name": "Chrome", "version": "147.0.0.0", "extensionVersion": "0.8.5"}]
|
||||||
|
|
||||||
|
with patch.dict(os.environ, {}, clear=True), patch(
|
||||||
|
"browser_cli.cli.remote_target_for_alias", return_value=resolved_target
|
||||||
|
), patch(
|
||||||
|
"browser_cli.cli.remote_browser_targets", return_value=all_remote_targets
|
||||||
|
), patch("browser_cli.cli.send_command", side_effect=fake_send_command) as send_command:
|
||||||
|
result = CliRunner().invoke(main, ["--browser", "192.168.188.104", "clients"])
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
send_command.assert_called_once()
|
||||||
|
assert "Chrome" in result.output
|
||||||
|
assert "0.8.5" in result.output
|
||||||
|
|
||||||
|
|
||||||
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):
|
||||||
|
|||||||
Reference in New Issue
Block a user