litellm/tests/unit/responses
tavren27 77cf5c497f
fix(gemini): keep an empty trailing user turn so Gemini doesn't answer a model-turn 400 (#51311)
* fix(gemini): keep an empty trailing user turn so Gemini doesn't answer a model-turn 400

* fix(anthropic): keep an empty user message on the /v1/messages adapter so Gemini sees the user turn

* fix(gemini): add the blank user turn only for Gemini targets and fill an empty last user message with the continue message

The Responses bridge and the Anthropic Messages adapter now add back an empty
user message only when the target's chat config is Gemini's, the caller's last
message was an empty user message, and the converted request does not already
end on a user, tool or function message. With ensure_alternating_roles on, an
empty last user message is replaced by the continue message, and the continue
messages are copied so no request edits the shared default.

Ports 0a532277d8, f06c3b3893, 51c83ccd88 and fbc2df0e71 from the LTS branch.

* fix(gemini): send the blank user turn only for blank content and copy each inserted continue message

Drop the ensure_alternating_roles fill so alternating deployments of other providers keep the request they got before. Content of the wrong type keeps the base 400, and every inserted continue message is a fresh copy so a folded system prompt never reaches a later request

* fix(gemini): send the blank user turn only for the last user messages and catch every Gemini target in the bridges

* fix(responses): read a Vertex AI deployment's model_info.base_model when picking the Gemini route in the bridges

* fix(responses): keep an empty last user message for alternating Gemini deployments

The bridges dropped it when ensure_alternating_roles was set, so alternation sent the continue message on some shapes and the blank turn on others

* fix(gemini): send an alternating deployment's continue message for an empty last user message, and keep the user turn on adapter_completion

On an alternating Gemini deployment, completion() now drops an empty last user message so ensure_alternating_roles appends the configured user_continue_message, the same text /v1/messages already sent, on every route. adapter_completion, which proxy pass-through adapter targets use, now keeps the empty last user turn for Gemini like the /v1/messages handler

* test(gemini): flatten Gemini parts with chain.from_iterable in two tests

* fix(gemini): send a whitespace-only last Messages user turn to Gemini as a user turn

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-23 15:45:29 -08:00
..
litellm_completion_transformation 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
mcp 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
__init__.py ci: move provider-independent MCP tests into tests/unit and run mcp-integration from litellm-tests (#42904) 2026-09-24 23:07:48 +00:00
test_additional_tools.py feat(proxy): mixed Codex model picker and LiteLLM routing on native codex routes (#49408) 2026-11-06 11:14:47 -08:00
test_custom_tool_call.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_input_items_query.py fix(proxy): forward limit, order, after, before and include on GET /v1/responses/{id}/input_items (#51259) 2026-11-20 07:54:26 -08:00
test_instructions_length.py fix(responses): send bridged system prompts too long for instructions as input (#52964) 2026-11-20 11:56:47 -08:00
test_metadata_codex_callback.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_no_duplicate_spend_logs.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_null_test_fix.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_responses_api_bridge_flag.py fix(tool_choice): accept the Responses API's flat allowed_tools layout on chat completions (#50467) 2026-11-10 13:04:06 -08:00
test_responses_api_lifecycle.py fix(responses): log the resolved provider on Responses API calls (#52622) 2026-11-18 22:34:16 +00:00
test_responses_api_request_body.py fix(responses): log the resolved provider on Responses API calls (#52622) 2026-11-18 22:34:16 +00:00
test_responses_prompt_management.py fix(sdk): decide MCP gateway routing without importing the proxy handler (#45961) 2026-10-20 01:44:54 +00:00
test_responses_router_cooldown.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_responses_streaming_iterator.py fix(responses): resume background response streams with stream and starting_after (#48819) 2026-10-29 02:31:22 -07:00
test_responses_supported_endpoints_passthrough.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_responses_utils.py feat(gemini): support Gemini Live Avatar on Vertex AI realtime (#53270) 2026-11-21 15:06:59 -08:00
test_responses_websocket_all_providers.py fix(responses): replay tool calls a client answers in managed WebSocket history (#53410) 2026-11-22 22:23:30 +00:00
test_rust_bridge_websocket.py refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
test_sse_output_recovery.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_streaming_iterator.py fix(responses): encode ids on faked Responses streams and drop unmarked reasoning on affinity pins (#53746) 2026-11-23 09:43:29 -08:00
test_streaming_iterator_error_events.py fix(responses): surface mid-stream upstream errors that arrive without an event type (#50466) 2026-11-07 14:53:07 -08:00
test_text_format_conversion.py refactor: expose core private helpers under public names (#44871) 2026-10-07 00:05:27 +00:00