Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

test(traffic-learner): regression test for shutdown evidence gate

Garma8ebf9ac5e1c
diff --git a/tests/test_memory/test_traffic_learner.py b/tests/test_memory/test_traffic_learner.py
index 877ca2659..abb337c3e 100644
--- a/tests/test_memory/test_traffic_learner.py
+++ b/tests/test_memory/test_traffic_learner.py
@@ -867,6 +867,34 @@ class TestFlushToFile:
assert len(recs) == 1
assert "python3" in recs[0].content
+ @pytest.mark.asyncio
+ async def test_shutdown_flush_respects_min_evidence(self, tmp_path, monkeypatch):
+ """Regression: stop() must not bypass the evidence gate.
+
+ Earlier behavior collapsed min_evidence to 1 at shutdown, persisting
+ every singleton pattern. This is exactly inverted: singletons are the
+ *least* trustworthy patterns. The gate must use self._min_evidence at
+ all times, including stop()'s final flush.
+ """
+ writer = _FakeWriter()
+ proj = _make_project(str(tmp_path))
+ plugin = _FakePlugin(roots=[proj], writer=writer)
+ _install_plugin_registry(monkeypatch, plugin)
+
+ learner = TrafficLearner(backend=None, agent_type="claude", min_evidence=5)
+ # Singleton pattern: should NOT survive the shutdown flush.
+ learner._pattern_counts["h"] = (
+ ExtractedPattern(
+ category=PatternCategory.ENVIRONMENT,
+ content=f"singleton at {tmp_path}/main.py",
+ importance=0.5,
+ evidence_count=1,
+ ),
+ 1,
+ )
+ await learner.stop() # triggers a final flush_to_file
+ assert writer.calls == [], "singleton survived the shutdown gate"
+
@pytest.mark.asyncio
async def test_early_returns_no_plugin(self, monkeypatch):
"""No plugin detected → flush is a no-op."""