@@ -34,14 +34,6 @@ beforeAll(async () => {
3434
3535installProviderHttpMockCleanup ( ) ;
3636
37- function postJsonRequest ( index = 0 ) : Record < string , unknown > {
38- const request = postJsonRequestMock . mock . calls [ index ] ?. [ 0 ] as Record < string , unknown > | undefined ;
39- if ( ! request ) {
40- throw new Error ( `expected postJsonRequest call ${ index } ` ) ;
41- }
42- return request ;
43- }
44-
4537function postMultipartRequest ( index = 0 ) : Record < string , unknown > {
4638 const request = postMultipartRequestMock . mock . calls [ index ] ?. [ 0 ] as
4739 | Record < string , unknown >
@@ -188,8 +180,8 @@ describe("openai video generation provider", () => {
188180 expect ( postJsonRequestMock ) . not . toHaveBeenCalled ( ) ;
189181 } ) ;
190182
191- it ( "uses JSON for text-only Sora requests" , async ( ) => {
192- postJsonRequestMock . mockResolvedValue ( {
183+ it ( "uses SDK-compatible multipart for text-only Sora requests" , async ( ) => {
184+ postMultipartRequestMock . mockResolvedValueOnce ( {
193185 response : streamedJsonResponse ( {
194186 id : "vid_123" ,
195187 model : "sora-2" ,
@@ -221,7 +213,13 @@ describe("openai video generation provider", () => {
221213 durationSeconds : 4 ,
222214 } ) ;
223215
224- expect ( postJsonRequest ( ) . url ) . toBe ( "https://api.openai.com/v1/videos" ) ;
216+ const createRequest = postMultipartRequest ( ) ;
217+ expect ( createRequest . url ) . toBe ( "https://api.openai.com/v1/videos" ) ;
218+ const form = createRequest . body as FormData ;
219+ expect ( form . get ( "prompt" ) ) . toBe ( "A paper airplane gliding through golden hour light" ) ;
220+ expect ( form . get ( "model" ) ) . toBe ( "sora-2" ) ;
221+ expect ( form . get ( "seconds" ) ) . toBe ( "4" ) ;
222+ expect ( form . get ( "input_reference" ) ) . toBeNull ( ) ;
225223 const [ pollUrl , pollInit , pollTimeout , pollFetch ] = fetchWithTimeoutCall ( 0 ) ;
226224 expect ( pollUrl ) . toBe ( "https://api.openai.com/v1/videos/vid_123" ) ;
227225 expect ( pollInit ?. method ) . toBe ( "GET" ) ;
@@ -238,7 +236,7 @@ describe("openai video generation provider", () => {
238236 "surfaces an immediately failed OpenAI submission before polling or validating id (%s)" ,
239237 async ( videoId ) => {
240238 const release = vi . fn ( async ( ) => { } ) ;
241- postJsonRequestMock . mockResolvedValue ( {
239+ postMultipartRequestMock . mockResolvedValueOnce ( {
242240 response : streamedJsonResponse ( {
243241 ...( videoId ? { id : videoId } : { } ) ,
244242 status : "failed" ,
@@ -264,7 +262,7 @@ describe("openai video generation provider", () => {
264262
265263 it ( "downloads an immediately completed OpenAI submission without polling it again" , async ( ) => {
266264 const release = vi . fn ( async ( ) => { } ) ;
267- postJsonRequestMock . mockResolvedValue ( {
265+ postMultipartRequestMock . mockResolvedValueOnce ( {
268266 response : streamedJsonResponse ( {
269267 id : "vid_completed" ,
270268 model : "sora-2" ,
@@ -296,7 +294,7 @@ describe("openai video generation provider", () => {
296294 } ) ;
297295
298296 it ( "rejects generated video downloads that exceed the configured media cap" , async ( ) => {
299- postJsonRequestMock . mockResolvedValue ( {
297+ postMultipartRequestMock . mockResolvedValueOnce ( {
300298 response : streamedJsonResponse ( {
301299 id : "vid_too_large" ,
302300 model : "sora-2" ,
@@ -325,8 +323,8 @@ describe("openai video generation provider", () => {
325323 ) . rejects . toThrow ( "OpenAI generated video download exceeds 1 bytes" ) ;
326324 } ) ;
327325
328- it ( "uses JSON input_reference.image_url for image-to- video requests " , async ( ) => {
329- postJsonRequestMock . mockResolvedValue ( {
326+ it ( "uploads the SDK-compatible image reference in a multipart video request " , async ( ) => {
327+ postMultipartRequestMock . mockResolvedValueOnce ( {
330328 response : streamedJsonResponse ( {
331329 id : "vid_456" ,
332330 model : "sora-2" ,
@@ -356,11 +354,15 @@ describe("openai video generation provider", () => {
356354 inputImages : [ { buffer : Buffer . from ( "png-bytes" ) , mimeType : "image/png" } ] ,
357355 } ) ;
358356
359- const createRequest = postJsonRequest ( ) ;
357+ const createRequest = postMultipartRequest ( ) ;
360358 expect ( createRequest . url ) . toBe ( "https://api.openai.com/v1/videos" ) ;
361- expect ( ( createRequest . body as Record < string , unknown > ) . input_reference ) . toEqual ( {
362- image_url : "data:image/png;base64,cG5nLWJ5dGVz" ,
363- } ) ;
359+ const form = createRequest . body as FormData ;
360+ const reference = form . get ( "input_reference" ) ;
361+ expect ( reference ) . toBeInstanceOf ( File ) ;
362+ const referenceFile = reference as File ;
363+ expect ( referenceFile . name ) . toBe ( "reference-image.png" ) ;
364+ expect ( referenceFile . type ) . toBe ( "image/png" ) ;
365+ expect ( Buffer . from ( await referenceFile . arrayBuffer ( ) ) ) . toEqual ( Buffer . from ( "png-bytes" ) ) ;
364366 const [ pollUrl , pollInit , pollTimeout , pollFetch ] = fetchWithTimeoutCall ( 0 ) ;
365367 expect ( pollUrl ) . toBe ( "https://api.openai.com/v1/videos/vid_456" ) ;
366368 expect ( pollInit ?. method ) . toBe ( "GET" ) ;
@@ -369,7 +371,7 @@ describe("openai video generation provider", () => {
369371 } ) ;
370372
371373 it ( "keeps configured local baseUrl private-network blocked unless explicitly enabled" , async ( ) => {
372- postJsonRequestMock . mockResolvedValue ( {
374+ postMultipartRequestMock . mockResolvedValueOnce ( {
373375 response : streamedJsonResponse ( {
374376 id : "vid_local" ,
375377 model : "sora-2" ,
@@ -409,13 +411,13 @@ describe("openai video generation provider", () => {
409411
410412 expect ( providerHttpConfigRequest ( ) . baseUrl ) . toBe ( "http://127.0.0.1:44080/v1" ) ;
411413 expect ( providerHttpConfigRequest ( ) . request ) . toBeUndefined ( ) ;
412- const createRequest = postJsonRequest ( ) ;
414+ const createRequest = postMultipartRequest ( ) ;
413415 expect ( createRequest . url ) . toBe ( "http://127.0.0.1:44080/v1/videos" ) ;
414416 expect ( createRequest . allowPrivateNetwork ) . toBe ( false ) ;
415417 } ) ;
416418
417419 it ( "honors configured request allowPrivateNetwork for local video providers" , async ( ) => {
418- postJsonRequestMock . mockResolvedValue ( {
420+ postMultipartRequestMock . mockResolvedValueOnce ( {
419421 response : streamedJsonResponse ( {
420422 id : "vid_local" ,
421423 model : "sora-2" ,
@@ -459,7 +461,7 @@ describe("openai video generation provider", () => {
459461 } ) ;
460462 expect ( providerHttpConfigRequest ( ) . baseUrl ) . toBe ( "http://127.0.0.1:44080/v1" ) ;
461463 expect ( providerHttpConfigRequest ( ) . request ) . toEqual ( { allowPrivateNetwork : true } ) ;
462- const createRequest = postJsonRequest ( ) ;
464+ const createRequest = postMultipartRequest ( ) ;
463465 expect ( createRequest . url ) . toBe ( "http://127.0.0.1:44080/v1/videos" ) ;
464466 expect ( createRequest . allowPrivateNetwork ) . toBe ( true ) ;
465467 const statusRequest = pollProviderOperationRequest ( ) ;
@@ -490,7 +492,7 @@ describe("openai video generation provider", () => {
490492 throw new Error ( label ) ;
491493 } )
492494 . mockImplementationOnce ( async ( ) => { } ) ;
493- postJsonRequestMock . mockResolvedValue ( {
495+ postMultipartRequestMock . mockResolvedValueOnce ( {
494496 response : streamedJsonResponse ( {
495497 id : "vid_local" ,
496498 model : "sora-2" ,
@@ -559,7 +561,7 @@ describe("openai video generation provider", () => {
559561 . mockImplementationOnce ( async ( _response , label ) => {
560562 throw new Error ( label ) ;
561563 } ) ;
562- postJsonRequestMock . mockResolvedValue ( {
564+ postMultipartRequestMock . mockResolvedValueOnce ( {
563565 response : streamedJsonResponse ( {
564566 id : "vid_local" ,
565567 model : "sora-2" ,
0 commit comments