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.

fix(tests): repair three main-branch test failures (#2306)

Tejas Chopra1d79e70f9598
diff --git a/tests/test_anthropic_compaction_transforms.py b/tests/test_anthropic_compaction_transforms.py
index f2f078eaa..5eb658924 100644
--- a/tests/test_anthropic_compaction_transforms.py
+++ b/tests/test_anthropic_compaction_transforms.py
@@ -114,13 +114,18 @@ class TestAnthropicToolDescCompactionTransforms:
``anthropic:tool_desc_compaction`` must appear in ``transforms_applied``."""
def test_l2_appends_transform_label(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ import headroom.proxy.tool_schema_compaction as _mod
from headroom.proxy.tool_schema_compaction import (
compact_tool_descriptions,
tool_desc_max_chars,
)
- # Opt-in with a very short max so truncation triggers.
+ # Opt-in with a very short max so truncation triggers. Reset the
+ # per-process cache first: an earlier test in the shard may have read
+ # the (unset) env and pinned max_chars to 0, which would swallow our
+ # setenv below.
monkeypatch.setenv("HEADROOM_TOOL_DESC_MAX_CHARS", "20")
+ _mod._TOOL_DESC_MAX_CHARS = None
payload = _make_anthropic_payload_with_tools()
max_chars = tool_desc_max_chars()
@@ -129,6 +134,8 @@ class TestAnthropicToolDescCompactionTransforms:
body, modified, before, after = compact_tool_descriptions(payload, max_chars)
assert modified is True
assert before > after
+ # Don't leak the cached 20 into later tests in this shard.
+ _mod._TOOL_DESC_MAX_CHARS = None
def test_l2_skips_label_when_disabled(self) -> None:
import headroom.proxy.tool_schema_compaction as _mod
diff --git a/tests/test_proxy_dashboard_stats_cache.py b/tests/test_proxy_dashboard_stats_cache.py
index ece4c0ef7..484b4a55c 100644
--- a/tests/test_proxy_dashboard_stats_cache.py
+++ b/tests/test_proxy_dashboard_stats_cache.py
@@ -740,7 +740,9 @@ def test_dashboard_uses_cached_stats_and_lazy_history_feed_polling() -> None:
assert "Lean-ctx" in html
assert "Context Tool" in html
assert "cliFilteringLabel + ' Filtered (this session)'" in html
- assert "cliFilteringLabel + ' Filtered (lifetime)'" in html
+ # Lifetime CLI-filtering savings moved from the session card to the
+ # history tab as "Lifetime Saved" in #2198 (persist lifetime metrics).
+ assert "cliFilteringLabel) + ' Lifetime Saved'" in html
def test_dashboard_session_metrics_do_not_repeat_proxy_tokens_without_new_context() -> None:
diff --git a/tests/test_transforms_content_router.py b/tests/test_transforms_content_router.py
index 3e478fc74..92dbea334 100644
--- a/tests/test_transforms_content_router.py
+++ b/tests/test_transforms_content_router.py
@@ -693,11 +693,14 @@ def test_smart_crusher_log_fallback_runs_for_valid_json(
monkeypatch.setattr(router, "_get_smart_crusher", lambda: NoopSmartCrusher())
monkeypatch.setattr(router, "_get_log_compressor", lambda: ShrinkingLogCompressor())
- # Kompress no-op → Log fallback fires.
+ # Kompress no-op → Log fallback fires. A faithful no-op reports the same
+ # token count the router computed for the (unchanged) content — using
+ # _estimate_tokens, not a naive word split, so it isn't mistaken for a
+ # saving once #1857's whitespace-aware counting rates the JSON above 8.
monkeypatch.setattr(
router,
"_try_ml_compressor",
- lambda content, context, question=None: (content, len(content.split())),
+ lambda content, context, question=None: (content, _estimate_tokens(content)),
)
compressed, _compressed_tokens, strategy_chain = router._apply_strategy_to_content(