litellm/tests/test_litellm_rust
2026-09-10 13:50:26 -07:00
..
ocr fix(ocr): retain callback mutations for native calls 2026-09-10 13:50:26 -07:00
support fix(ocr): retain callback mutations for native calls 2026-09-10 13:50:26 -07:00
conftest.py fix(ocr): retain callback mutations for native calls 2026-09-10 13:50:26 -07:00
README.md fix(ocr): retain callback mutations for native calls 2026-09-10 13:50:26 -07:00
test_ocr.py test(ocr): assert explicit backend dispatch 2026-09-10 13:25:29 -07:00

Rust OCR bridge tests

This suite covers OCR requests through LiteLLM's compiled Rust extension. OCR behavior tests live under ocr/; reusable OCR request, callback, and recording-server fixtures live under support/

A test name identifies the OCR entrypoint or callback under test and its expected observable result. Parameter IDs state the execution mode or credential case. Keep multiple assertions together only when they prove one request, mutation, failure, or callback lifecycle behavior. Record callback observations and assert them after the callback returns because production logging can swallow callback exceptions

ocr/test_requests.py covers provider payloads, file preparation, endpoint and credential resolution, normalized responses, errors, timeouts, and Azure token-provider behavior. ocr/test_callbacks.py covers OCR callback inputs, mutations, ordering, context, failure handling, concurrency, and cleanup. ocr/test_guardrails.py covers OCR post-call blocking and response replacement. These contract modules call the Rust bridge directly. ocr/test_dispatch.py has the single public API dispatch test, covering enabled native dispatch and disabled Python dispatch. test_ocr.py is a strict smoke test of the compiled Rust OCR transport

Run make test-rust-extension as the acceptance command. It builds a fresh wheel, installs that wheel into a temporary environment, requires LITELLM_RUST=1, and runs this suite with isolated Python imports

Collection fails when LITELLM_RUST=1 is set but the compiled _native module cannot be imported. The autouse fixture isolates callback and configuration state but does not select a backend. Native contract tests call litellm.rust_bridge.ocr directly, while the strict dispatch test explicitly enables and disables Rust and records which OCR entrypoint runs

The OCR callback contracts and supported request behavior are strict. Five request and guardrail cases remain non-strict expected failures for post-call route attribution, sanitized provider errors, timeout-specific mapping, and native Azure validation