Files
hermes-agent/tests/hermes_cli/test_compress_flags.py
teknium1 d10bb2ab6f test: make tests/ mirror the source tree; drop issue numbers from filenames
`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.

Parallel directories for one source package, folded into the mirror:
  tests/acp        -> tests/acp_adapter   (its __init__/conftest move with it)
  tests/cli        -> tests/hermes_cli    (prompt_toolkit fixture merged into
                                           hermes_cli/conftest.py)
  tests/run_agent  -> tests/agent         (backoff fixture becomes
                                           agent/conftest.py)
  tests/relay      -> tests/gateway/relay
  tests/state      -> tests/hermes_state

246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.

Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.

Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).

Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
2026-09-13 09:18:02 -07:00

110 lines
3.0 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