diff --git a/browser_cli/cli.py b/browser_cli/cli.py index 8372cb6..3ffdcb4 100755 --- a/browser_cli/cli.py +++ b/browser_cli/cli.py @@ -86,6 +86,12 @@ def _print_version(ctx, param, value): ctx.exit() +def _client_display_profile(profile_name: str, sock_path: str) -> str: + if profile_name != "default": + return profile_name + return Path(sock_path).stem or profile_name + + @click.group() @click.option( "-V", "--version", @@ -136,14 +142,20 @@ def cmd_clients(): all_clients = [] for profile_name, sock_path in profiles.items(): + display_profile = _client_display_profile(profile_name, sock_path) try: result = send_command("clients.list", profile=profile_name) for c in (result or []): - c.setdefault("profile", profile_name) + c["profile"] = display_profile all_clients.append(c) except (BrowserNotConnected, RuntimeError): # Socket registered but browser no longer connected - all_clients.append({"profile": profile_name, "name": "—", "version": "—", "platform": "disconnected"}) + all_clients.append({ + "profile": display_profile, + "name": "—", + "version": "—", + "extensionVersion": "disconnected", + }) if not all_clients: console.print("[yellow]No browser clients found. Start a browser with the extension enabled first.[/yellow]") @@ -154,9 +166,14 @@ def cmd_clients(): table.add_column("Profile") table.add_column("Browser") table.add_column("Version") - table.add_column("Platform") + table.add_column("Extension Version") for c in all_clients: - table.add_row(c.get("profile", ""), c.get("name", ""), c.get("version", ""), c.get("platform", "")) + table.add_row( + c.get("profile", ""), + c.get("name", ""), + c.get("version", ""), + c.get("extensionVersion", ""), + ) console.print(table) diff --git a/extension/manifest.json b/extension/manifest.json index 8edaadb..56ecdc5 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "browser-cli", - "version": "0.5.0", + "version": "0.5.1", "description": "Control your browser from the terminal via browser-cli", "permissions": [ "tabs", diff --git a/pyproject.toml b/pyproject.toml index 6724caf..113d7fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "browser-cli" -version = "0.5.0" +version = "0.5.1" description = "Control your real running browser from the terminal via a Chrome extension" requires-python = ">=3.10" dependencies = [ diff --git a/tests/test_cli.py b/tests/test_cli.py index 0485378..ed4401e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -55,6 +55,35 @@ def test_clients_exits_cleanly_when_registry_is_missing(): assert result.exit_code == 1 assert "No browser clients found" in result.output +def test_clients_shows_named_profile_and_uses_socket_uuid_for_default(tmp_path): + registry_path = tmp_path / "registry.json" + default_socket = tmp_path / "550e8400-e29b-41d4-a716-446655440000.sock" + work_socket = tmp_path / "work.sock" + registry_path.write_text( + '{"default": "%s", "work": "%s"}' % (default_socket, work_socket), + encoding="utf-8", + ) + + responses = { + "default": [{"profile": "default", "name": "Chrome", "version": "1", "extensionVersion": "2.3.4"}], + "work": [{"profile": "default", "name": "Chrome", "version": "1", "extensionVersion": "2.3.4"}], + } + + def fake_send_command(command, args=None, profile=None): + assert command == "clients.list" + return responses[profile] + + with patch("browser_cli.client.REGISTRY_PATH", registry_path), patch( + "browser_cli.cli.send_command", side_effect=fake_send_command + ): + result = CliRunner().invoke(main, ["clients"]) + + assert result.exit_code == 0 + assert "550e8400-e29b-41d4-a716-446655440000" in result.output + assert "work" in result.output + assert "Extension Version" in result.output + assert "2.3.4" in result.output + def test_extract_markdown_command(): with patch("browser_cli.commands.extract.send_command", return_value="# Title\n") as send_command: result = CliRunner().invoke(main, ["extract", "markdown"]) diff --git a/uv.lock b/uv.lock index 048b7ac..5ae21ee 100644 --- a/uv.lock +++ b/uv.lock @@ -4,7 +4,7 @@ requires-python = ">=3.10" [[package]] name = "browser-cli" -version = "0.4.1" +version = "0.5.1" source = { editable = "." } dependencies = [ { name = "click" },