Files
hermes-agent/tests/tools/test_read_preview_tool.py
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

66 lines
2.0 KiB
Python

"""Tests for the GUI-surface ``read_preview`` tool."""
import json
from tools import read_preview_tool as rp
from tools.registry import registry
def test_lives_in_the_gui_surface_toolset(monkeypatch):
"""Mirrors read_terminal: scoped by toolset, not by the backend's env."""
monkeypatch.delenv("HERMES_DESKTOP", raising=False)
entry = registry.get_entry("read_preview")
assert entry is not None
assert entry.toolset == "desktop_ui"
assert entry.check_fn is None
def test_requires_callback():
"""Outside the desktop GUI there is no bridge — a clear error, no crash."""
result = json.loads(rp.read_preview_tool(callback=None))
assert "desktop" in result["error"]
def test_empty_answer_means_nothing_open():
result = json.loads(rp.read_preview_tool(callback=lambda **_: ""))
assert "error" in result
def test_passes_json_through():
payload = {"kind": "url", "url": "https://news.ycombinator.com", "title": "HN", "text": "hello"}
result = json.loads(rp.read_preview_tool(callback=lambda **_: json.dumps(payload)))
assert result == payload
def test_wraps_non_json_text():
result = json.loads(rp.read_preview_tool(callback=lambda **_: "plain words"))
assert result == {"text": "plain words"}
def test_window_forwarded_and_validated():
seen = {}
def cb(**kwargs):
seen.update(kwargs)
return json.dumps({"kind": "url"})
rp.read_preview_tool(start=100, count=500, callback=cb)
assert seen == {"start": 100, "count": 500}
# Floors mirror read_terminal: start >= 0, count >= 1.
seen.clear()
rp.read_preview_tool(start=-5, count=0, callback=cb)
assert seen == {"start": 0, "count": 1}
result = json.loads(rp.read_preview_tool(start="lots", callback=cb))
assert "integers" in result["error"]
def test_callback_failure_is_reported():
def _boom(**_kwargs):
raise RuntimeError("renderer went away")
result = json.loads(rp.read_preview_tool(callback=_boom))
assert "renderer went away" in result["error"]