Files
hermes-agent/tests/agent/test_reasoning_echo_resolver_e2e.py
T
teknium1 d10bb2ab6f test: make tests/ mirror the source tree; drop issue numbers from filenames
`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.

Parallel directories for one source package, folded into the mirror:
  tests/acp        -> tests/acp_adapter   (its __init__/conftest move with it)
  tests/cli        -> tests/hermes_cli    (prompt_toolkit fixture merged into
                                           hermes_cli/conftest.py)
  tests/run_agent  -> tests/agent         (backoff fixture becomes
                                           agent/conftest.py)
  tests/relay      -> tests/gateway/relay
  tests/state      -> tests/hermes_state

246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.

Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.

Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).

Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
2026-09-13 09:18:02 -07:00

109 lines
4.6 KiB
Python

"""Production-shape coverage for reasoning_echo: real resolver + real init read.
Salvaged from #73811 per the consolidation triage on #76503 and adapted to this
PR's per-active-provider `model.reasoning_echo` design.
Every existing reasoning_echo test hand-sets `agent._reasoning_echo_flag` (and
`provider`/`base_url`). None drives the REAL config path that `init_agent` uses:
agent._reasoning_echo_flag = bool(
(load_config_readonly().get("model") or {}).get("reasoning_echo"))
...which is wrapped in `except Exception: False`, so if that read ever breaks the
feature silently dies and no current test catches it. This test closes that gap.
It also pins the named-custom-provider case: a provider declared under
`providers.<name>` resolves at runtime to `provider == "custom"` (see
`hermes_cli/runtime_provider.py`), and the echo flag must still take effect for
it. A future refactor keying the flag on provider *name* would reintroduce that
miss; this test is the tripwire.
Uses a temp HERMES_HOME + real `load_config_readonly` (the config cache is
path-keyed, so this is hermetic) — no live server, no hand-set flag.
"""
from __future__ import annotations
from hermes_cli.runtime_provider import resolve_runtime_provider
from agent.agent_runtime_helpers import copy_reasoning_content_for_api
from run_agent import AIAgent
def _write_home(tmp_path, monkeypatch, reasoning_echo: bool):
"""Point HERMES_HOME at a temp profile declaring a named custom provider."""
home = tmp_path / "hermes"
home.mkdir()
lines = [
"model:",
" default: kimi-k3",
" provider: llamacpp-k3",
]
if reasoning_echo:
lines.append(" reasoning_echo: true")
lines += [
"providers:",
" llamacpp-k3:",
" base_url: http://127.0.0.1:8098/v1",
" key_env: LLAMACPP_KEY",
]
(home / "config.yaml").write_text("\n".join(lines) + "\n")
monkeypatch.setenv("HERMES_HOME", str(home))
# Drop any path-keyed config cache from a prior test.
try:
from hermes_cli import config as _cfg
for name in ("_CONFIG_CACHE", "_config_cache"):
if hasattr(_cfg, name):
getattr(_cfg, name).clear()
except Exception:
pass
def _agent_with_init_flag() -> AIAgent:
"""Build an agent and materialize the echo flag the way init_agent does."""
from hermes_cli.config import load_config_readonly
agent = object.__new__(AIAgent)
agent._reasoning_echo_flag = bool(
(load_config_readonly().get("model") or {}).get("reasoning_echo")
)
agent.provider = "custom" # what the resolver returns for a named custom provider
agent.base_url = "http://127.0.0.1:8098/v1"
agent.model = "kimi-k3"
agent.verbose_logging = False
return agent
class TestReasoningEchoResolverE2E:
def test_named_custom_provider_resolves_to_custom(self, tmp_path, monkeypatch):
"""The provider config path really does collapse to provider == 'custom'."""
_write_home(tmp_path, monkeypatch, reasoning_echo=True)
rt = resolve_runtime_provider(requested="llamacpp-k3")
assert rt["provider"] == "custom"
assert rt["base_url"].rstrip("/") == "http://127.0.0.1:8098/v1"
def test_flag_materializes_from_real_config_and_echoes(self, tmp_path, monkeypatch):
"""reasoning_echo: true -> flag True via the real init read -> reasoning kept."""
_write_home(tmp_path, monkeypatch, reasoning_echo=True)
agent = _agent_with_init_flag()
assert agent._reasoning_echo_flag is True
assert agent._reasoning_echo_opt_in() is True
assert agent._needs_thinking_reasoning_pad() is True
source = {"role": "assistant", "content": "calling a tool",
"reasoning_content": "the model's chain of thought"}
api_msg = dict(source)
copy_reasoning_content_for_api(agent, source, api_msg)
assert api_msg["reasoning_content"] == "the model's chain of thought"
def test_flag_absent_strips(self, tmp_path, monkeypatch):
"""No reasoning_echo -> flag False -> reasoning_content stripped on replay."""
_write_home(tmp_path, monkeypatch, reasoning_echo=False)
agent = _agent_with_init_flag()
assert agent._reasoning_echo_flag is False
assert agent._reasoning_echo_opt_in() is False
source = {"role": "assistant", "content": "calling a tool",
"reasoning_content": "should be stripped"}
api_msg = dict(source)
copy_reasoning_content_for_api(agent, source, api_msg)
assert "reasoning_content" not in api_msg