feat: add multimedia endpoint support (image, TTS, transcription, video)#101
feat: add multimedia endpoint support (image, TTS, transcription, video)#101
Conversation
commit: |
jpr5
left a comment
There was a problem hiding this comment.
Code Review — Multimedia Endpoint Support
Well-structured PR. All 4 handlers follow consistent patterns, endpoint backfill is correct across all existing handlers, tests are strong (575 lines with specific assertions). One medium finding, two low.
Medium
Fixtures without endpoint match multimedia requests, then 500 at type guard (router.ts:44-48)
Endpoint filtering is one-directional: fixtures WITH endpoint are restricted, but fixtures WITHOUT endpoint match ANY request type. A user with a generic chat fixture:
mock.addFixture({ match: { userMessage: "guitar" }, response: { content: "Chat about guitars" } });This matches image requests for "guitar". handleImages matches it, then isImageResponse(response) fails → 500. The test only verifies the reverse direction (image fixture doesn't match chat).
Fix: when a request has _endpointType and the matched fixture has no endpoint, verify the response type is compatible with the endpoint before returning the match. Or make filtering bidirectional.
Low
extractFormField regex on binary multipart data (transcription.ts:15-22) — readBody converts binary to UTF-8 string. If file part appears before text fields, mangled bytes could theoretically match the regex. Extremely unlikely with real audio but fragile. A boundary-delimited parser would be more robust.
_endpointType not a declared field (types.ts) — stored via index signature, no type safety. Adding _endpointType?: string to ChatCompletionRequest would catch typos.
Clean
- Image gen (OpenAI + Gemini Imagen), TTS, transcription, video create/poll all correct
matchFixtureendpoint filtering works for the designed direction- Convenience methods (onImage, onSpeech, etc.) wire correctly
- Video state map with X-Test-Id isolation is correct
- Backfill of
_endpointTypeon all existing handlers is consistent
🤖 Reviewed with Claude Code
785a371 to
8541b42
Compare
8541b42 to
a76ea32
Compare
Summary
/v1/images/generations,/v1beta/models/{model}:predict), text-to-speech (/v1/audio/speech), audio transcription (/v1/audio/transcriptions), and video generation (/v1/videos,/v1/videos/{id})match.endpointfield toFixtureMatchfor isolating fixtures by endpoint type, preventing cross-matching (e.g., image fixtures won't match chat requests)onImage,onSpeech,onTranscription,onVideo) onLLMockand backfill_endpointTypeon all existing handlersNew Endpoints
/v1/images/generationsprompt→userMessage/v1beta/models/{model}:predictinstances[0].prompt→userMessage/v1/audio/speechinput→userMessage/v1/audio/transcriptionsmatch.endpointonly/v1/videosprompt→userMessage/v1/videos/{id}Test plan
endpoint: "chat"andendpoint: "embedding"fixtures match existing handlers