Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/tools/test_vision_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
_validate_image_url,
_handle_vision_analyze,
_determine_mime_type,
_detect_image_mime_type,
_image_to_base64_data_url,
_resize_image_for_vision,
_image_exceeds_dimension,
Expand Down Expand Up @@ -143,6 +144,19 @@ def test_unknown_extension_defaults_to_jpeg(self):
assert _determine_mime_type(Path("file.xyz")) == "image/jpeg"


# ---------------------------------------------------------------------------
# _detect_image_mime_type
# ---------------------------------------------------------------------------


class TestDetectImageMimeType:
def test_bmp_header_is_unsupported_for_native_embedding(self, tmp_path):
img = tmp_path / "sample.bmp"
img.write_bytes(b"BM" + b"\x00" * 62)

assert _detect_image_mime_type(img) is None


# ---------------------------------------------------------------------------
# _image_to_base64_data_url
# ---------------------------------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion tools/vision_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ def _detect_image_mime_type(image_path: Path) -> Optional[str]:
return "image/jpeg"
if header.startswith((b"GIF87a", b"GIF89a")):
return "image/gif"
# The native multimodal path sends this MIME directly to model APIs.
# OpenAI/Codex currently accepts jpeg/png/gif/webp only; returning BMP
# here wedges sessions with HTTP 400 once the tool output is embedded.
# Treat BMP as unsupported unless/until we add conversion to a supported
# format before constructing the data URL.
if header.startswith(b"BM"):
return "image/bmp"
return None
if len(header) >= 12 and header[:4] == b"RIFF" and header[8:12] == b"WEBP":
return "image/webp"
if image_path.suffix.lower() == ".svg":
Expand Down