Repository navigation
test(integration): exact four-part translation cases on a shared fake provider and shared YAML deployment #44451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
12a4817
test(integration): exact four-part translation cases on a shared fake…
kerry-berri ae6ed76
test(integration): compare every non-transport provider header and ch…
kerry-berri b1c46c2
test(integration): name TranslationTestCase fields after litellm and …
kerry-berri 6e866cc
test(integration): prefix checked TranslationTestCase fields with exp…
kerry-berri e323739
docs(integration): name TranslationTestCase fields in the translation…
kerry-berri fffdcb1
test(integration): add a claude-opus-5-5 base case and deployment nex…
kerry-berri 9804606
test(integration): name translation cases <MODEL>_TEST_CASE and docum…
kerry-berri 502f51a
docs(integration): move translation test rules into tests/integration…
kerry-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| """The fake provider shared by every integration test that takes the `provider` fixture. | ||
|
|
||
| Deployments in `proxy_config.yaml` point at `PROVIDER_URL`, so one server answers for all of them. A test | ||
| queues the replies it expects with `expect` and reads what the proxy sent with `received`. Tests run one at a | ||
| time against it; the `provider` fixture checks nothing is left over between tests. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections import deque | ||
| from collections.abc import Iterator | ||
| from contextlib import contextmanager | ||
| from dataclasses import dataclass, field | ||
| from typing import Final | ||
|
|
||
| from tests.integration._support.wire import Reply, Request, Wire, wire_server | ||
|
|
||
| PROVIDER_PORT: Final = 8191 | ||
| PROVIDER_URL: Final = f"http://127.0.0.1:{PROVIDER_PORT}" | ||
| _UNQUEUED: Final = Reply(status=500, body=b'{"error": "the shared fake provider has no reply queued for this request"}') | ||
|
|
||
|
|
||
| @dataclass(slots=True) | ||
| class SharedProvider: | ||
| wire: Wire | ||
| replies: deque[Reply] | ||
| last_test: str | None = field(default=None) | ||
|
|
||
| def expect(self, *replies: Reply) -> None: | ||
| self.replies.extend(replies) | ||
|
|
||
| def received(self) -> tuple[Request, ...]: | ||
| return self.wire.drain() | ||
|
|
||
|
|
||
| @contextmanager | ||
| def shared_provider() -> Iterator[SharedProvider]: | ||
| replies: Final[deque[Reply]] = deque() | ||
|
|
||
| def respond(request: Request) -> Reply: | ||
| return replies.popleft() if replies else _UNQUEUED | ||
|
|
||
| with wire_server(respond, port=PROVIDER_PORT) as wire: | ||
| yield SharedProvider(wire, replies) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from collections.abc import Mapping | ||
| from dataclasses import dataclass | ||
|
|
||
| from pydantic import JsonValue | ||
|
|
||
|
|
||
| @dataclass(frozen=True, slots=True, kw_only=True) | ||
| class TranslationTestCase: | ||
| """One request through the proxy to a deployment in `proxy_config.yaml`: what the test sends to LiteLLM, the | ||
| exact request the provider must receive, the fake provider's reply, and the exact response LiteLLM must return.""" | ||
|
|
||
| scenario: str | ||
| litellm_endpoint: str | ||
| litellm_request: Mapping[str, JsonValue] | ||
| expected_provider_endpoint: str | ||
| expected_provider_headers: Mapping[str, str] | ||
| expected_provider_request: Mapping[str, JsonValue] | ||
| mock_provider_response: Mapping[str, JsonValue] | ||
| expected_litellm_status_code: int = 200 | ||
| expected_litellm_response: Mapping[str, JsonValue] | ||
|
|
||
| @property | ||
| def id(self) -> str: | ||
| return f"{self.litellm_request['model']}-{self.scenario}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import pytest | ||
|
|
||
| pytest.register_assert_rewrite("integration.translation.runner") |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from typing import Final | ||
|
|
||
| from integration.translation.case import TranslationTestCase | ||
|
|
||
| CLAUDE_SONNET_4_6: Final = TranslationTestCase( | ||
| scenario="basic", | ||
| litellm_endpoint="/v1/messages", | ||
| litellm_request={ | ||
| "model": "anthropic/claude-sonnet-4-6", | ||
| "max_tokens": 64, | ||
| "system": "You are a terse assistant.", | ||
| "messages": [{"role": "user", "content": "Say hello."}], | ||
| "cache": {"no-cache": True}, | ||
| }, | ||
| expected_provider_endpoint="/v1/messages", | ||
| expected_provider_headers={ | ||
| "x-api-key": "synthetic-anthropic-key", | ||
| "anthropic-version": "2023-06-01", | ||
| "content-type": "application/json", | ||
| }, | ||
| expected_provider_request={ | ||
| "model": "claude-sonnet-4-6", | ||
| "max_tokens": 64, | ||
| "stream": False, | ||
| "system": "You are a terse assistant.", | ||
| "messages": [{"role": "user", "content": "Say hello."}], | ||
| }, | ||
| mock_provider_response={ | ||
| "model": "claude-sonnet-4-6", | ||
| "id": "msg_011CffzUNHaEfzVxCh5hskBG", | ||
| "type": "message", | ||
| "role": "assistant", | ||
| "content": [{"type": "text", "text": "Hello!"}], | ||
| "container": None, | ||
| "stop_reason": "end_turn", | ||
| "stop_sequence": None, | ||
| "stop_details": None, | ||
| "usage": { | ||
| "input_tokens": 18, | ||
| "cache_creation_input_tokens": 0, | ||
| "cache_read_input_tokens": 0, | ||
| "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, | ||
| "output_tokens": 5, | ||
| "service_tier": "standard", | ||
| "inference_geo": "global", | ||
| }, | ||
| "diagnostics": None, | ||
| }, | ||
| expected_litellm_response={ | ||
| "model": "anthropic/claude-sonnet-4-6", | ||
| "id": "msg_011CffzUNHaEfzVxCh5hskBG", | ||
| "type": "message", | ||
| "role": "assistant", | ||
| "content": [{"type": "text", "text": "Hello!"}], | ||
| "container": None, | ||
| "stop_reason": "end_turn", | ||
| "stop_sequence": None, | ||
| "stop_details": None, | ||
| "usage": { | ||
| "input_tokens": 18, | ||
| "cache_creation_input_tokens": 0, | ||
| "cache_read_input_tokens": 0, | ||
| "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, | ||
| "output_tokens": 5, | ||
| "service_tier": "standard", | ||
| "inference_geo": "global", | ||
| }, | ||
| "diagnostics": None, | ||
| }, | ||
| ) |
Empty file.
11 changes: 11 additions & 0 deletions
11
tests/integration/translation/messages/basic/test_messages_basic_anthropic.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import pytest | ||
| from integration._support.client import Gateway | ||
| from integration._support.provider import SharedProvider | ||
| from integration.translation.case import TranslationTestCase | ||
| from integration.translation.messages.bases.anthropic import CLAUDE_SONNET_4_6 | ||
| from integration.translation.runner import run | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("case", [CLAUDE_SONNET_4_6], ids=lambda case: case.id) | ||
| def test_messages_basic_anthropic(case: TranslationTestCase, gateway: Gateway, provider: SharedProvider) -> None: | ||
| run(case, gateway, provider) |
Empty file.
72 changes: 72 additions & 0 deletions
72
tests/integration/translation/messages/reasoning/test_messages_reasoning_anthropic.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| from dataclasses import replace | ||
| from typing import Final | ||
|
|
||
| import pytest | ||
| from integration._support.client import Gateway | ||
| from integration._support.provider import SharedProvider | ||
| from integration.translation.case import TranslationTestCase | ||
| from integration.translation.messages.bases.anthropic import CLAUDE_SONNET_4_6 as BASE | ||
| from integration.translation.runner import run | ||
|
|
||
| SIGNATURE_1: Final = ( | ||
| "EpECCqgBCBIYAipAivUPApu85FYYe3+cXal8EiJOza7QGqKyekC8vDSn4oyeqGa2CrarO4abiuG7dzBXjmYR8+daw4h50ZjKmak7czIRY2xh" | ||
| "dWRlLXNvbm5ldC00LTY4AEIIdGhpbmtpbmdaJGQwMDgxZjJiLWQ5NjEtNGFhYi05ZTRjLTcxYmU3ZTA0ZTY3MJoBEwoRY2xhdWRlLXNvbm5l" | ||
| "dC00LTaoAY3fhdYGEgwJHsjNkCTlV9k1jWQaDOmeP/z67YtLTojSqCIwhRXGrNzSuGfMD1HqA72lctQCy83Wkr0u8W5lBXXn+MD6WfJGTJqM" | ||
| "1FW7qRmOMOKJKhbheeMpsTs7XvdvsiDQqgM4PAJt4cwgGAE=" | ||
| ) | ||
|
|
||
| THINKING_BUDGET: Final = replace( | ||
| BASE, | ||
| scenario="thinking_budget", | ||
| litellm_request={ | ||
| **BASE.litellm_request, | ||
| "max_tokens": 2048, | ||
| "thinking": {"type": "enabled", "budget_tokens": 1024}, | ||
| }, | ||
| expected_provider_request={ | ||
| **BASE.expected_provider_request, | ||
| "max_tokens": 2048, | ||
| "thinking": {"type": "enabled", "budget_tokens": 1024}, | ||
| }, | ||
| mock_provider_response={ | ||
| **BASE.mock_provider_response, | ||
| "id": "msg_011CffzUREgTzMm1dXRqP2LR", | ||
| "content": [ | ||
| {"type": "thinking", "thinking": "Hello!", "signature": SIGNATURE_1}, | ||
| {"type": "text", "text": "Hello!"}, | ||
| ], | ||
| "usage": { | ||
| "input_tokens": 47, | ||
| "cache_creation_input_tokens": 0, | ||
| "cache_read_input_tokens": 0, | ||
| "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, | ||
| "output_tokens": 15, | ||
| "output_tokens_details": {"thinking_tokens": 7}, | ||
| "service_tier": "standard", | ||
| "inference_geo": "global", | ||
| }, | ||
| }, | ||
| expected_litellm_response={ | ||
| **BASE.expected_litellm_response, | ||
| "id": "msg_011CffzUREgTzMm1dXRqP2LR", | ||
| "content": [ | ||
| {"type": "thinking", "thinking": "Hello!", "signature": SIGNATURE_1}, | ||
| {"type": "text", "text": "Hello!"}, | ||
| ], | ||
| "usage": { | ||
| "input_tokens": 47, | ||
| "cache_creation_input_tokens": 0, | ||
| "cache_read_input_tokens": 0, | ||
| "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0}, | ||
| "output_tokens": 15, | ||
| "output_tokens_details": {"thinking_tokens": 7}, | ||
| "service_tier": "standard", | ||
| "inference_geo": "global", | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("case", [THINKING_BUDGET], ids=lambda case: case.id) | ||
| def test_messages_reasoning_anthropic(case: TranslationTestCase, gateway: Gateway, provider: SharedProvider) -> None: | ||
| run(case, gateway, provider) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import json | ||
| from typing import Final | ||
|
|
||
| from integration._support.client import Gateway | ||
| from integration._support.provider import SharedProvider | ||
| from integration._support.wire import Reply | ||
| from integration.translation.case import TranslationTestCase | ||
|
|
||
| TRANSPORT_HEADERS: Final = frozenset({"host", "accept", "accept-encoding", "connection", "content-length", "user-agent"}) | ||
|
|
||
|
|
||
| def run(case: TranslationTestCase, gateway: Gateway, provider: SharedProvider) -> None: | ||
| provider.expect(Reply(body=json.dumps(case.mock_provider_response).encode())) | ||
| response: Final = gateway.request("POST", case.litellm_endpoint, case.litellm_request) | ||
| received: Final = provider.received() | ||
| assert [(request.method, request.target) for request in received] == [("POST", case.expected_provider_endpoint)] | ||
| sent: Final = received[0] | ||
| assert {name: value for name, value in sent.headers.items() if name not in TRANSPORT_HEADERS} == dict(case.expected_provider_headers) | ||
| assert json.loads(sent.body) == case.expected_provider_request | ||
| assert response.status_code == case.expected_litellm_status_code, response.text | ||
| assert response.json() == case.expected_litellm_response |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_UNQUEUEDis defined in this module and returned when no provider reply is queued. The repository requires sentinel-like variables to be defined inconstants.pyinstead. Please satisfy that requirement before merging.Rule Used: What: Require sentinel-like variables (e.g.,
_NEGATIVE_TEAM_SENTINEL) to be defined inconstants.pyinstead of inline or in other modules. Why: Centralizing shared constants prevents duplication, inconsistencies, and makes future changes safer ... (source)Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a test-only fake reply, so litellm/constants.py would ship it in the package; tests/integration/_support keeps private constants local, like _NO_MARKER
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right.
_UNQUEUEDis private state for the integration-only fake provider, and moving it intolitellm/constants.pywould unnecessarily ship a test sentinel with the package. The existing_NO_MARKERpattern intests/integration/_supportsupports keeping these test-only constants local, so this comment can be disregarded.