Files
vectorize-io__hindsight/hindsight-dev/tests/test_generate_openapi.py
Nicolò Boschi 82800ba864 fix(ci): repair zeroentropy embedding tests and regenerate drifted clients (#2009)
* fix(openapi): keep binary upload fields as format:binary; regen spec+clients

The #1982 dep bump (FastAPI 0.136 / Pydantic 2.12) serializes binary upload
fields as OpenAPI-3.1 {"type":"string","contentMediaType":"application/
octet-stream"}. openapi-generator v7.10.0 (generate-clients.sh) does NOT
treat contentMediaType as a file upload, so it regenerated the Files `files`
and document-transfer `file` params as plain strings — silently breaking
multipart upload in the Go/Python/TypeScript clients ([]*os.File -> []string,
StrictBytes -> StrictStr, Blob|File -> string).

generate_openapi.py now post-processes the exported schema to restore the
prior `format: binary` representation (still valid under openapi 3.1.0, and
what the generator understands) for application/octet-stream string fields,
scoped to binary uploads only. Regenerated the spec and clients: the upload
signatures are back to the file-upload form (identical to main); the only
remaining delta vs main is ValidationError dropping its `url` field, a real
Pydantic 2.12 change (error metadata, harmless).

* test(embeddings): give zeroentropy routing mocks a dimension attribute

PR #1670 added post-encode dimension validation to generate_embeddings_batch
— it now reads embeddings_backend.dimension, which the EmbeddingsBackend
Protocol already requires. The pre-existing QueryAwareEmbeddings/
DocumentAwareEmbeddings routing mocks (#1770) omit it, so the two routing
tests started failing with AttributeError on main.

The mocks return single-element vectors, so declare dimension = 1 to satisfy
the Protocol and let validation pass. Pure test fix; no behavior change.

* test(openapi): lock _restore_binary_format binary-upload rewrite

Regression guard for the file-upload break: asserts octet-stream string
fields are rewritten to format:binary (incl. nested/array-item schemas) and
that other content media types are left untouched.
2026-06-05 14:38:44 +02:00

57 lines
1.9 KiB
Python

"""Regression tests for OpenAPI spec post-processing in generate_openapi."""
from hindsight_dev.generate_openapi import _restore_binary_format
def test_restores_format_binary_for_octet_stream_string():
"""contentMediaType binary uploads are rewritten to the format:binary form.
Guards the Files / document-transfer file-upload regression: FastAPI 0.136 /
Pydantic 2.12 emit OpenAPI-3.1 contentMediaType, which openapi-generator
v7.10.0 generates as a plain string instead of a multipart file upload.
"""
schema = {
"type": "string",
"title": "File",
"contentMediaType": "application/octet-stream",
}
_restore_binary_format(schema)
assert schema == {"type": "string", "title": "File", "format": "binary"}
assert "contentMediaType" not in schema
def test_rewrites_nested_and_array_item_schemas():
"""The walk reaches binary fields nested in properties and array items."""
schema = {
"components": {
"schemas": {
"Upload": {
"type": "object",
"properties": {
"files": {
"type": "array",
"items": {"type": "string", "contentMediaType": "application/octet-stream"},
}
},
}
}
}
}
_restore_binary_format(schema)
item = schema["components"]["schemas"]["Upload"]["properties"]["files"]["items"]
assert item == {"type": "string", "format": "binary"}
def test_leaves_other_content_media_types_untouched():
"""Only application/octet-stream is rewritten; other media types are preserved."""
schema = {"type": "string", "contentMediaType": "application/json"}
_restore_binary_format(schema)
assert schema == {"type": "string", "contentMediaType": "application/json"}
assert "format" not in schema