mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 15:10:00 +08:00
feat/https-compose-caddy
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
1b7466d1d7 |
test(integrations): drop duplicated LangChain and LiteLLM tests (#4133)
## Description
This PR removes duplicated tests for the LangChain and LiteLLM
integrations. It changes no product code.
- **`tests/test_integrations/langchain/test_extended.py`** repeated
tests for:
- `HeadroomChatMessageHistory`
- `HeadroomDocumentCompressor`
- `HeadroomToolWrapper`
- the streaming metrics tracker
The per-module test files already cover all four. Line and branch
coverage of `headroom/integrations/langchain` is identical with and
without these tests.
- **The LiteLLM tests removed** only asserted `hasattr`, `callable` or
not-None on hooks that other tests in the same files call and await.
Refs #4136
## Type of Change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [x] Code refactoring (no functional changes)
## Changes Made
- `test_extended.py`: delete these classes:
- `TestHeadroomChatMessageHistory` (5 tests)
- `TestHeadroomDocumentCompressor` (7)
- `TestStreamingMetricsTracker` (8)
- 5 of the 6 `TestHeadroomToolWrapper` tests
- Kept from `TestHeadroomToolWrapper`:
`test_call_compresses_large_json`. It is the only LangChain test that
runs `compress_tool_result` unmocked. It is also the only test in this
set that reaches the non-JSON fallback in
`headroom/integrations/mcp/server.py:343-344`;
`tests/test_integrations/mcp` does not cover those lines.
- Also kept: `TestProviderDetection`,
`TestHeadroomLangSmithCallbackHandler` and
`TestAutoDetectProviderInChatModel`. They are the only coverage for
`providers.py` and `langsmith.py`.
- Moved, not deleted: `test_output_tokens` and
`test_messages_passthrough_under_threshold`. Every other memory and
streaming test passes a mock provider or patches `OpenAIProvider`; these
two were the only ones that ran the real default provider
(`OpenAIProvider().get_token_counter(model)`) end to end. They now live
next to their siblings:
-
`test_streaming.py::TestStreamingMetricsTrackerProperties::test_output_tokens_with_default_provider`
-
`test_memory.py::TestHeadroomChatMessageHistoryMessages::test_messages_below_threshold_with_default_provider`
- The `langchain_core` availability probe now imports the package
instead of 4 names that are no longer used.
- `tests/test_litellm_callback.py`: delete
`test_instantiates_without_error`,
`test_has_async_post_call_success_hook`,
`test_async_post_call_success_hook_is_callable` and
`test_async_pre_call_hook_still_works`. Still covered by:
- `test_async_post_call_success_hook_does_not_raise`;
- `test_all_current_litellm_async_hooks_present`;
- the route tests that await `async_pre_call_hook`.
- `tests/test_integrations/test_litellm_callback.py`: delete
`test_method_exists` and `test_method_is_coroutine`.
`test_returns_response_unchanged` awaits the same hook.
## Testing
- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [ ] New tests added for new functionality
- [x] Manual testing performed
### Test Output
```text
$ pytest tests/test_integrations/langchain/test_extended.py tests/test_litellm_callback.py tests/test_integrations/test_litellm_callback.py
origin/main: 59 passed
this branch: 28 passed (31 removed: 25 + 4 + 2)
$ pytest <the same 3 files> tests/test_integrations/langchain/test_memory.py tests/test_integrations/langchain/test_streaming.py
origin/main: 124 passed
this branch: 95 passed (29 fewer: 31 removed, 2 moved into test_memory.py / test_streaming.py)
# coverage evidence, on origin/main (coverage run --branch over tests/test_integrations/langchain, 244 passed / 21 skipped)
headroom/integrations/langchain/* with the 26 tests: 1150 stmts, 161 miss, 346 branches, 52 partial
headroom/integrations/langchain/* without the 26 tests: 1150 stmts, 161 miss, 346 branches, 52 partial
# the only difference outside langchain/ in that run: mcp/server.py 343-344, sqlite.py, compression_store.py, toin.py
# per-test check: mcp/server.py 343-344 come from test_call_compresses_large_json, which this branch keeps.
# The sqlite/compression_store/toin lines are side effects of real compression; their own test suites own them.
$ uvx ruff@0.16.8 check / format <3 touched files> -> All checks passed! / unchanged
```
## Real Behavior Proof
- Environment: macOS, Python 3.12, repo venv (langchain-core and litellm
installed).
- Exact command / steps:
- `python -m coverage run --branch -m pytest -p no:cov
tests/test_integrations/langchain`, with and without `--deselect` of the
four classes, then `coverage report -m` and a diff.
- `pytest-cov` breaks the litellm import (`KeyError:
'pydantic.root_model'`), so coverage was run directly.
- Observed result: identical numbers for
`headroom/integrations/langchain`. The one test that adds unique
coverage elsewhere is kept.
- Smoke harness (real proxy started from this checkout against a local
fake upstream; temp HOME and workspace, offline):
```text
branch: cleanup/cli-integrations-dedupe-integration-tests @
|
||
|
|
63c5df8a39 |
fix(litellm): compress anthropic messages route in HeadroomCallback (#3504)
## Description Closes #3503 LiteLLM's proxy maps /v1/messages and /anthropic/v1/messages to the `anthropic_messages` call type (`aanthropic_messages` for the async path), but `HeadroomCallback.async_pre_call_hook` only accepted `completion` and `acompletion`, so every request through the Anthropic Messages route exited at the call-type gate and no compression ran at all the payload on that route still carries `messages` in Anthropic format and `compress()` already handles that shape, so the gate now accepts the two anthropic call types next to the existing two ### Steps to reproduce 1. build a `HeadroomCallback()` and call `async_pre_call_hook(user_api_key_dict={}, cache=None, data=<anthropic payload with a 200-row JSON tool_result block>, call_type="anthropic_messages")` 2. Expected: the tool_result content gets compressed and `total_tokens_saved` grows 3. Actual (raw output on untouched main |
||
|
|
8527b910dc | test(litellm): remove unused pytest import | ||
|
|
9be727de68 |
fix(litellm): inherit CustomLogger so future hooks don't crash proxy (#1114) (#1391)
## Summary Fixes #1114 — LiteLLM 1.89.x added `async_post_call_success_hook` and started calling it after every successful completion. `HeadroomCallback` was a plain `object` subclass with no such method, causing: ``` AttributeError: type object 'HeadroomCallback' has no attribute 'async_post_call_success_hook' ``` This crashed the LiteLLM proxy on every successful API call. ### Root cause ```python class HeadroomCallback: # plain object — no-op hooks not inherited ... ``` ### Fix Inherit from `litellm.integrations.custom_logger.CustomLogger` which provides no-op defaults for every hook it defines. Future additions to `CustomLogger` will be covered automatically. ```python try: from litellm.integrations.custom_logger import CustomLogger as _CustomLogger except ImportError: _CustomLogger = object # litellm not installed — graceful fallback class HeadroomCallback(_CustomLogger): ... def __init__(self, ...): super().__init__() ... ``` ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) ## Changes Made - `headroom/integrations/litellm_callback.py` — inherit `CustomLogger`; add `super().__init__()` - `tests/test_litellm_callback.py` — 7 tests: instantiation, `async_post_call_success_hook` present + callable + no-op, all current hooks present, pre-call hook still works ## Real behavior proof **Setup:** Python 3.13, litellm 1.89.1, headroom-ai 0.27.0-dev **Steps after patch:** ```bash python3 -c " from headroom.integrations.litellm_callback import HeadroomCallback import asyncio cb = HeadroomCallback() # Simulate what litellm proxy calls on success asyncio.run(cb.async_post_call_success_hook(data={}, user_api_key_dict={}, response=None)) print('OK — no AttributeError') " ``` **After-fix evidence:** Runs without exception. Before fix: `AttributeError: type object 'HeadroomCallback' has no attribute 'async_post_call_success_hook'`. **What I did not test:** Live LiteLLM proxy with YAML config (no LiteLLM proxy running in test env); tested via unit tests and direct Python instantiation. ## Test Results ``` tests/test_litellm_callback.py 7/7 passed ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) |