add multi browser mode to arragate data from all browsers by tabs list, tabs count, group list, group count and windows list
Package Extension / package-extension (push) Successful in 12s
Build & Publish Package / publish (push) Successful in 22s

remove (unnamed) into the group names just leave it a empty string, remove Focused on windows how should the browser know what windows are focused
This commit is contained in:
2026-04-10 12:49:51 +02:00
parent 6979f2ef30
commit 61b774a7a4
14 changed files with 578 additions and 79 deletions
+120 -2
View File
@@ -4,6 +4,7 @@ from click.testing import CliRunner
from unittest.mock import patch
from browser_cli.cli import main, _project_version
from browser_cli.client import BrowserTarget
def _expected_version() -> str:
pyproject = Path(__file__).resolve().parent.parent / "pyproject.toml"
@@ -50,7 +51,7 @@ def test_install_help_lists_supported_browsers():
assert "[chrome|chromium|brave|edge|vivaldi]" in result.output
def test_clients_exits_cleanly_when_registry_is_missing():
with patch("browser_cli.client.REGISTRY_PATH", Path("/nonexistent/browser-cli-registry.json")):
with patch("browser_cli.cli.REGISTRY_PATH", Path("/nonexistent/browser-cli-registry.json")):
result = CliRunner().invoke(main, ["clients"])
assert result.exit_code == 1
@@ -74,7 +75,7 @@ def test_clients_shows_named_profile_and_uses_socket_uuid_for_default(tmp_path):
assert command == "clients.list"
return responses[profile]
with patch("browser_cli.client.REGISTRY_PATH", registry_path), patch(
with patch("browser_cli.cli.REGISTRY_PATH", registry_path), patch(
"browser_cli.cli.send_command", side_effect=fake_send_command
):
result = CliRunner().invoke(main, ["clients"])
@@ -85,6 +86,123 @@ def test_clients_shows_named_profile_and_uses_socket_uuid_for_default(tmp_path):
assert "Extension Version" in result.output
assert "2.3.4" in result.output
def test_tabs_list_multi_browser_shows_browser_column():
def fake_send_command(command, args=None, profile=None):
assert command == "tabs.list"
return [{"id": 1 if profile == "default" else 2, "windowId": 1, "active": True, "title": profile, "url": "https://example.com"}]
with patch(
"browser_cli.commands.tabs.active_browser_targets",
return_value=[
BrowserTarget("default", "550e8400-e29b-41d4-a716-446655440000", "/tmp/default.sock"),
BrowserTarget("work", "work", "/tmp/work.sock"),
],
), patch("browser_cli.commands.tabs.send_command", side_effect=fake_send_command):
result = CliRunner().invoke(main, ["tabs", "list"])
assert result.exit_code == 0
assert "Browser" in result.output
assert "550e8400-e29b-41d4-a716-446655440000" in result.output
assert "work" in result.output
def test_tabs_list_with_explicit_browser_does_not_show_browser_column():
with patch(
"browser_cli.commands.tabs.active_browser_targets",
return_value=[
BrowserTarget("default", "uuid-1", "/tmp/default.sock"),
BrowserTarget("work", "work", "/tmp/work.sock"),
],
), patch(
"browser_cli.commands.tabs.send_command",
return_value=[{"id": 1, "windowId": 1, "active": True, "title": "Example", "url": "https://example.com"}],
) as send_command:
result = CliRunner().invoke(main, ["--browser", "work", "tabs", "list"])
assert result.exit_code == 0
assert "Browser" not in result.output
send_command.assert_called_once_with("tabs.list", {}, profile=None)
def test_tabs_count_multi_browser_shows_total():
counts = {"default": 3, "work": 4}
def fake_send_command(command, args=None, profile=None):
assert command == "tabs.count"
assert args == {"pattern": "github"}
return counts[profile]
with patch(
"browser_cli.commands.tabs.active_browser_targets",
return_value=[
BrowserTarget("default", "uuid-1", "/tmp/default.sock"),
BrowserTarget("work", "work", "/tmp/work.sock"),
],
), patch("browser_cli.commands.tabs.send_command", side_effect=fake_send_command):
result = CliRunner().invoke(main, ["tabs", "count", "github"])
assert result.exit_code == 0
assert "Browser" in result.output
assert "Total" in result.output
assert "7" in result.output
def test_group_count_multi_browser_shows_total():
counts = {"default": 1, "work": 2}
def fake_send_command(command, args=None, profile=None):
assert command == "group.count"
return counts[profile]
with patch(
"browser_cli.commands.groups.active_browser_targets",
return_value=[
BrowserTarget("default", "uuid-1", "/tmp/default.sock"),
BrowserTarget("work", "work", "/tmp/work.sock"),
],
), patch("browser_cli.commands.groups.send_command", side_effect=fake_send_command):
result = CliRunner().invoke(main, ["group", "count"])
assert result.exit_code == 0
assert "Browser" in result.output
assert "Total" in result.output
assert "3" in result.output
def test_group_list_leaves_unnamed_group_cell_empty():
with patch(
"browser_cli.commands.groups.send_command",
return_value=[{"id": 42, "title": "", "color": "grey", "collapsed": False, "tabCount": 1}],
):
result = CliRunner().invoke(main, ["group", "list"])
assert result.exit_code == 0
assert "(unnamed)" not in result.output
assert "42" in result.output
assert "grey" in result.output
def test_windows_list_multi_browser_shows_browser_column():
def fake_send_command(command, args=None, profile=None):
assert command == "windows.list"
return [{"id": 1, "alias": profile, "focused": True, "tabCount": 2, "state": "normal"}]
with patch(
"browser_cli.commands.windows.active_browser_targets",
return_value=[
BrowserTarget("default", "uuid-1", "/tmp/default.sock"),
BrowserTarget("work", "work", "/tmp/work.sock"),
],
), patch("browser_cli.commands.windows.send_command", side_effect=fake_send_command):
result = CliRunner().invoke(main, ["windows", "list"])
assert result.exit_code == 0
assert "Browser" in result.output
assert "Focused" not in result.output
assert "uuid-1" in result.output
assert "work" 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"])