hermes-agent/tests/hermes_cli/test_yolo_startup_order.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

57 lines
2 KiB
Python

"""Regression tests for #60328: --yolo must set HERMES_YOLO_MODE in
main() before _prepare_agent_startup() triggers tool imports.
The freeze mechanism in tools.approval (_YOLO_MODE_FROZEN) is correct
by design (PR #7994). The bug was that main() set the env var inside
cmd_chat(), which runs *after* _prepare_agent_startup() has already
imported tools.approval and frozen the constant to False.
These tests verify the ordering in main() itself: the env var must
already be set at the moment _prepare_agent_startup() is called.
If someone moves the assignment back into cmd_chat(), these tests
fail — catching the exact #60328 regression.
"""
import os
import sys
def _run_main_and_capture_yolo_at_startup(monkeypatch, argv):
"""Run main() with *argv*, capturing HERMES_YOLO_MODE at the
moment _prepare_agent_startup is called.
Returns the captured env var value (or None if unset).
"""
yolo_at_startup = {}
def spy_prepare_startup(args):
yolo_at_startup["value"] = os.environ.get("HERMES_YOLO_MODE")
monkeypatch.setattr(
"hermes_cli.main._prepare_agent_startup", spy_prepare_startup
)
# Stub cmd_chat so main() returns cleanly without entering chat.
monkeypatch.setattr("hermes_cli.main.cmd_chat", lambda args: None)
monkeypatch.delenv("HERMES_YOLO_MODE", raising=False)
monkeypatch.setattr(sys, "argv", argv)
from hermes_cli.main import main as cli_main
cli_main()
return yolo_at_startup.get("value")
def test_top_level_yolo_flag_sets_env_before_startup(monkeypatch):
"""hermes --yolo must set HERMES_YOLO_MODE before
_prepare_agent_startup imports tools.approval."""
result = _run_main_and_capture_yolo_at_startup(
monkeypatch, ["hermes", "--yolo"]
)
assert result == "1", (
"HERMES_YOLO_MODE was not '1' when _prepare_agent_startup was "
"called from main() with --yolo. This is the #60328 regression: "
"the env var is set too late (inside cmd_chat, after tool imports)."
)