mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-30 19:09:28 +00:00
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).
109 lines
3 KiB
Python
109 lines
3 KiB
Python
"""Tests for /compress --preview/--dry-run/--aggressive flags and the
|
|
/compact alias (PR #3243 salvage).
|
|
|
|
Covers the pure helpers in ``hermes_cli.partial_compress`` plus alias
|
|
resolution in the command registry. The CLI and gateway surfaces both
|
|
route through these helpers, so the flag semantics are pinned here once.
|
|
"""
|
|
|
|
from hermes_cli.commands import COMMANDS, resolve_command
|
|
from hermes_cli.partial_compress import (
|
|
DEFAULT_KEEP_LAST,
|
|
extract_compress_flags,
|
|
parse_partial_compress_args,
|
|
summarize_compress_preview,
|
|
)
|
|
|
|
|
|
def _history(n_pairs: int) -> list[dict[str, str]]:
|
|
h: list[dict[str, str]] = []
|
|
for i in range(n_pairs):
|
|
h.append({"role": "user", "content": f"u{i}"})
|
|
h.append({"role": "assistant", "content": f"a{i}"})
|
|
return h
|
|
|
|
|
|
# ── /compact alias resolution ─────────────────────────────────────────
|
|
|
|
|
|
def test_compact_resolves_to_compress():
|
|
cmd = resolve_command("compact")
|
|
assert cmd is not None
|
|
assert cmd.name == "compress"
|
|
assert "compact" in cmd.aliases
|
|
|
|
|
|
|
|
|
|
def test_compact_listed_in_flat_commands():
|
|
assert "/compact" in COMMANDS
|
|
assert "alias for /compress" in COMMANDS["/compact"]
|
|
|
|
|
|
|
|
|
|
# ── extract_compress_flags ────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_dry_run_is_preview():
|
|
for form in ("--dry-run", "--dryrun", "--DRY-RUN"):
|
|
_, preview, _ = extract_compress_flags(form)
|
|
assert preview is True, form
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_flags_coexist_with_focus_topic():
|
|
rest, preview, _ = extract_compress_flags("database schema --dry-run")
|
|
assert rest == "database schema"
|
|
assert preview is True
|
|
partial, _, focus = parse_partial_compress_args(rest)
|
|
assert partial is False and focus == "database schema"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ── summarize_compress_preview ────────────────────────────────────────
|
|
|
|
|
|
def test_preview_full_compress_counts():
|
|
hist = _history(5)
|
|
report = summarize_compress_preview(hist, False, DEFAULT_KEEP_LAST, None, 1234)
|
|
assert report["head_count"] == 10
|
|
assert report["tail_count"] == 0
|
|
assert report["total"] == 10
|
|
assert report["partial"] is False
|
|
joined = "\n".join(report["lines"])
|
|
assert "no changes made" in joined.lower()
|
|
assert "10 of 10" in joined
|
|
assert "1,234" in joined
|
|
|
|
|
|
def test_preview_partial_boundary_counts():
|
|
hist = _history(5)
|
|
report = summarize_compress_preview(hist, True, 2, None, 999)
|
|
# Keeping last 2 exchanges = 4 tail messages, 6 head messages.
|
|
assert report["head_count"] == 6
|
|
assert report["tail_count"] == 4
|
|
assert report["partial"] is True
|
|
joined = "\n".join(report["lines"])
|
|
assert "last 2 exchange" in joined
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_preview_is_side_effect_free():
|
|
hist = _history(4)
|
|
before = [dict(m) for m in hist]
|
|
summarize_compress_preview(hist, True, 1, None, 10)
|
|
assert hist == before
|