test(rust): cover debug bridge forwarding

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>
This commit is contained in:
Devin AI 2026-07-29 22:57:50 +00:00
parent 78ec7a6ba3
commit d857e6ab0f

View file

@ -7,6 +7,7 @@ import httpx
import pytest
import litellm
from litellm import _logging
from litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandler
from litellm.types.llms.anthropic_messages.anthropic_response import (
AnthropicMessagesResponse,
@ -89,6 +90,44 @@ class RecordingAsyncMessages:
return dict(FAKE_MESSAGES_RESPONSE)
class DebugRecordingMessages:
def __init__(self) -> None:
self.debug: bool | None = None
def __call__(
self,
model: str,
body: dict[str, object],
api_key: str | None,
api_base: str | None,
custom_llm_provider: str | None,
extra_headers: dict[str, object] | None,
timeout_seconds: float | None,
debug: bool,
) -> dict[str, object]:
self.debug = debug
return dict(FAKE_MESSAGES_RESPONSE)
class DebugRecordingAsyncMessages:
def __init__(self) -> None:
self.debug: bool | None = None
async def __call__(
self,
model: str,
body: dict[str, object],
api_key: str | None,
api_base: str | None,
custom_llm_provider: str | None,
extra_headers: dict[str, object] | None,
timeout_seconds: float | None,
debug: bool,
) -> dict[str, object]:
self.debug = debug
return dict(FAKE_MESSAGES_RESPONSE)
class ExplodingAsyncMessages:
def __init__(self) -> None:
self.calls = 0
@ -195,6 +234,26 @@ def test_messages_wrapper_forwards_args_and_converts_timeout():
}
def test_messages_wrapper_forwards_debug_to_new_bridge():
bridge = DebugRecordingMessages()
litellm.use_litellm_rust(True, messages=bridge)
litellm._turn_on_debug()
try:
response = rust_messages.messages(
model="claude-sonnet-4-5",
body=REQUEST_BODY,
api_key="sk-azure",
api_base="https://resource.services.ai.azure.com/anthropic",
custom_llm_provider="azure_ai",
extra_headers=None,
timeout=12.5,
)
finally:
_logging._disable_debugging()
assert response == FAKE_MESSAGES_RESPONSE
assert bridge.debug is True
@pytest.mark.asyncio
async def test_amessages_wrapper_forwards_args():
bridge = RecordingAsyncMessages()
@ -215,6 +274,27 @@ async def test_amessages_wrapper_forwards_args():
assert bridge.calls[0]["timeout_seconds"] == 12.5
@pytest.mark.asyncio
async def test_amessages_wrapper_forwards_debug_to_new_bridge():
bridge = DebugRecordingAsyncMessages()
litellm.use_litellm_rust(True, amessages=bridge)
litellm._turn_on_debug()
try:
response = await rust_messages.amessages(
model="claude-sonnet-4-5",
body=REQUEST_BODY,
api_key="sk-azure",
api_base="https://resource.services.ai.azure.com/anthropic",
custom_llm_provider="azure_ai",
extra_headers=None,
timeout=12.5,
)
finally:
_logging._disable_debugging()
assert response == FAKE_MESSAGES_RESPONSE
assert bridge.debug is True
def _gate(**overrides):
kwargs = {
"custom_llm_provider": "azure_ai",