hermes-agent/tests/tools/test_focus_pane_tool.py
Brooklyn Nicholson 70ba3c4828 feat(desktop): agent can focus panes + shared desktop-UI event bridge
Extract the open_preview emitter into a shared tools/desktop_ui bridge
(one gateway-injected sink, routed by HERMES_UI_SESSION_ID) and add a
second desktop-gated tool on top of it:

- focus_pane(chat|files|terminal|review|sessions) -> pane.reveal event.
  The desktop runs each pane's own reveal path (revealDesktopPane table)
  and only acts on the active window -- a background turn never moves the
  user's focus (desktop AGENTS.md: offer, don't hijack).

open_preview now emits through the same bridge. Both tools are check_fn
on HERMES_DESKTOP (zero footprint elsewhere), sitting beside
read_terminal/close_terminal in _HERMES_CORE_TOOLS.

Deliberately not adding run_slash: letting the agent fire slash commands
mid-turn (/model, /new, /clear) fights prompt-cache + conversation
invariants.
2026-07-22 12:13:01 -05:00

42 lines
1.1 KiB
Python

"""Tests for the desktop-gated ``focus_pane`` tool."""
import json
import pytest
from tools import desktop_ui, focus_pane_tool as fp
@pytest.fixture(autouse=True)
def _reset_emitter():
desktop_ui.set_emitter(None)
yield
desktop_ui.set_emitter(None)
def test_gated_on_desktop(monkeypatch):
monkeypatch.delenv("HERMES_DESKTOP", raising=False)
assert fp.check_focus_pane_requirements() is False
monkeypatch.setenv("HERMES_DESKTOP", "1")
assert fp.check_focus_pane_requirements() is True
def test_rejects_unknown_pane():
desktop_ui.set_emitter(lambda *a: None)
assert json.loads(fp.focus_pane_tool("banana"))["error"]
def test_desktop_only_without_emitter():
assert "desktop" in json.loads(fp.focus_pane_tool("terminal"))["error"].lower()
@pytest.mark.parametrize("pane", fp.PANES)
def test_emits_pane_reveal(pane):
calls = []
desktop_ui.set_emitter(lambda sid, event, payload: calls.append((event, payload)))
out = json.loads(fp.focus_pane_tool(f" {pane.upper()} "))
assert out == {"success": True, "pane": pane}
assert calls == [("pane.reveal", {"pane": pane})]