From 052b3449e595e35c21308b24a1f32754b33526b5 Mon Sep 17 00:00:00 2001 From: revar Date: Tue, 28 Apr 2026 04:58:16 -0700 Subject: [PATCH] test(cli): regression test for manual /compress system_message Add tests/test_cli_manual_compress.py verifying _manual_compress passes None (not the cached system prompt) to _compress_context, forwards the /compress focus string, rotates CLI session_id to the new child session, and clears the pending title. Co-authored-by: revar --- tests/test_cli_manual_compress.py | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/test_cli_manual_compress.py diff --git a/tests/test_cli_manual_compress.py b/tests/test_cli_manual_compress.py new file mode 100644 index 000000000..26b966ab6 --- /dev/null +++ b/tests/test_cli_manual_compress.py @@ -0,0 +1,57 @@ +from contextlib import nullcontext + +from cli import HermesCLI + + +class DummyAgent: + def __init__(self): + self.compression_enabled = True + self._cached_system_prompt = "FULL CACHED SYSTEM PROMPT SHOULD NOT BE NESTED" + self.session_id = "new-session" + self.calls = [] + + def _compress_context(self, messages, system_message, *, approx_tokens=None, focus_topic=None): + self.calls.append( + { + "messages": messages, + "system_message": system_message, + "approx_tokens": approx_tokens, + "focus_topic": focus_topic, + } + ) + return ([{"role": "user", "content": "[CONTEXT SUMMARY]: compacted"}], "new system prompt") + + +def test_manual_compress_does_not_pass_cached_system_prompt(monkeypatch): + """Manual /compress should rebuild the next prompt without nesting the old one.""" + cli = HermesCLI.__new__(HermesCLI) + cli.conversation_history = [ + {"role": "user", "content": "one"}, + {"role": "assistant", "content": "two"}, + {"role": "user", "content": "three"}, + {"role": "assistant", "content": "four"}, + ] + cli.agent = DummyAgent() + cli.session_id = "old-session" + cli._pending_title = "old title" + cli._busy_command = lambda _message: nullcontext() + + monkeypatch.setattr( + "agent.manual_compression_feedback.summarize_manual_compression", + lambda *args, **kwargs: { + "noop": False, + "headline": "compressed", + "token_line": "tokens reduced", + "note": "", + }, + ) + + cli._manual_compress("/compress database schema") + + assert len(cli.agent.calls) == 1 + call = cli.agent.calls[0] + assert call["system_message"] is None + assert call["system_message"] != cli.agent._cached_system_prompt + assert call["focus_topic"] == "database schema" + assert cli.session_id == "new-session" + assert cli._pending_title is None