The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(compression): trim lean-tail skill marker tests to the survival invariant
Tekniumd74f7c2f7e24
diff --git a/tests/agent/test_context_compressor_tail.py b/tests/agent/test_context_compressor_tail.pyindex 8582e13a57e..2d610100c03 100644--- a/tests/agent/test_context_compressor_tail.py+++ b/tests/agent/test_context_compressor_tail.py@@ -4,12 +4,7 @@ import jsonimport pytestimport agent.context_compressor as cc-from agent.context_compressor_tail import (- _LEAN_TAIL_DEMOTE_MIN_CHARS,- _LEAN_TAIL_KEEP_TOOL_ROUNDS,- _lean_recovery_stub,- demote_stale_tail_tools,-)+from agent.context_compressor_tail import _LEAN_TAIL_KEEP_TOOL_ROUNDSSKILL = "synthetic-tail-skill"BODY = "Skill instructions " + "s" * 2000@@ -37,38 +32,6 @@ def _stub_for(rows, call_id):return next(r["content"] for r in rows if r.get("role") == "tool" and r.get("tool_call_id") == call_id)-def test_demoted_skill_view_keeps_reload_marker():- rows = _round("skill-1", "skill_view", {"name": SKILL}, BODY) + _fresh_rounds()-- out, demoted = demote_stale_tail_tools(rows, 0, "sess-1")-- stub = _stub_for(out, "skill-1")- assert demoted == 1 and stub.startswith(_lean_recovery_stub("skill_view", len(BODY), "sess-1"))- assert cc._extract_pruned_skill_names(stub) == [SKILL] # the next compaction lists it under ## Pruned Skills---def test_non_skill_stub_unchanged_and_fresh_rounds_kept():- output = "Terminal output " + "o" * _LEAN_TAIL_DEMOTE_MIN_CHARS- rows = _round("term-1", "terminal", {"command": "make"}, output) + _fresh_rounds()-- out, demoted = demote_stale_tail_tools(rows, 0, "")-- assert demoted == 1 and _stub_for(out, "term-1") == _lean_recovery_stub("terminal", len(output), "")- assert all(out[i] is rows[i] for i in range(2, len(rows)))---def test_each_skill_row_gets_its_own_name_and_tool_name_is_optional():- calls = [_call("a", "skill_view", {"name": "skill-a"}), _call("b", "skill_view", {"name": "skill-b"})]- rows = [{"role": "assistant", "tool_calls": calls},- {"role": "tool", "tool_call_id": "a", "content": BODY},- {"role": "tool", "tool_call_id": "b", "content": BODY}] + _fresh_rounds()-- out, _ = demote_stale_tail_tools(rows, 0, "")-- assert cc._extract_pruned_skill_names(_stub_for(out, "a")) == ["skill-a"]- assert cc._extract_pruned_skill_names(_stub_for(out, "b")) == ["skill-b"]--@pytest.fixturedef compressor(monkeypatch):monkeypatch.setattr(cc, "get_model_context_length", lambda *a, **k: 100_000)@@ -80,31 +43,6 @@ def compressor(monkeypatch):return comp-def test_compress_demotes_tail_skill_with_reload_marker(compressor):- rows = [- {"role": "system", "content": "Synthetic test conversation."},- {"role": "user", "content": "Summarize the completed earlier work."},- {"role": "assistant", "content": "Old notes " + "x" * 40_000},- # Phase-1 pressure demotes this older result first, so the skill body reaches tail demotion raw.- *_round("older-terminal", "terminal", {"command": "old-job"}, "Earlier output " + "o" * 8000),- {"role": "user", "content": "Continue the current work."},- *_round("skill-1", "skill_view", {"name": SKILL}, BODY),- *_fresh_rounds(),- {"role": "assistant", "content": "All rounds completed."},- {"role": "user", "content": "Report the current work."},- {"role": "assistant", "content": "Current work reported."},- ]- _, end = compressor._compress_window(rows)- assert any(r.get("tool_call_id") == "skill-1" for r in rows[end:]), "skill row must be in the tail"-- out = compressor.compress(rows, force=True)-- assert compressor.compression_count == 1 and not compressor._last_summary_fallback_used- stub = _stub_for(out, "skill-1")- assert "output demoted at compaction" in stub- assert cc._extract_pruned_skill_names(stub) == [SKILL], stub--def test_reload_marker_survives_the_next_compaction(compressor):# With a session id the marked stub passes the Phase-1 prune floor (200 chars); it must not be# re-summarised into a plain "[skill_view] ..." line that drops the marker.