hermes-agent/tests/tui_gateway/test_reasoning_session_scope.py
Teknium 6b81590c55
test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions
Systematic prune per AGENTS.md test policy, one pass over every major
test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli,
cron, tui_gateway, honcho/openviking, root-level):

- DELETE: source-reading tests (read_text/getsource on prod files),
  change-detector tests (exact catalog counts, model-name snapshots,
  config version literals), mock-echo tests (assert a mock returns what
  it was told), assertion-free/trivial tests, near-duplicate
  parametrizations (boundaries + one representative kept), async/sync
  twin duplicates, cosmetic within-file variations.
- KEEP (mandatory): security/redaction/approval guards, message-role
  alternation invariants, prompt-caching/deterministic-call-id
  invariants, issue-number regression tests (deduped), E2E tests.
- 6 test files deleted outright (script-style/no-assert or fully
  redundant); conftest.py, fakes/, fixtures/ untouched.
- tests/acp/conftest.py added: autouse fixture stubs the live
  models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server
  tests performed on every session create — test_server.py 147s → 3.4s,
  and the tests are now genuinely hermetic.
- Sleep-based slowness shrunk where safe (codex_ttfb_watchdog,
  compression_concurrent_fork, etc.); no wall-clock assertion tightened.

Verification: full hermetic suite via scripts/run_tests.sh —
2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall
(baseline: 583s wall, 13,564s subprocess CPU).
2026-07-29 13:10:23 -07:00

103 lines
3.9 KiB
Python

"""Reasoning-effort session scoping in the TUI gateway (desktop backend).
Covers the "desktop reverts thinking to medium after one turn" report:
1. ``_session_info`` must report ``reasoning_effort: "none"`` when reasoning
is disabled — reporting ``""`` (indistinguishable from "unset") made the
desktop adopt the empty value after the first turn, wiping its sticky
"thinking off" pick so every later chat reverted to the default effort.
2. ``config.set key=reasoning`` with a live session must be session-scoped:
it must NOT rewrite the global ``agent.reasoning_effort`` in config.yaml
(the desktop model menu applies a per-model preset on every selection,
which was silently clobbering the user's configured value), and it must
land on ``create_reasoning_override`` so lazily-built sessions (agent not
constructed until the first prompt) don't drop the change.
3. ``_load_reasoning_config`` must honor a YAML boolean False
(``reasoning_effort: false`` / ``off`` / ``no``) as thinking-disabled.
"""
from __future__ import annotations
from types import SimpleNamespace
from unittest.mock import patch
import tui_gateway.server as server
from tui_gateway.server import _session_info
def _agent(reasoning_config):
return SimpleNamespace(
reasoning_config=reasoning_config,
service_tier=None,
model="glm-5",
provider="zai",
session_id="sess-key",
)
class TestSessionInfoReasoningEffort:
"""Disabled reasoning must be reported as 'none', never ''."""
def test_disabled_reports_none(self) -> None:
info = _session_info(_agent({"enabled": False}))
assert info["reasoning_effort"] == "none"
def test_enabled_reports_effort(self) -> None:
info = _session_info(_agent({"enabled": True, "effort": "high"}))
assert info["reasoning_effort"] == "high"
def test_unset_reports_empty(self) -> None:
info = _session_info(_agent(None))
assert info["reasoning_effort"] == ""
class TestConfigSetReasoningSessionScope:
"""Session-targeted reasoning changes must not touch global config."""
def _dispatch(self, params: dict) -> dict:
handler = server._methods["config.set"]
return handler("rid-1", params)
def test_session_scoped_set_skips_global_write(self) -> None:
agent = _agent(None)
session = {"session_key": "k1", "agent": agent}
with patch.dict(server._sessions, {"s1": session}, clear=False), \
patch.object(server, "_write_config_key") as write_key, \
patch.object(server, "_persist_live_session_runtime"), \
patch.object(server, "_emit"):
resp = self._dispatch(
{"key": "reasoning", "session_id": "s1", "value": "none"}
)
assert resp["result"]["value"] == "none"
assert agent.reasoning_config == {"enabled": False}
write_key.assert_not_called()
def test_no_session_persists_globally(self) -> None:
with patch.object(server, "_write_config_key") as write_key:
resp = self._dispatch({"key": "reasoning", "value": "low"})
assert resp["result"]["value"] == "low"
write_key.assert_called_once_with("agent.reasoning_effort", "low")
def test_unknown_value_rejected(self) -> None:
resp = self._dispatch({"key": "reasoning", "value": "bogus"})
assert "error" in resp
class TestLoadReasoningConfigYamlBoolean:
"""YAML `reasoning_effort: false` means disabled, not default."""
def test_boolean_false_disables(self) -> None:
with patch.object(
server, "_load_cfg", return_value={"agent": {"reasoning_effort": False}}
):
assert server._load_reasoning_config() == {"enabled": False}
def test_string_false_disables(self) -> None:
with patch.object(
server, "_load_cfg", return_value={"agent": {"reasoning_effort": "false"}}
):
assert server._load_reasoning_config() == {"enabled": False}