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

88 lines
3.2 KiB
Python

"""Tests for /init — generate or update AGENTS.md from a project scan.
Covers the shared prompt builder (hermes_cli.init_command.build_init_prompt)
and the slash-command registry wiring. /init has no engine and no model tool:
it builds a guidance-laden prompt that the live agent runs as a normal turn
(the /learn pattern), so these are the load-bearing behavior contracts.
"""
from hermes_cli.init_command import (
_QUALITY_BAR,
build_init_prompt,
build_init_prompt_for_cwd,
)
class TestBuildInitPrompt:
def test_includes_the_cwd(self):
prompt = build_init_prompt("/home/alice/projects/acme")
assert "/home/alice/projects/acme" in prompt
def test_fresh_generation_when_no_existing_file(self):
prompt = build_init_prompt("/tmp/proj", existing_file=None)
assert "generate an AGENTS.md" in prompt
# No merge discipline block for a fresh file.
assert "MERGE DISCIPLINE" not in prompt
def test_merge_not_overwrite_when_existing_file_passed(self):
existing = "# My Project\n\nAlways run `make lint` before committing.\n"
prompt = build_init_prompt("/tmp/proj", existing_file=existing)
low = prompt.lower()
# Update mode, with explicit merge-not-overwrite discipline.
assert "UPDATE the existing AGENTS.md" in prompt
assert "merge" in low
assert "do not overwrite" in low or "not overwrite" in low
assert "preserve" in low
# And it carries the current content so the agent can merge.
assert existing.strip() in prompt
def test_includes_extra_notes_verbatim(self):
notes = "focus on the test setup, and mention the flaky e2e suite"
prompt = build_init_prompt("/tmp/proj", extra=notes)
assert notes in prompt
def test_always_includes_the_quality_bar(self):
for existing in (None, "# old content"):
prompt = build_init_prompt("/tmp/proj", existing_file=existing)
assert _QUALITY_BAR in prompt
def test_quality_bar_demands_exact_commands_and_conciseness(self):
low = _QUALITY_BAR.lower()
assert "100 lines" in low
assert "never invent" in low
assert "no generic advice" in low
class TestBuildInitPromptForCwd:
def test_reads_existing_agents_md(self, tmp_path):
(tmp_path / "AGENTS.md").write_text(
"# Existing\n\nRun `tox -e py311`.\n", encoding="utf-8"
)
prompt = build_init_prompt_for_cwd(cwd=str(tmp_path))
assert "UPDATE the existing AGENTS.md" in prompt
assert "Run `tox -e py311`." in prompt
def test_passes_extra_through(self, tmp_path):
prompt = build_init_prompt_for_cwd(cwd=str(tmp_path), extra="keep it short")
assert "keep it short" in prompt
class TestInitRegistryWiring:
def test_init_is_registered_and_resolves(self):
from hermes_cli.commands import resolve_command
cmd = resolve_command("init")
assert cmd is not None
assert cmd.name == "init"
def test_init_works_on_the_gateway(self):
# /init is a both-surfaces command like /learn, not CLI-only.
from hermes_cli.commands import GATEWAY_KNOWN_COMMANDS
assert "init" in GATEWAY_KNOWN_COMMANDS