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

68 lines
1.8 KiB
Python

"""Behavioral coverage for manual compression status messages."""
from types import SimpleNamespace
from agent.manual_compression_feedback import (
describe_compression_lock_skip,
summarize_manual_compression,
)
def _messages(count: int) -> list[dict[str, str]]:
return [
{"role": "user" if index % 2 == 0 else "assistant", "content": str(index)}
for index in range(count)
]
def test_failure_reason_redaction_is_forced_at_ui_boundary(monkeypatch):
messages = _messages(12)
fake_secret = "sk-proj-" + "X" * 40
state = SimpleNamespace(
_last_compress_aborted=True,
_last_summary_fallback_used=False,
_last_summary_error=f"provider rejected OPENAI_API_KEY={fake_secret}",
)
monkeypatch.setattr("agent.redact._REDACT_ENABLED", False, raising=False)
feedback = summarize_manual_compression(
messages,
list(messages),
120_000,
120_000,
compression_state=state,
)
assert fake_secret not in feedback["note"]
assert "OPENAI_API_KEY=" in feedback["note"]
def test_fallback_compression_reports_dropped_message_count():
before = _messages(12)
after = before[:2] + before[-2:]
state = SimpleNamespace(
_last_compress_aborted=False,
_last_summary_fallback_used=True,
_last_summary_dropped_count=8,
_last_summary_error="summary provider returned an invalid response",
)
feedback = summarize_manual_compression(
before,
after,
120_000,
40_000,
compression_state=state,
)
assert feedback["aborted"] is False
assert feedback["fallback_used"] is True
assert feedback["headline"] == "Compressed with fallback: 12 → 4 messages"
assert "removed 8 message(s)" in feedback["note"]
assert "invalid response" in feedback["note"]