mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-26 17:38:36 +00:00
Address review on #69619: the previous commit mutated the newest frozen entry in _HISTORICAL_SUMMARY_PREFIXES and never froze the live prefix it retired (the generation with both the four-heading discard clause and the tools-active clause). A summary persisted immediately before upgrading was therefore treated as an ordinary message on resume/re-compaction, keeping the old handoff text embedded in the body. - Prepend the exact pre-change live prefix as a new frozen entry (newest-first), leaving all existing frozen entries byte-identical - Restore the Jul 2026 (#65848 class) frozen entry to its original four-heading text - Pin the retired generation as a literal in test_summary_prefix_semantics.py so mutating or dropping it fails CI - Make the #65848 tool-use regression position-agnostic (match the pre-clause generation by content, not tuple index) Verified byte-identity of both rescued generations against the parent commit. 233 focused prefix/resume/compressor tests pass.
61 lines
2.9 KiB
Python
61 lines
2.9 KiB
Python
"""Regression tests for the SUMMARY_PREFIX tool-use clause (#65848 class).
|
|
|
|
The REFERENCE ONLY framing must keep its anti-resumption protections while
|
|
explicitly NOT restricting tool use — the strong wording was observed bleeding
|
|
into general tool-use suppression (narration-only turns after compression).
|
|
"""
|
|
|
|
from agent.context_compressor import (
|
|
_HISTORICAL_SUMMARY_PREFIXES,
|
|
LEGACY_SUMMARY_PREFIX,
|
|
SUMMARY_PREFIX,
|
|
)
|
|
|
|
|
|
class TestSummaryPrefixToolUseClause:
|
|
def test_prefix_affirms_tools_remain_active(self):
|
|
assert "tools remain fully active" in SUMMARY_PREFIX
|
|
assert "narrating" in SUMMARY_PREFIX
|
|
|
|
def test_prefix_keeps_anti_resumption_protections(self):
|
|
"""The clause is additive — every load-bearing protection stays."""
|
|
assert "REFERENCE ONLY" in SUMMARY_PREFIX
|
|
assert "Do NOT answer questions or fulfill requests" in SUMMARY_PREFIX
|
|
assert "the latest user message WINS" in SUMMARY_PREFIX
|
|
assert "Reverse signals" in SUMMARY_PREFIX
|
|
assert "ALWAYS authoritative" in SUMMARY_PREFIX
|
|
|
|
def test_previous_generation_frozen_in_historical_prefixes(self):
|
|
"""Per the module contract: whenever SUMMARY_PREFIX changes, the prior
|
|
generation must be frozen into _HISTORICAL_SUMMARY_PREFIXES so old
|
|
persisted summaries still get the directive-strip on re-compaction."""
|
|
assert len(_HISTORICAL_SUMMARY_PREFIXES) >= 3
|
|
# The pre-clause generation (#65848 incident era): same framing, no
|
|
# tools-active clause. Newer generations are prepended ahead of it as
|
|
# the prefix evolves (tuple is newest-first), so match by content,
|
|
# not position. "topic overlap" distinguishes it from the older
|
|
# carveout-era entry.
|
|
pre_clause = [
|
|
p for p in _HISTORICAL_SUMMARY_PREFIXES
|
|
if "tools remain fully active" not in p
|
|
and "topic overlap" in p.lower()
|
|
and "Do NOT answer questions or fulfill requests" in p
|
|
]
|
|
assert pre_clause, "pre-clause generation missing from frozen tuple"
|
|
assert all(p != SUMMARY_PREFIX for p in pre_clause)
|
|
|
|
def test_historical_prefixes_are_distinct_from_current(self):
|
|
for frozen in _HISTORICAL_SUMMARY_PREFIXES:
|
|
assert frozen != SUMMARY_PREFIX
|
|
assert LEGACY_SUMMARY_PREFIX != SUMMARY_PREFIX
|
|
|
|
def test_strip_recognizes_current_and_frozen_prefixes(self):
|
|
"""Re-compaction normalization must strip both the live prefix and the
|
|
newly frozen one (the incident generation)."""
|
|
from agent.context_compressor import ContextCompressor
|
|
|
|
for prefix in (SUMMARY_PREFIX, _HISTORICAL_SUMMARY_PREFIXES[0]):
|
|
text = f"{prefix}\nsummary body here"
|
|
stripped = ContextCompressor._strip_summary_prefix(text)
|
|
assert "summary body here" in stripped
|
|
assert "REFERENCE ONLY" not in stripped
|