headroom/tests/test_transforms
chopratejas d7d50fef60 fix: Extend Anthropic format tool protection to IntelligentContextManager
Follows up on PR #19 which fixed RollingWindow but missed IntelligentContextManager,
the default context manager used by the proxy.

Changes:
1. intelligent_context.py: Extended `_get_protected_indices()` to handle Anthropic format:
   - Scan assistant.content for type="tool_use" blocks
   - Protect user messages containing type="tool_result" blocks with matching tool_use_id

2. test_intelligent_context.py: Added TestAnthropicFormatToolProtection class with 5 tests:
   - test_anthropic_tool_result_protected_when_tool_use_protected
   - test_anthropic_tool_units_dropped_atomically
   - test_anthropic_multiple_tools_same_message_atomic
   - test_anthropic_format_no_api_error_scenario (verifies bug fix)
   - test_mixed_openai_and_anthropic_formats

3. test_rolling_window.py: Added matching TestAnthropicFormatToolProtection class with 5 tests
   - Added skip decorator for CI/CD when OPENAI_API_KEY is not set

This ensures both context managers (RollingWindow and IntelligentContextManager) correctly
handle Anthropic's native tool_use/tool_result format, preventing the
"unexpected tool_use_id found in tool_result blocks" API error.
2026-02-01 12:27:17 -08:00
..
__init__.py Initial commit: Headroom SDK - LLM context optimization toolkit 2026-01-06 23:16:58 -08:00
test_anchor_selector.py Add reasoning capability forwarding to HeadroomAgnoModel 2026-01-21 20:32:02 -08:00
test_cache_aligner.py Integrate DynamicContentDetector into CacheAligner (Phase 1) 2026-01-19 22:56:20 -08:00
test_code_compressor.py Integrate DynamicContentDetector into CacheAligner (Phase 1) 2026-01-19 22:56:20 -08:00
test_content_router.py fix(tests): add missing skip decorator and tests for exclude_tools 2026-01-31 17:44:03 -08:00
test_diff_compressor.py Add DiffCompressor and fix hnswlib SIGILL crash on CI 2026-01-31 08:09:55 -08:00
test_html_extractor.py fix(tests): skip HTML extractor tests when trafilatura not installed 2026-01-31 15:39:55 -08:00
test_intelligent_context.py fix: Extend Anthropic format tool protection to IntelligentContextManager 2026-02-01 12:27:17 -08:00
test_llmlingua_compressor.py Add comprehensive evaluation framework for compression accuracy 2026-01-22 09:31:54 -08:00
test_progressive_summarizer.py Add quality retention eval and fix linting for Python 3.12 2026-01-19 21:52:18 -08:00
test_rolling_window.py fix: Extend Anthropic format tool protection to IntelligentContextManager 2026-02-01 12:27:17 -08:00
test_scoring.py Add IntelligentContextManager for semantic-aware context management 2026-01-18 22:22:48 -08:00
test_smart_crusher.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00
test_tool_crusher.py Fix all ruff lint and format errors for CI 2026-01-10 15:33:44 -08:00