Files
hermes-agent/tests/tui_gateway/test_gui_surface_toolsets.py
T
Brooklyn Nicholson 7ad9ace2cc fix(agent): the desktop's tools reach it on remote and cloud backends too
The pane, in-app browser, and reaction tools were gated on HERMES_DESKTOP=1 —
an env var set only on backends Electron spawns itself (local and SSH). A
desktop client connected to a plain URL gateway or Hermes Cloud lost all six:
they were stripped from the schema before the model saw them, on the same
backend whose platform hint was telling it "you are chatting inside the Hermes
desktop app". open_preview, read_preview, read_terminal, close_terminal,
focus_pane, and react_to_message were all silently absent.

The client is not the host. Capability now resolves from the session's own
source, which session.create already carries:

- The six tools move into a `desktop_ui` toolset, off _HERMES_CORE_TOOLS so no
  other platform pays their schema.
- _gui_surface_toolsets(platform) folds `desktop_ui` (and the existing
  `project` tools) into the GUI gateway's resolution when the session's
  platform is the desktop app — the same answer on every topology.
- check_fn drops the env probe. It kept the one thing that is genuinely a
  per-process/user fact: react_to_message's display.message_reactions opt-in,
  which the desktop mirrors onto whichever gateway it is connected to.

react_to_message was doubly broken: it read that toggle behind the env gate, so
even a local-backend user's Settings toggle could not reach a remote session.

The embedded terminal pane keeps working correctly the other way round: it runs
`hermes --tui` against a desktop-spawned backend, and a tui-sourced session
gets no GUI tools even though HERMES_DESKTOP=1 is set on that process.
2026-08-06 19:35:47 -06:00

114 lines
4.4 KiB
Python

"""GUI capability follows the SESSION's client, not the backend's process env.
The desktop app is a client. It can drive a backend that Electron spawned
locally, one reached over SSH, one behind a plain URL+token, or Hermes Cloud —
and only the first two run with ``HERMES_DESKTOP=1`` in their environment.
Gating the pane/browser/reaction tools on that env var therefore stripped every
one of them from URL and cloud gateways, while the same backend still told the
model "You are chatting inside the Hermes desktop app".
These tests pin the contract that replaced it: eligibility is resolved from the
session's own ``source`` (``session.create``'s ``source: 'desktop'``), so the
answer is identical on every connection topology.
"""
import pytest
import tui_gateway.server as server
from toolsets import TOOLSETS, resolve_toolset
GUI_TOOLS = {
"close_terminal",
"focus_pane",
"open_preview",
"read_preview",
"read_terminal",
"react_to_message",
}
@pytest.fixture
def no_desktop_env(monkeypatch):
"""A backend nobody told about the desktop — i.e. every remote gateway."""
monkeypatch.delenv("HERMES_DESKTOP", raising=False)
monkeypatch.delenv("HERMES_DESKTOP_TERMINAL", raising=False)
monkeypatch.delenv("HERMES_TUI_TOOLSETS", raising=False)
return monkeypatch
class TestDesktopUiToolset:
def test_holds_exactly_the_gui_affordances(self):
assert set(resolve_toolset("desktop_ui")) == GUI_TOOLS
def test_stays_off_the_core_tool_list(self):
"""Core ships on every API call — a GUI-only tool must not be there."""
from toolsets import _HERMES_CORE_TOOLS
assert GUI_TOOLS.isdisjoint(_HERMES_CORE_TOOLS)
def test_no_platform_bundle_carries_it(self):
"""Messaging/CLI bundles must not pick these up by listing them."""
for name, spec in TOOLSETS.items():
if name == "desktop_ui":
continue
assert GUI_TOOLS.isdisjoint(set(spec.get("tools") or ())), name
class TestSurfaceResolution:
def test_desktop_session_gets_them_with_no_desktop_env(self, no_desktop_env):
"""THE regression: a desktop client on a remote/cloud backend."""
assert "desktop_ui" in server._gui_surface_toolsets("desktop")
def test_tui_session_does_not(self, no_desktop_env):
assert "desktop_ui" not in server._gui_surface_toolsets("tui")
def test_desktop_env_alone_does_not_grant_them(self, no_desktop_env):
"""A desktop-spawned backend serving a TUI session stays clean.
The embedded terminal pane runs `hermes --tui` against this same
backend; env-keyed gating handed it GUI tools it cannot answer.
"""
no_desktop_env.setenv("HERMES_DESKTOP", "1")
assert "desktop_ui" not in server._gui_surface_toolsets("tui")
def test_project_tools_ride_on_every_gui_surface(self, no_desktop_env):
for platform in ("desktop", "tui"):
assert "project" in server._gui_surface_toolsets(platform)
class TestResolverPlumbing:
def test_posture_path_folds_in_the_session_surface(self, no_desktop_env):
"""Focus-mode returns early — the surface toolsets must survive it."""
import agent.coding_context as cc
no_desktop_env.setattr(cc, "coding_selection", lambda **_: ["coding"])
assert server._load_enabled_toolsets("desktop") == [
"coding",
"desktop_ui",
"project",
]
assert server._load_enabled_toolsets("tui") == ["coding", "project"]
def test_config_path_folds_in_the_session_surface(self, no_desktop_env):
import agent.coding_context as cc
import hermes_cli.config as config_mod
no_desktop_env.setattr(cc, "coding_selection", lambda **_: None)
no_desktop_env.setattr(
config_mod, "load_config", lambda: {"platform_toolsets": {"cli": ["memory"]}}
)
desktop = server._load_enabled_toolsets("desktop")
tui = server._load_enabled_toolsets("tui")
assert desktop is not None and tui is not None
assert "desktop_ui" in desktop
assert "desktop_ui" not in tui
def test_explicit_env_pin_still_wins(self, no_desktop_env):
"""HERMES_TUI_TOOLSETS is an operator override; surface can't re-add."""
no_desktop_env.setenv("HERMES_TUI_TOOLSETS", "web,memory")
assert server._load_enabled_toolsets("desktop") == ["web", "memory"]