Skip to content

Commit 522cfb2

Browse files
Test OpenAI embed 400/422 fail-loud mapping (#222)
Spec's v0.16.0 review flagged that the OpenAI embed error path (400/422 to provider_invalid_request) was untested, unlike the parametrized Cohere and TEI equivalents. This is the fail-loud behavior the count-based batch chunking relies on -- an over-token chunk aborts the whole call rather than returning a partial. Add the missing parametrized test so the tag-gating behavior is test-protected, not inspection-only.
1 parent a0cf0fa commit 522cfb2

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/unit/test_retrieval_provider.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,24 @@ def handler(_req: httpx.Request) -> httpx.Response:
602602
assert response.usage.input_tokens == 0
603603

604604

605+
@pytest.mark.parametrize("status", [400, 422])
606+
async def test_openai_embed_invalid_request_maps_to_provider_invalid_request(status: int) -> None:
607+
# The OpenAI embed error path: a 400 / 422 (malformed or over-length
608+
# request) surfaces provider_invalid_request. This is the fail-loud behavior
609+
# the count-based batch chunking relies on -- an over-token chunk (each
610+
# slice within the 2048-input count cap but exceeding OpenAI's summed-token
611+
# ceiling) aborts the whole call rather than returning a partial or a
612+
# truncated result. The sibling Cohere / TEI mappings have the equivalent
613+
# test; this closes the gap for the OpenAI mapping.
614+
def handler(_req: httpx.Request) -> httpx.Response:
615+
return httpx.Response(status, json={"error": {"message": "input exceeds the maximum context length"}})
616+
617+
provider = _openai_embed_provider(handler)
618+
with pytest.raises(ProviderInvalidRequest):
619+
await provider.embed(["a very long document that exceeds the embedding model context window"])
620+
await provider.aclose()
621+
622+
605623
def _embedding_event() -> EmbeddingEvent:
606624
return EmbeddingEvent(
607625
invocation_id="inv",

0 commit comments

Comments
 (0)