mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +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).
93 lines
3 KiB
Python
93 lines
3 KiB
Python
"""Tests for focus_topic flowing through the compressor.
|
|
|
|
Verifies that _generate_summary and compress accept and use the focus_topic
|
|
parameter correctly. Inspired by Claude Code's /compact <focus>.
|
|
"""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from agent.context_compressor import ContextCompressor
|
|
|
|
|
|
def _make_compressor():
|
|
"""Create a ContextCompressor with minimal state for testing."""
|
|
compressor = ContextCompressor.__new__(ContextCompressor)
|
|
compressor.protect_first_n = 2
|
|
compressor.protect_last_n = 5
|
|
compressor.tail_token_budget = 20000
|
|
compressor.context_length = 200000
|
|
compressor.threshold_percent = 0.80
|
|
compressor.threshold_tokens = 160000
|
|
compressor.summary_target_ratio = 0.20
|
|
compressor.max_summary_tokens = 10000
|
|
compressor.quiet_mode = True
|
|
compressor.compression_count = 0
|
|
compressor.last_prompt_tokens = 0
|
|
compressor._previous_summary = None
|
|
compressor._ineffective_compression_count = 0
|
|
compressor._verify_compaction_cleared_threshold = False
|
|
compressor._summary_failure_cooldown_until = 0.0
|
|
compressor.summary_model = None
|
|
compressor.model = "test-model"
|
|
compressor.provider = "test"
|
|
compressor.base_url = "http://localhost"
|
|
compressor.api_key = "test-key"
|
|
compressor.api_mode = "chat_completions"
|
|
return compressor
|
|
|
|
|
|
def test_focus_topic_injected_into_summary_prompt():
|
|
"""When focus_topic is provided, the LLM prompt includes focus guidance."""
|
|
compressor = _make_compressor()
|
|
turns = [
|
|
{"role": "user", "content": "Tell me about the database schema"},
|
|
{"role": "assistant", "content": "The schema has tables: users, orders, products."},
|
|
]
|
|
|
|
captured_prompt = {}
|
|
|
|
def mock_call_llm(**kwargs):
|
|
captured_prompt["messages"] = kwargs["messages"]
|
|
resp = MagicMock()
|
|
resp.choices = [MagicMock()]
|
|
resp.choices[0].message.content = "## Goal\nUnderstand DB schema."
|
|
return resp
|
|
|
|
with patch("agent.context_compressor.call_llm", mock_call_llm):
|
|
result = compressor._generate_summary(turns, focus_topic="database schema")
|
|
|
|
assert result is not None
|
|
prompt_text = captured_prompt["messages"][0]["content"]
|
|
assert 'FOCUS TOPIC: "database schema"' in prompt_text
|
|
assert "PRIORITISE" in prompt_text
|
|
assert "60-70%" in prompt_text
|
|
|
|
|
|
def test_no_focus_topic_no_injection():
|
|
"""Without focus_topic, the prompt doesn't contain focus guidance."""
|
|
compressor = _make_compressor()
|
|
turns = [
|
|
{"role": "user", "content": "Hello"},
|
|
{"role": "assistant", "content": "Hi"},
|
|
]
|
|
|
|
captured_prompt = {}
|
|
|
|
def mock_call_llm(**kwargs):
|
|
captured_prompt["messages"] = kwargs["messages"]
|
|
resp = MagicMock()
|
|
resp.choices = [MagicMock()]
|
|
resp.choices[0].message.content = "## Goal\nGreeting."
|
|
return resp
|
|
|
|
with patch("agent.context_compressor.call_llm", mock_call_llm):
|
|
result = compressor._generate_summary(turns)
|
|
|
|
prompt_text = captured_prompt["messages"][0]["content"]
|
|
assert "FOCUS TOPIC" not in prompt_text
|
|
|
|
|
|
|
|
|
|
|
|
|