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).
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
"""Regression: detect compression progress by tokens, not just rows.
|
|
|
|
Issue #39548: preflight compression in the turn prologue was checking
|
|
``len(messages) >= _orig_len`` to decide "Cannot compress further". This
|
|
false-positives when a pass summarises message contents — reducing the
|
|
estimated request token count without removing any rows — and surfaces a
|
|
spurious ``Context length exceeded`` failure followed by an auto-reset of
|
|
an otherwise healthy session.
|
|
|
|
These tests pin the contract of ``_compression_made_progress``: a
|
|
row-count reduction OR a *material* (>5%) token-count reduction counts as
|
|
progress.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from agent.turn_context import (
|
|
_compression_made_progress,
|
|
_compression_warrants_another_preflight_pass,
|
|
)
|
|
|
|
|
|
class TestCompressionMadeProgress:
|
|
def test_rows_reduced_counts_as_progress(self):
|
|
"""Removing message rows is the obvious progress signal."""
|
|
assert _compression_made_progress(
|
|
orig_len=10, new_len=5, orig_tokens=1000, new_tokens=1000
|
|
) is True
|
|
|
|
|
|
|
|
def test_neither_moved_means_no_progress(self):
|
|
"""The genuine "stuck" case — same rows, same tokens, give up."""
|
|
assert _compression_made_progress(
|
|
orig_len=10, new_len=10, orig_tokens=1000, new_tokens=1000
|
|
) is False
|
|
|
|
|
|
|
|
|
|
def test_sub_5pct_token_drop_is_not_progress(self):
|
|
"""A token reduction below the 5% material floor does NOT count as
|
|
progress — matching the overflow-handler retry path (#39550) so a
|
|
marginal wobble can't keep the multi-pass loop spinning."""
|
|
# 1000 -> 970 is a 3% drop, below the 5% floor.
|
|
assert _compression_made_progress(
|
|
orig_len=10, new_len=10, orig_tokens=1000, new_tokens=970
|
|
) is False
|
|
# 1000 -> 940 is a 6% drop, above the floor.
|
|
assert _compression_made_progress(
|
|
orig_len=10, new_len=10, orig_tokens=1000, new_tokens=940
|
|
) is True
|
|
|
|
|
|
|
|
class TestCompressionWarrantsAnotherPreflightPass:
|
|
def test_material_reduction_above_threshold_allows_another_pass(self):
|
|
assert _compression_warrants_another_preflight_pass(
|
|
orig_tokens=400_000,
|
|
new_tokens=350_000,
|
|
threshold_tokens=272_000,
|
|
) is True
|
|
|
|
def test_marginal_reduction_above_threshold_stops(self):
|
|
assert _compression_warrants_another_preflight_pass(
|
|
orig_tokens=350_000,
|
|
new_tokens=345_000,
|
|
threshold_tokens=272_000,
|
|
) is False
|
|
|