litellm/tests/unit/rust_bridge
Nate Armstrong 1c45174926
fix(messages): close high and medium rust messages parity bugs (#52042)
* fix(messages): sign bedrock invoke with sigv4 when api_key is empty

With api_key set to an empty string and AWS_BEARER_TOKEN_BEDROCK in the env, the handler dropped the empty key before it reached the Bedrock Invoke config, so Rust read the env token and sent it as a bearer. Python's bedrock_bearer_token treats an empty key as no bearer without reading the env and signs the call with SigV4. The empty key is now dropped only when the azure_ai module api_key fallback is in play. Fixes AUTH-084, AUTH-049 and BI-021.

* fix(messages): guard the anthropic env base like a caller api_base

With no caller api_base, an anthropic call took its base from ANTHROPIC_API_BASE or ANTHROPIC_BASE_URL in Rust, and the host's malformed-base guard only looked at the caller api_base. So ANTHROPIC_API_BASE=http:///d/anthropic was parsed by the native client as host d, and a user:pass@h base went to h, both with the operator x-api-key. Rust also skipped a whitespace-only ANTHROPIC_API_BASE and fell through to ANTHROPIC_BASE_URL or api.anthropic.com. Python resolves api_base or get_secret_str("ANTHROPIC_API_BASE") or get_secret_str("ANTHROPIC_BASE_URL") and hands the result to its HTTP client, which refuses those URLs, and keeps a whitespace-only value so the call fails locally. The host now resolves the anthropic env base the same way, runs it through the guard so these bases post through Python's client, and seeds the values it read into the native route. Rust now only skips an empty env base, as Python does. Catalog ids ANT-012, ANT-009, ANT-010 (ruling R1)

* fix(messages): bound connect and response head per phase and retry a failed connect once

A native Messages call whose TCP connect never completes was bounded by a fixed 10 s client connect cap and by one tokio timeout over connect plus response head, so it failed as a read timeout that the proxy billed at the prompt estimate, and a connect error was never retried. Python bounds connect by the call timeout (5 s when none is set) and the head by the read timeout separately, raises ConnectTimeout labelled Connection that is not billed, and its async client retries a ConnectError once. Rust now applies a per-call connect bound through a connector layer, times the head from when the connection is ready, and retries a failed connect once on async calls. Catalog ids ERR-082, ERR-083, ERR-084, ERR-088, COST-073, RTR-066.

* fix(messages): give the agentic follow-up the caller's system, not the hoisted wire system

With system "S" and a leading role system turn "R" on azure_ai or bedrock_invoke, the Rust host built the agentic follow-up params from the upstream wire body, whose system was already hoisted to [S, R], while replaying the un-hoisted messages, so the follow-up hoisted R again and sent [S, R, R]. Python hands its follow-up the caller's request params, whose system is still S, since the hoist only rewrites the transformed request, so the follow-up sends [S, R]. The host now takes system from the caller's requested params whenever the wire body carries one. AZ-091. ANT-085 is left as is: Python's transform pops max_tokens from the same params dict it later hands the agentic hooks, so Python's follow-up also falls back to 1024 or budget plus 1024, which the host already matches.

* fix(messages): keep explicit nulls in typed request fields on the wire

A request carrying cache_control null or cache_control.ttl null, tool_result.content or tool_use.input null, a block type null, output_config.effort or format null, thinking.display null, or context_management.edits null lost those keys in the Rust typed round-trip, and with output_config.effort null plus reasoning_effort Rust filled in the mapped effort. Python forwards these dicts as sent and its setdefault keeps the null effort. The fields now deserialize an explicit null into a kept value through the recognized helpers, as budget_tokens already does, while beta selection and effort decisions still read null as unset like Python's get checks. Catalog ids SHAPE-078, SHAPE-112, SHAPE-132, SHAPE-133.

* fix(messages): add the anthropic oauth beta when the oauth key comes from ANTHROPIC_API_KEY

With no caller api_key and ANTHROPIC_API_KEY=sk-ant-oat01-..., or with an api_key that only matches
the OAuth prefix after trimming, Rust sent the token as a bearer without anthropic-beta:
oauth-2025-04-20. Python's _static_auth_header builds the bearer through _oauth_bearer_header, which
adds that beta (merged with the caller's betas, no direct browser access header), so Rust now builds
that case like the minted OAuth environment. A Bearer-prefixed key keeps the F10 ruling and is sent
once without the beta. Catalog id ANT-018

* fix(messages): assume the irsa role explicitly before a cross-account bedrock role

With IRSA (AWS_WEB_IDENTITY_TOKEN_FILE and AWS_ROLE_ARN set), no keys, and an aws_role_name naming a different role, Rust built an aws-config AssumeRoleProvider whose source credentials came from the default chain, so the web identity hop used an SDK session name and no GetCallerIdentity was sent. Python reads the token file and calls AssumeRoleWithWebIdentity on the IRSA role with the caller's session name, then GetCallerIdentity and AssumeRole on the target with those credentials, all against the same STS endpoint and region. Rust now makes the same three calls with the same parameters. Catalog id AUTH-033

* fix(http): drop tls 1.2 chacha20 suites from the rust client under fips_mode

With general_settings.fips_mode on, Python's outbound SSL contexts drop RSA key exchange and TLS 1.2 ChaCha20 (set_ciphers with :!kRSA:!CHACHA20, falling back to TLS 1.3 only when nothing is left), but the Rust client built its rustls config from the ring provider and kept every TLS 1.2 suite, so Rust-served Messages traffic and its auth calls still offered ECDHE ChaCha20. The host now passes the exclusion flag in its http settings and the Rust client removes the TLS 1.2 ChaCha20 suites from the configured or default list, offering TLS 1.3 only when none remain. rustls has no RSA key exchange, so nothing else changes. Catalog DISP-074, ruling R15.

* fix(messages): filter anthropic-beta through the beta config python loaded

SHAPE-020. The Rust messages route filtered anthropic-beta values for azure_ai, bedrock, bedrock_mantle and Foundry against its compiled copy of the bundled table, while Python filters against whatever _load_beta_headers_config loaded: the remote JSON by default, or the bundled file under LITELLM_LOCAL_ANTHROPIC_BETA_HEADERS, offline mode or a failed fetch. A remote config that differs from the bundled one therefore sent different betas on each path

The host now hands Rust that loaded map for every call whose betas are filtered, Rust installs it once per distinct config object, and the azure_ai and bedrock policy, the Foundry and bedrock_mantle allowlist and Bedrock Invoke's own filter read it with Python's lookup order (provider aliases, the header-only column, then the provider column) before falling back to the compiled table. Checks Python makes against the bundled config alone keep the compiled table
2026-11-16 21:08:25 +00:00
..
host fix(messages): close high and medium rust messages parity bugs (#52042) 2026-11-16 21:08:25 +00:00
messages feat(messages): serve bedrock invoke messages on rust only (#51330) 2026-11-15 16:58:31 -08:00
ocr refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
trace refactor(lens): connect LiteLLM to the independent Lens service (#45529) 2026-10-09 16:17:05 -07:00
__init__.py
AGENTS.md refactor(rust-bridge): decide native routing in the catalog, drop the bypass predicates (#46750) 2026-10-20 15:06:24 -07:00
native_route_wheel_test.py fix(bedrock): omit system prompt from audio transcription and report its token usage (#41565) 2026-10-28 19:23:15 -07:00
stubtest.ini
test_bindings.py refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
test_catalog.py feat(messages): serve bedrock invoke messages on rust only (#51330) 2026-11-15 16:58:31 -08:00
test_clickhouse.py refactor(lens): connect LiteLLM to the independent Lens service (#45529) 2026-10-09 16:17:05 -07:00
test_configuration.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_detectors.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00
test_execution.py refactor(rust-bridge): return an unstarted Execution from native entrypoints and drive it in Python (#46299) 2026-10-14 17:50:44 -07:00
test_failures.py
test_fork_guard.py refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
test_logger.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_public_call.py fix(rust): run native async calls through python's async wrapper steps (#50423) 2026-11-10 00:24:20 +00:00
test_runtime.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00
test_token_counter.py fix(proxy): count the request's tool_choice on the token count routes (#51133) 2026-11-14 07:53:27 -05:00
test_tokenizer.py refactor(sdk): separate core AWS and tokenizer dependencies (#44447) 2026-10-08 19:07:57 -07:00
test_verify_linux_native_wheel.py chore: move scripts and runtime sources under litellm (#51006) 2026-11-12 04:19:57 +00:00