feat: improve remote browser tree routing
Testing / remote-protocol-compat (0.9.3) (push) Successful in 43s
Testing / test (push) Successful in 1m1s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 39s
Build & Publish Package / publish (push) Successful in 58s
Package Extension / package-extension (push) Successful in 1m15s
Testing / remote-protocol-compat (0.9.3) (push) Successful in 43s
Testing / test (push) Successful in 1m1s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 39s
Build & Publish Package / publish (push) Successful in 58s
Package Extension / package-extension (push) Successful in 1m15s
- Allow remote host aliases passed via --browser to fan out for read-only multi-browser SDK paths while preserving strict routing for mutating commands. - Add remote host grouping and scoped profile labels to tabs tree output so global views avoid repeated host prefixes. - Carry browser family metadata through remote targets, tabs, and groups and style tree browser labels by family. - Split CLI rendering helpers into a typed rendering package with dedicated common, label, tabs-tree, and windows-tree modules. - Bump browser-cli and extension versions to 0.15.5. - Cover the new routing and rendering behavior with unit and CLI tests.
This commit is contained in:
+29
-3
@@ -5,15 +5,26 @@ from rich.tree import Tree
|
||||
|
||||
from browser_cli.models import Tab
|
||||
from browser_cli.commands import rendering
|
||||
from browser_cli.commands.rendering import common
|
||||
|
||||
def test_shorten_uses_ellipsis():
|
||||
assert rendering.shorten("abcdef", 4) == "abc…"
|
||||
assert rendering.shorten("abc", 4) == "abc"
|
||||
|
||||
def test_terminal_width_prefers_shell_width_when_rich_is_redirected(monkeypatch):
|
||||
monkeypatch.setattr(rendering.shutil, "get_terminal_size", lambda fallback: terminal_size((140, 20)))
|
||||
monkeypatch.setattr(common.shutil, "get_terminal_size", lambda fallback: terminal_size((140, 20)))
|
||||
assert rendering.terminal_width(Console(width=80)) == 140
|
||||
|
||||
def test_browser_label_style_distinguishes_browser_families():
|
||||
assert rendering.browser_label_style("Firefox") == "orange1"
|
||||
assert rendering.browser_label_style("Chrome") == "cyan"
|
||||
assert rendering.browser_label_style(None) == "bold cyan"
|
||||
|
||||
def test_scoped_browser_label_strips_repeated_remote_prefix():
|
||||
assert rendering.scoped_browser_label("browser-host.example:work", "browser-host.example", grouped=True) == "work"
|
||||
assert rendering.scoped_browser_label("work", "browser-host.example", grouped=True) == "work"
|
||||
assert rendering.scoped_browser_label("browser-host.example:work", "browser-host.example", grouped=False) == "browser-host.example:work"
|
||||
|
||||
def test_tab_tree_label_is_reusable_no_wrap_text():
|
||||
tab = type("Tab", (), {"id": 1, "title": "abcdef", "active": True, "url": "https://example.com"})()
|
||||
label = rendering.tab_tree_label(tab, title_limit=4, show_urls=True, url_limit=12)
|
||||
@@ -29,8 +40,8 @@ def test_print_tree_uses_detected_width(monkeypatch):
|
||||
widths.append(kwargs.get("width"))
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
monkeypatch.setattr(rendering, "Console", CapturingConsole)
|
||||
monkeypatch.setattr(rendering, "terminal_width", lambda console=None: 132)
|
||||
monkeypatch.setattr(common, "Console", CapturingConsole)
|
||||
monkeypatch.setattr(common, "terminal_width", lambda console=None: 132)
|
||||
rendering.print_tree(Tree("Root"))
|
||||
assert widths == [132]
|
||||
|
||||
@@ -48,6 +59,21 @@ def test_build_tabs_tree_groups_by_browser_window_and_group():
|
||||
assert "collapsed" in text
|
||||
assert "Inside" in text
|
||||
|
||||
def test_build_tabs_tree_groups_remote_browsers_by_scope():
|
||||
tabs = [
|
||||
Tab(id=1, window_id=5, active=False, muted=False, title="Remote A", url="https://example.com/a", index=0, browser="main", browser_group="browser-host.example"),
|
||||
Tab(id=2, window_id=6, active=False, muted=False, title="Remote B", url="https://example.com/b", index=0, browser="work", browser_group="browser-host.example"),
|
||||
Tab(id=3, window_id=7, active=False, muted=False, title="Local", url="https://example.com/local", index=0, browser="local"),
|
||||
]
|
||||
tree = rendering.build_tabs_tree(tabs, [], console=Console(width=120))
|
||||
text = "\n".join(str(line) for line in tree.__rich_console__(Console(width=120), Console(width=120).options))
|
||||
assert "browser-host.example" in text
|
||||
assert "main" in text
|
||||
assert "work" in text
|
||||
assert "browser-host.example:main" not in text
|
||||
assert "browser-host.example:work" not in text
|
||||
assert "Local" in text
|
||||
|
||||
def test_build_windows_tree_keeps_multi_browser_windows_separate():
|
||||
tabs = [
|
||||
Tab(id=1, window_id=5, active=False, muted=False, title="Work Tab", url="https://example.com/work", index=0, browser="work"),
|
||||
|
||||
Reference in New Issue
Block a user