litellm/tests/unit/responses/litellm_completion_transformation
joshua-berri a479cbb0c2
fix(caching): preserve caller message limits across chat bridges (#54500)
* fix(caching): count the caller's messages for max_messages on the chat completion bridges

responses() and anthropic.messages on providers that bridge to completion()
checked max_messages against the translated chat messages, so 5 Responses
items with grouped function calls were cached and 3 Anthropic messages with
3 tool results never were. Each bridge now stamps the caller's count into
the inner call's cache controls as a frozen CallerMessageCount, which the
cache gate reads before counting the request. A count an outer bridge
already stamped is kept, a forged int or dict under the key is ignored,
and string Responses input stays unstamped so it keeps its current gate.

* test(caching): cover string input, system prompts and async writes on the chat completion bridges

Restrict the cache to completion call types so the outer Responses and
Messages caches cannot hide the inner gate, and check that string Responses
input keeps its chat message count at max_messages 0 and 1, that a separate
system prompt is not a caller message, and that async Messages under the
limit is cached. Async tests now await cache writes and flush the logging
worker in a finally block.

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-11-25 13:06:17 -08:00
..
__init__.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_anthropic_responses_bridge.py feat(responses): store each bridged turn's path to the root so a fork replays only its ancestors (#49519) 2026-11-23 12:43:11 -08:00
test_client_tool_search.py fix(responses): one answer for which tool a bridged call is, read by the reply, tool permission and spend logs (#53269) 2026-11-24 22:26:42 +00:00
test_compaction_items.py fix(responses): answer Codex compaction_trigger on the chat-completions bridge (#53266) 2026-11-21 14:53:31 -08:00
test_compaction_trigger.py fix(responses): answer Codex compaction_trigger on the chat-completions bridge (#53266) 2026-11-21 14:53:31 -08:00
test_count_request.py fix(bedrock): stop the prefill 400 when the last user message is empty (#50701) 2026-11-18 03:44:11 +00:00
test_function_call_output_normalization.py fix(responses): preserve deferred tool references on Anthropic routes (#52977) 2026-11-19 15:55:31 -08:00
test_google_ai_studio_responses_bridge.py test: move the unit half of 126 mixed legacy files into tests/unit (#45090) 2026-10-07 14:07:43 -07:00
test_google_ai_studio_responses_wire.py fix(gemini): keep an empty trailing user turn so Gemini doesn't answer a model-turn 400 (#51311) 2026-11-23 15:45:29 -08:00
test_handler.py fix(caching): preserve caller message limits across chat bridges (#54500) 2026-11-25 13:06:17 -08:00
test_image_generation_output.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_litellm_completion_responses.py fix(responses): reject an unresolvable previous_response_id on the chat completions bridge (#53766) 2026-11-25 13:32:42 +00:00
test_reasoning_input_item_preservation.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_reasoning_items.py feat(proxy): mixed Codex model picker and LiteLLM routing on native codex routes (#49408) 2026-11-06 11:14:47 -08:00
test_session_handler.py fix(responses): keep sent tool names in cold storage replay and guardrail rewrites (#54240) 2026-11-25 05:41:32 +00:00
test_session_handler_with_cold_storage.py refactor(s3-log): move the rust-backed s3 logger from s3_v3 to s3_v2 (#51893) 2026-11-14 22:24:23 -08:00
test_streaming_iterator_transformation.py fix(vertex_ai): keep Gemini 3+ web search next to function tools and report searches as web_search_call items (#53423) 2026-11-23 07:29:54 +00:00
test_tool_output_order_preserved_for_gemini.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00