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

61 lines
1.9 KiB
Python

"""Tests for the CLI `/prompt` editor-compose command.
`/prompt` opens `$VISUAL`/`$EDITOR` on a temp markdown file so the user can
hand-edit a multi-line prompt, then queues the saved buffer as the next
agent turn via the one-shot `_pending_agent_seed` (same path `/blueprint`
uses). These drive a fake editor subprocess to verify read-back, header
stripping, seeding, and the empty-buffer cancel path.
"""
import os
import stat
import tempfile
import pytest
from hermes_cli.cli_commands_mixin import CLICommandsMixin
from hermes_cli.commands import resolve_command
class _Stub(CLICommandsMixin):
def __init__(self):
self._pending_agent_seed = None
def _fake_editor(body: str, mode: str = "append") -> str:
"""Write a tiny shell 'editor' that mutates the file it is handed."""
f = tempfile.NamedTemporaryFile("w", suffix=".sh", delete=False)
if mode == "append":
f.write("#!/usr/bin/env bash\n")
f.write(f"cat >> \"$1\" <<'EOF'\n{body}\nEOF\n")
else: # clear
f.write("#!/usr/bin/env bash\n: > \"$1\"\n")
f.close()
os.chmod(f.name, os.stat(f.name).st_mode | stat.S_IEXEC)
return f.name
@pytest.fixture(autouse=True)
def _no_visual(monkeypatch):
monkeypatch.delenv("VISUAL", raising=False)
def test_command_registered():
cd = resolve_command("prompt")
assert cd and cd.name == "prompt"
assert resolve_command("compose").name == "prompt"
def test_compose_reads_and_strips_header(monkeypatch):
monkeypatch.setenv("EDITOR", _fake_editor("Refactor the auth module.\nUse pytest."))
out = _Stub()._compose_in_editor("")
assert "Refactor the auth module." in out
assert "Use pytest." in out
assert "#!" not in out # the instructional header is stripped
def test_empty_buffer_does_not_seed(monkeypatch):
monkeypatch.setenv("EDITOR", _fake_editor("", mode="clear"))
s = _Stub()
s._handle_prompt_compose_command("/prompt")
assert s._pending_agent_seed is None