litellm/tests/test_litellm_rust/responses/test_requests.py
yujonglee 7d79ccb7cc
test(rust-bridge): select native routes per test without LITELLM_RUST (#46620)
* feat(rust-bridge): scope catalog rules with a contextvar

Co-Authored-By: Yujong Lee <yujong@berri.ai>

* test(rust-bridge): select native integration routes with scoped rules

Co-Authored-By: Yujong Lee <yujong@berri.ai>

* test(rust-bridge): run the Rust extension suite without LITELLM_RUST

Co-Authored-By: Yujong Lee <yujong@berri.ai>

* test(rust-bridge): use scoped catalog rules in dispatch tests

Co-Authored-By: Yujong Lee <yujong@berri.ai>

* refactor(rust-bridge): keep catalog rules a static global and override them once per test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 09:12:08 -07:00

54 lines
2 KiB
Python

import asyncio
from typing import Final
import pytest
from pydantic import TypeAdapter
import litellm
from litellm.responses.utils import ResponsesAPIRequestUtils
from litellm.types.llms.openai import ResponsesAPIResponse
from tests.test_litellm_rust.responses.data import RESPONSES_MODEL, RESPONSES_TEXT, call
from tests.test_litellm_rust.support.recording_server import RecordingServer
from tests.test_litellm_rust.support.routing import assert_served_natively
pytestmark = pytest.mark.requires_rust_extension
_OBJECT: Final = TypeAdapter(dict[str, object])
@pytest.mark.asyncio
@pytest.mark.parametrize("asynchronous", (False, True))
async def test_positional_parameters_reach_the_wire(server: RecordingServer, asynchronous: bool) -> None:
arguments: Final = ("hello", RESPONSES_MODEL, None, "Be brief", 16)
supplied: Final = {"api_key": "test-key", "api_base": server.base_url}
result: Final = (
await litellm.aresponses(*arguments, **supplied)
if asynchronous
else await asyncio.to_thread(litellm.responses, *arguments, **supplied)
)
assert isinstance(result, ResponsesAPIResponse)
assert result.output_text == RESPONSES_TEXT
assert_served_natively(server)
body: Final = _OBJECT.validate_python(server.requests[0].body)
assert body["instructions"] == arguments[3]
assert body["max_output_tokens"] == arguments[4]
@pytest.mark.asyncio
@pytest.mark.parametrize("asynchronous", (False, True))
@pytest.mark.parametrize("encoded", (False, True))
async def test_continuation_ids_are_decoded_before_they_reach_the_wire(
server: RecordingServer, asynchronous: bool, encoded: bool
) -> None:
original: Final = "resp_upstream"
previous: Final = (
ResponsesAPIRequestUtils._build_responses_api_response_id("openai", "deployment", original)
if encoded
else original
)
await call(server, asynchronous=asynchronous, previous_response_id=previous)
assert _OBJECT.validate_python(server.requests[0].body)["previous_response_id"] == original