test: cover remaining branches flagged by Codecov patch coverage

Adds regression tests for the 9 lines Codecov flagged as uncovered in
the diff: the two early-return branches in
_get_model_group_custom_llm_provider (no model to infer from, and
get_llm_provider raising for an unrecognized model string), and the
Pydantic-object and pass-through branches in
_remove_foreign_thought_signatures_from_messages for both messages
and tool calls.
This commit is contained in:
Felix Mathew 2026-07-30 11:24:22 -05:00
parent bda6e9acfc
commit df504c49af
2 changed files with 71 additions and 0 deletions

View file

@ -202,6 +202,20 @@ class TestGetModelGroupCustomLlmProvider:
assert _get_model_group_custom_llm_provider(router, "unregistered-model") is None
def test_returns_none_when_deployment_has_no_model_to_infer_from(self):
router = RecordingRouter(deployments_by_model_group={"broken-model": [{"litellm_params": {}}]})
assert _get_model_group_custom_llm_provider(router, "broken-model") is None
def test_returns_none_when_provider_cannot_be_inferred_from_model_string(self):
router = RecordingRouter(
deployments_by_model_group={
"unrecognized-model": [{"litellm_params": {"model": "totally-unknown-nonexistent-model-xyz-123"}}]
}
)
assert _get_model_group_custom_llm_provider(router, "unrecognized-model") is None
class TestCrossesGeminiEndpointBoundary:
def test_true_between_vertex_ai_and_gemini(self):

View file

@ -14,8 +14,10 @@ import litellm
from litellm.proxy.utils import is_valid_api_key
from litellm.types.utils import (
CallTypes,
ChatCompletionMessageToolCall,
Delta,
LlmProviders,
Message,
ModelResponseStream,
StreamingChoices,
)
@ -4972,3 +4974,58 @@ class TestRemoveForeignThoughtSignaturesFromMessages:
result = _remove_foreign_thought_signatures_from_messages(messages, "__thought__")
assert result[0]["tool_call_id"] == "call_abc123"
def test_strips_signature_from_a_pydantic_message_object(self):
"""Real SDK responses hand back Message objects, not plain dicts, so
the model_dump() branch needs its own coverage."""
message = Message(
role="assistant",
content=None,
tool_calls=[
{
"id": "call_abc123__thought__VERTEX_SIG",
"type": "function",
"provider_specific_fields": {"thought_signature": "VERTEX_SIG"},
"function": {"name": "get_weather", "arguments": "{}"},
}
],
)
result = _remove_foreign_thought_signatures_from_messages([message], "__thought__")
tool_call = result[0]["tool_calls"][0]
assert tool_call["id"] == "call_abc123"
assert "thought_signature" not in tool_call["provider_specific_fields"]
def test_passes_through_a_message_that_is_neither_dict_nor_pydantic(self):
messages = ["not-a-message", {"role": "user", "content": "hello"}]
result = _remove_foreign_thought_signatures_from_messages(messages, "__thought__")
assert result[0] == "not-a-message"
assert result[1] == {"role": "user", "content": "hello"}
def test_strips_signature_from_a_pydantic_tool_call_object_inside_a_dict_message(self):
"""Some internal call sites build a dict message whose tool_calls
list holds real ChatCompletionMessageToolCall objects rather than
dicts, so that branch needs its own coverage too."""
tool_call = ChatCompletionMessageToolCall(
id="call_abc123__thought__VERTEX_SIG",
type="function",
function={"name": "get_weather", "arguments": "{}"},
)
tool_call.provider_specific_fields = {"thought_signature": "VERTEX_SIG"}
messages = [{"role": "assistant", "content": None, "tool_calls": [tool_call]}]
result = _remove_foreign_thought_signatures_from_messages(messages, "__thought__")
stripped_tool_call = result[0]["tool_calls"][0]
assert stripped_tool_call["id"] == "call_abc123"
assert "thought_signature" not in stripped_tool_call["provider_specific_fields"]
def test_passes_through_a_tool_call_that_is_neither_dict_nor_pydantic(self):
messages = [{"role": "assistant", "content": None, "tool_calls": ["not-a-tool-call"]}]
result = _remove_foreign_thought_signatures_from_messages(messages, "__thought__")
assert result[0]["tool_calls"] == ["not-a-tool-call"]