Files
hermes-agent/tests/agent/test_platform_hint_desktop.py
Teknium 2a95791992 simplify(compat): run_agent/model_tools/toolsets/acp/providers — drop 42 re-exports/aliases, repoint 15 callers + 99 test files
run_agent.py: delete the `# noqa: F401` re-export block (agent.process_bootstrap
OpenAI/_SafeWriter/_get_proxy_*, model_tools get_tool_definitions/
handle_function_call/check_toolset_requirements, FailoverReason,
_qwen_portal_headers/_routermint_headers, session_persistence names,
estimate_request_tokens_rough, ContextCompressor + friends, jittered_backoff,
prompt_builder names, message_sanitization names, tool_dispatch_helpers
names) — 41 names run_agent never used itself — and the `_STREAM_DIAG_HEADERS`
back-compat class alias (no in-tree reader). run_agent now imports only what
it uses (get_toolset_for_tool, is_local_endpoint, coalesce/uniquify tool-call
ids, cleanup_vm/get_active_env from terminal_tool_lifecycle).

agent/*: `_ra().X` late-binds that only reached a re-export now import the
defining module directly (agent_runtime_helpers -> process_bootstrap.OpenAI,
model_tools.handle_function_call, session_persistence._safe_session_filename_component;
agent_init -> model_tools.get_tool_definitions/check_toolset_requirements,
_lazy_headers("agent.client_lifecycle", ...) for qwen/routermint;
system_prompt -> agent.prompt_builder / model_tools directly, dropping its
own _ra() shim and the `_r` parameter threading). `_ra()` stays for
run_agent-resident names (logger, AIAgent, _hermes_home, _set_interrupt, ...).

toolsets.py: remove resolve_multiple_toolsets (shim-only, restored by
34abf954bd); tests/test_toolsets.py pins the same union behavior via
resolve_toolset over each name.

providers/__init__.py: drop the OMIT_TEMPERATURE re-export (no callers via the
package); ProviderProfile stays because __init__ uses it for annotations —
2 tests repointed to providers.base.

agent/iteration_budget.py: drop the "run_agent re-exports the class"
docstring pointer; 4 tests import IterationBudget from its home.

model_tools.py (arg_coercion names), agent/tool_executor.py, and
hermes_cli/cli_session_mixin.py repoints landed via a sibling commit on this
shared worktree.

Callers repointed: gateway/run.py, hermes_cli/cli_chat_turn_mixin.py,
hermes_cli/cli_tui_mixin.py, tui_gateway/session_workdir.py,
agent/transports/codex.py (one-line imports) + comment pointers in
tools/file_state.py, tools/schema_sanitizer.py, scripts/tool_search_livetest.py.
Tests: patch("run_agent.X") / monkeypatch.setattr(run_agent, "X") /
`from run_agent import X` -> defining module across 99 test files.
2026-09-03 13:28:22 -07:00

179 lines
7.2 KiB
Python

"""System-prompt assembly for the desktop chat surface.
Pins the second half of the fix: the new ``PLATFORM_HINTS["desktop"]``
entry, the deletion of the standalone desktop-hint block from
``build_environment_hints()``, and the lookup-site extension that
appends the embedded-terminal-pane clarifier to the ``tui`` platform hint
when ``HERMES_DESKTOP_TERMINAL=1``.
These tests run against the real prompt builders (no mocks) because
cache-stability and byte-for-byte text contracts are what we are
verifying — mocking the resolver would hide exactly the class of bug
this test covers.
"""
from types import SimpleNamespace
from unittest.mock import patch
import pytest
from agent.prompt_builder import PLATFORM_HINTS, build_environment_hints
from agent.system_prompt import (
_tui_embedded_pane_clarifier,
build_system_prompt_parts,
)
def _stable_prompt(agent):
with (
patch("agent.prompt_builder.load_soul_md", return_value=""),
patch("agent.prompt_builder.build_environment_hints", return_value=""),
patch("agent.prompt_builder.build_context_files_prompt", return_value=""),
):
return build_system_prompt_parts(agent)["stable"]
def _make_agent(platform="", **overrides):
base = dict(
load_soul_identity=False,
skip_context_files=False,
valid_tool_names=[],
_task_completion_guidance=False,
_tool_use_enforcement=False,
_environment_probe=False,
_kanban_worker_guidance="",
_memory_store=None,
_memory_manager=None,
_platform_hint_overrides={},
model="",
provider="",
pass_session_id=False,
session_id="",
)
base["platform"] = platform
base.update(overrides)
return SimpleNamespace(**base)
class TestDesktopHintEntry:
def test_desktop_key_exists(self):
"""The map must carry a "desktop" entry — without it the platform
hint lookup falls through to an empty string and the agent gets no
surface framing at all on the desktop chat surface."""
assert "desktop" in PLATFORM_HINTS
def test_desktop_hint_advertises_markdown(self):
"""The desktop renderer supports full GFM (verified via the
Streamdown pipeline in apps/desktop). The hint must steer the
agent toward markdown, not away from it like the cli/tui hints do."""
hint = PLATFORM_HINTS["desktop"]
assert "markdown" in hint.lower()
class TestDesktopHintBlockRemoved:
"""The standalone desktop-hint block that used to live in
``build_environment_hints()`` (lines ~1130-1144) was a band-aid for the
missing ``PLATFORM_HINTS["desktop"]`` entry. Once that entry exists, the
block is dead code that competes with the platform hint's claim of
what surface the agent is on. It must be gone."""
def test_build_environment_hints_has_no_runtime_surface_line(self, monkeypatch):
monkeypatch.setenv("HERMES_DESKTOP", "1")
monkeypatch.delenv("HERMES_DESKTOP_TERMINAL", raising=False)
from agent.prompt_builder import _BACKEND_PROBE_CACHE
_BACKEND_PROBE_CACHE.clear()
hints = build_environment_hints()
assert "Runtime surface:" not in hints
assert "desktop GUI app" not in hints
def test_build_environment_hints_has_no_embedded_pane_clarifier(self, monkeypatch):
"""The ⌥-drag / ⌘+L embedded-pane clarifier moves to the platform-hint
resolution site (system_prompt.py), not build_environment_hints()."""
monkeypatch.setenv("HERMES_DESKTOP", "1")
monkeypatch.setenv("HERMES_DESKTOP_TERMINAL", "1")
from agent.prompt_builder import _BACKEND_PROBE_CACHE
_BACKEND_PROBE_CACHE.clear()
hints = build_environment_hints()
assert "embedded terminal pane" not in hints
assert "Shift-drag" not in hints
class TestPlatformHintResolutionInStablePrompt:
"""End-to-end through ``build_system_prompt_parts`` — the platform tag on
the agent drives BOTH which PLATFORM_HINTS entry gets appended AND
whether the embedded-pane clarifier follows it. The desktop-hint block
that used to live in ``build_environment_hints()`` is gone."""
def test_desktop_platform_yields_desktop_hint_no_tui_framing(self, monkeypatch):
monkeypatch.setenv("HERMES_DESKTOP", "1")
monkeypatch.delenv("HERMES_DESKTOP_TERMINAL", raising=False)
stable = _stable_prompt(_make_agent(platform="desktop"))
assert PLATFORM_HINTS["desktop"] in stable
assert "terminal UI" not in stable
assert "Runtime surface:" not in stable
assert "embedded terminal pane" not in stable
def test_embedded_tui_yields_tui_hint_with_clarifier(self, monkeypatch):
monkeypatch.setenv("HERMES_DESKTOP", "1")
monkeypatch.setenv("HERMES_DESKTOP_TERMINAL", "1")
stable = _stable_prompt(_make_agent(platform="tui"))
assert PLATFORM_HINTS["tui"] in stable
assert "embedded terminal pane" in stable
assert "Shift-drag" in stable or "Option-drag" in stable or "⌥" in stable
class TestEmbeddedTuiPaneClarifier:
"""When ``HERMES_DESKTOP_TERMINAL=1``, a standalone ``hermes --tui`` is
running inside the desktop's embedded terminal pane. The user can
⌥-drag-select its output and ⌘/Ctrl+L to send it to the chat composer.
That clarifier must be appended to the ``tui`` platform hint at the
resolution site, NOT baked into the static ``PLATFORM_HINTS["tui"]``
string (which is shared with every standalone TUI session and must
stay byte-stable)."""
def test_embedded_pane_clarifier_appended_when_env_set(self, monkeypatch):
monkeypatch.setenv("HERMES_DESKTOP_TERMINAL", "1")
out = _tui_embedded_pane_clarifier(PLATFORM_HINTS["tui"])
assert out.startswith(PLATFORM_HINTS["tui"])
assert "embedded terminal pane" in out
assert "Shift-drag" in out or "Option-drag" in out or "⌥" in out
@pytest.mark.parametrize("val", ["0", "false", "no", "", "0", "False"])
def test_falsy_env_does_not_trigger_clarifier(self, monkeypatch, val):
monkeypatch.setenv("HERMES_DESKTOP_TERMINAL", val)
out = _tui_embedded_pane_clarifier(PLATFORM_HINTS["tui"])
assert out == PLATFORM_HINTS["tui"], (
f"HERMES_DESKTOP_TERMINAL={val!r} should not trigger clarifier"
)
class TestContradictionGone:
"""The original contradiction: a single assembled system prompt
contained both ``You are running in the Hermes terminal UI (TUI).`` and
``Runtime surface: you're running inside the Hermes desktop GUI app.``.
After the fix, no single session's prompt can carry both."""
def test_desktop_chat_session_has_no_tui_framing(self, monkeypatch):
monkeypatch.setenv("HERMES_DESKTOP", "1")
monkeypatch.delenv("HERMES_DESKTOP_TERMINAL", raising=False)
assert "tui" in PLATFORM_HINTS
assert "desktop" in PLATFORM_HINTS
desktop_hint = PLATFORM_HINTS["desktop"]
tui_hint = PLATFORM_HINTS["tui"]
assert "terminal UI" not in desktop_hint
assert "terminal UI" in tui_hint
def test_tui_hint_does_not_carry_desktop_marker(self):
tui_hint = PLATFORM_HINTS["tui"]
assert "desktop GUI app" not in tui_hint
assert "Runtime surface:" not in tui_hint