Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(rust): enforce shared upstream error contract in wheel checks (#43520)

devin-ai-integration[bot]c60c714278d9
diff --git a/tests/unit/rust_bridge/native_route_wheel_test.py b/tests/unit/rust_bridge/native_route_wheel_test.py
index 0b442f1f269..a665418e511 100644
--- a/tests/unit/rust_bridge/native_route_wheel_test.py
+++ b/tests/unit/rust_bridge/native_route_wheel_test.py
@@ -153,13 +153,8 @@ def success_value(route: str, response: dict[object, object]) -> object:
return response["choices"][0]["message"]["content"]
-def assert_rate_limit(native: object, route: str, error: BaseException) -> None:
- if route == "chat_completions":
- upstream_error: Final = native.RustUpstreamError
- if not isinstance(error, upstream_error) or error.args[0] != 429:
- raise AssertionError(f"{route} returned the wrong 429 error: {error!r}")
- return
- if not isinstance(error, RuntimeError) or "429" not in str(error):
+def assert_rate_limit(route: str, error: BaseException) -> None:
+ if error.args != (429, native_response(429, route).decode()):
raise AssertionError(f"{route} returned the wrong 429 error: {error!r}")
@@ -169,8 +164,8 @@ def exercise_sync(native: object, api_base: str) -> None:
assert_success(route, function(**route_kwargs(route, api_base, "success")))
try:
function(**route_kwargs(route, api_base, "429"))
- except (RuntimeError, native.RustUpstreamError) as error:
- assert_rate_limit(native, route, error)
+ except native.RustUpstreamError as error:
+ assert_rate_limit(route, error)
else:
raise AssertionError(f"{route} accepted a 429 response")
@@ -181,8 +176,8 @@ async def exercise_async(native: object, api_base: str) -> None:
assert_success(route, await function(**route_kwargs(route, api_base, "success")))
try:
await function(**route_kwargs(route, api_base, "429"))
- except (RuntimeError, native.RustUpstreamError) as error:
- assert_rate_limit(native, route, error)
+ except native.RustUpstreamError as error:
+ assert_rate_limit(route, error)
else:
raise AssertionError(f"a{route} accepted a 429 response")