mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
test(ocr): require Rust file input parity
This commit is contained in:
parent
2f7ba0b333
commit
bc0ba47e33
3 changed files with 18 additions and 28 deletions
|
|
@ -4,7 +4,7 @@ This suite covers OCR requests through LiteLLM's compiled Rust extension. OCR be
|
|||
|
||||
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, 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. `ocr/test_dispatch.py` covers public sync and async native dispatch, explicit Python dispatch, fallback, and the native compression header. `test_ocr.py` is the strict wire-level smoke test
|
||||
`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. `ocr/test_dispatch.py` covers public sync and async native dispatch and explicit Python dispatch. `test_ocr.py` is the strict wire-level smoke test
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ async def test_async_ocr_response_is_marked_as_rust_when_native_dispatch_is_enab
|
|||
assert has_rust_response_marker(response)
|
||||
|
||||
|
||||
def test_public_ocr_falls_back_to_python_for_unsupported_file_document(ocr_server: RecordingServer) -> None:
|
||||
def test_public_ocr_uses_rust_for_file_document(ocr_server: RecordingServer) -> None:
|
||||
response: Final = litellm.ocr(
|
||||
model=OCR_MODEL,
|
||||
document={"type": "file", "file": b"%PDF-1.4", "mime_type": "application/pdf"},
|
||||
|
|
@ -52,7 +52,7 @@ def test_public_ocr_falls_back_to_python_for_unsupported_file_document(ocr_serve
|
|||
)
|
||||
|
||||
assert response.pages[0].markdown == "native OCR response"
|
||||
assert not has_rust_response_marker(response)
|
||||
assert has_rust_response_marker(response)
|
||||
|
||||
|
||||
def test_public_ocr_response_has_no_rust_marker_when_native_dispatch_is_disabled(
|
||||
|
|
@ -69,14 +69,3 @@ def test_public_ocr_response_has_no_rust_marker_when_native_dispatch_is_disabled
|
|||
|
||||
assert response.pages[0].markdown == "native OCR response"
|
||||
assert not has_rust_response_marker(response)
|
||||
|
||||
|
||||
def test_native_ocr_sends_identity_accept_encoding_header(ocr_server: RecordingServer) -> None:
|
||||
litellm.ocr(
|
||||
model=OCR_MODEL,
|
||||
document=OCR_DOCUMENT,
|
||||
api_key="test-key",
|
||||
api_base=ocr_server.base_url,
|
||||
)
|
||||
|
||||
assert ocr_server.requests[0].headers["accept-encoding"] == "identity"
|
||||
|
|
|
|||
|
|
@ -69,19 +69,21 @@ def test_native_ocr_sends_model_and_document_to_mistral_ocr_path(ocr_server: Rec
|
|||
assert ocr_server.requests[0].body == {"model": "mistral-ocr-latest", "document": OCR_DOCUMENT}
|
||||
|
||||
|
||||
def test_native_ocr_rejects_file_document_before_callbacks_or_provider_request(ocr_server: RecordingServer) -> None:
|
||||
ocr_server.expected_requests = 0
|
||||
recorder: Final = RecordingLogger()
|
||||
def test_native_ocr_prepares_file_document_like_python(ocr_server: RecordingServer) -> None:
|
||||
response: Final = call_native_ocr(
|
||||
ocr_server,
|
||||
document={"type": "file", "file": b"%PDF-1.4", "mime_type": "application/pdf"},
|
||||
)
|
||||
|
||||
with pytest.raises(NotImplementedError, match="OCR file document preparation"):
|
||||
call_native_ocr(
|
||||
ocr_server,
|
||||
document={"type": "file", "file": b"%PDF-1.4", "mime_type": "application/pdf"},
|
||||
callbacks=[recorder],
|
||||
)
|
||||
|
||||
assert ocr_server.requests == []
|
||||
assert recorder.events == ()
|
||||
assert response.pages[0].markdown == "native OCR response"
|
||||
assert_native_request(ocr_server)
|
||||
assert ocr_server.requests[0].body == {
|
||||
"model": "mistral-ocr-latest",
|
||||
"document": {
|
||||
"type": "document_url",
|
||||
"document_url": "data:application/pdf;base64,JVBERi0xLjQ=",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_native_ocr_sends_pages_and_image_options(ocr_server: RecordingServer) -> None:
|
||||
|
|
@ -313,9 +315,8 @@ async def test_public_azure_ocr_token_provider_failure_prevents_pre_call_callbac
|
|||
[
|
||||
{"azure_ad_token": "oidc/assertion", "client_id": "client", "tenant_id": "tenant"},
|
||||
{"model": "azure_ai/doc-intelligence/prebuilt-read"},
|
||||
{"document": {"type": "file", "file": b"pdf"}},
|
||||
],
|
||||
ids=["oidc-assertion", "document-intelligence-model", "file-document"],
|
||||
ids=["oidc-assertion", "document-intelligence-model"],
|
||||
)
|
||||
def test_native_azure_ocr_rejects_unsupported_configuration_before_token_or_callbacks(
|
||||
ocr_server: RecordingServer,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue