litellm/tests/unit/rust_bridge/test_public_call.py
yujonglee 1bc85fad40
refactor(python-bridge): ship a signature base and read the resolved call (#45450)
* refactor(python-bridge): ship a signature base and read the resolved call

NativeCall carries base (positionals by name plus signature defaults) instead
of the fully bound dict. resolved lays kwargs over base, which is what bound
held, so every pre-hook read and every route host keeps seeing the same values.

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

* fix(bedrock): build the transcription NativeCall with an empty base

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

* test(dispatch): read the resolved call instead of bound

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

* refactor(host-python): rename effective to effective_py_args and note the shallow copy

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

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

64 lines
2 KiB
Python

from collections.abc import Mapping, Sequence
from typing import Final
import pytest
from litellm.rust_bridge.public_call import native_call, signature
def _messages(
max_tokens: int,
messages: Sequence[object],
model: str,
temperature: float | None = None,
api_key: str | None = None,
**kwargs: object, # kwargs-ok: exercise the public signature binding contract
) -> None:
return None
_SIGNATURE: Final = signature(_messages)
@pytest.mark.parametrize("supplied", ({}, {"api_key": None}, {"api_key": "explicit"}))
def test_base_holds_positionals_and_defaults_and_never_a_keyword(supplied: Mapping[str, object]) -> None:
messages: Final[Sequence[object]] = [{"role": "user", "content": "hello"}]
args: Final = (128, messages, "model", 0.25)
call: Final = native_call(_SIGNATURE, args, supplied)
assert call.args is args
assert call.kwargs is supplied
assert call.base == {
"max_tokens": 128,
"messages": messages,
"model": "model",
"temperature": 0.25,
"api_key": None,
}
assert call.base["messages"] is messages
assert call.resolved["api_key"] == supplied.get("api_key")
assert ("api_key" in call.kwargs) == ("api_key" in supplied)
def test_resolved_lays_the_keywords_over_the_base_and_equals_the_full_binding() -> None:
messages: Final[Sequence[object]] = []
metadata: Final = {"trace": "caller"}
supplied: Final = {"model": "keyword-model", "metadata": metadata}
args: Final = (128, messages)
call: Final = native_call(_SIGNATURE, args, supplied)
assert "model" not in call.base
assert "kwargs" not in call.base
assert "metadata" not in call.base
assert call.resolved == {
"max_tokens": 128,
"messages": messages,
"model": "keyword-model",
"temperature": None,
"api_key": None,
"metadata": metadata,
}
assert call.resolved["metadata"] is metadata
assert supplied == {"model": "keyword-model", "metadata": metadata}