@@ -26,6 +26,67 @@ function fetchGuardParams(call: number): { url?: unknown; auditContext?: unknown
2626 return params as { url ?: unknown ; auditContext ?: unknown } ;
2727}
2828
29+ function mockLocalVideoResponses ( params : {
30+ promptId : string ;
31+ outputs : Record < string , unknown > ;
32+ download ?: {
33+ body : string ;
34+ contentType : string ;
35+ } ;
36+ } ) {
37+ fetchWithSsrFGuardMock
38+ . mockResolvedValueOnce ( {
39+ response : new Response ( JSON . stringify ( { prompt_id : params . promptId } ) , {
40+ status : 200 ,
41+ headers : { "content-type" : "application/json" } ,
42+ } ) ,
43+ release : vi . fn ( async ( ) => { } ) ,
44+ } )
45+ . mockResolvedValueOnce ( {
46+ response : new Response (
47+ JSON . stringify ( {
48+ [ params . promptId ] : {
49+ outputs : params . outputs ,
50+ } ,
51+ } ) ,
52+ {
53+ status : 200 ,
54+ headers : { "content-type" : "application/json" } ,
55+ } ,
56+ ) ,
57+ release : vi . fn ( async ( ) => { } ) ,
58+ } ) ;
59+
60+ if ( params . download ) {
61+ fetchWithSsrFGuardMock . mockResolvedValueOnce ( {
62+ response : new Response ( Buffer . from ( params . download . body ) , {
63+ status : 200 ,
64+ headers : { "content-type" : params . download . contentType } ,
65+ } ) ,
66+ release : vi . fn ( async ( ) => { } ) ,
67+ } ) ;
68+ }
69+ }
70+
71+ function generateLocalVideo ( outputNodeId ?: string ) {
72+ const provider = buildComfyVideoGenerationProvider ( ) ;
73+ return provider . generateVideo ( {
74+ provider : "comfy" ,
75+ model : "workflow" ,
76+ prompt : "animate a lobster" ,
77+ cfg : buildComfyConfig ( {
78+ video : {
79+ workflow : {
80+ "6" : { inputs : { text : "" } } ,
81+ "9" : { inputs : { } } ,
82+ } ,
83+ promptNodeId : "6" ,
84+ ...( outputNodeId ? { outputNodeId } : { } ) ,
85+ } ,
86+ } ) ,
87+ } ) ;
88+ }
89+
2990describe ( "comfy video-generation provider" , ( ) => {
3091 beforeEach ( ( ) => {
3192 vi . clearAllMocks ( ) ;
@@ -143,6 +204,119 @@ describe("comfy video-generation provider", () => {
143204 } ) ;
144205 } ) ;
145206
207+ it ( "returns only MP4 video entries from mixed images buckets" , async ( ) => {
208+ setComfyFetchGuardForTesting ( fetchWithSsrFGuardMock ) ;
209+ mockLocalVideoResponses ( {
210+ promptId : "local-video-mixed" ,
211+ outputs : {
212+ "2" : {
213+ images : [ { filename : "generated.png" , subfolder : "" , type : "output" } ] ,
214+ } ,
215+ "4" : {
216+ images : [ { filename : "generated.mp4" , subfolder : "" , type : "output" } ] ,
217+ } ,
218+ } ,
219+ download : {
220+ body : "mp4-data" ,
221+ contentType : "video/mp4" ,
222+ } ,
223+ } ) ;
224+
225+ const result = await generateLocalVideo ( ) ;
226+
227+ expect ( fetchGuardParams ( 2 ) . url ) . toBe (
228+ "http://127.0.0.1:8188/view?filename=generated.mp4&subfolder=&type=output" ,
229+ ) ;
230+ expect ( result . videos ) . toEqual ( [
231+ expect . objectContaining ( {
232+ buffer : Buffer . from ( "mp4-data" ) ,
233+ mimeType : "video/mp4" ,
234+ fileName : "generated.mp4" ,
235+ metadata : {
236+ nodeId : "4" ,
237+ promptId : "local-video-mixed" ,
238+ } ,
239+ } ) ,
240+ ] ) ;
241+ expect ( result . metadata ?. outputNodeIds ) . toEqual ( [ "4" ] ) ;
242+ expect ( fetchWithSsrFGuardMock ) . toHaveBeenCalledTimes ( 3 ) ;
243+ } ) ;
244+
245+ it ( "accepts uppercase WEBM names from the images bucket" , async ( ) => {
246+ setComfyFetchGuardForTesting ( fetchWithSsrFGuardMock ) ;
247+ mockLocalVideoResponses ( {
248+ promptId : "local-video-webm" ,
249+ outputs : {
250+ "9" : {
251+ images : [ { name : "generated.WEBM" , subfolder : "" , type : "output" } ] ,
252+ } ,
253+ } ,
254+ download : {
255+ body : "webm-data" ,
256+ contentType : "video/webm" ,
257+ } ,
258+ } ) ;
259+
260+ const result = await generateLocalVideo ( ) ;
261+
262+ expect ( fetchGuardParams ( 2 ) . url ) . toBe (
263+ "http://127.0.0.1:8188/view?filename=generated.WEBM&subfolder=&type=output" ,
264+ ) ;
265+ expect ( result . videos [ 0 ] ) . toEqual (
266+ expect . objectContaining ( {
267+ buffer : Buffer . from ( "webm-data" ) ,
268+ mimeType : "video/webm" ,
269+ fileName : "generated.WEBM" ,
270+ } ) ,
271+ ) ;
272+ } ) ;
273+
274+ it ( "rejects images-only workflow output for video generation" , async ( ) => {
275+ setComfyFetchGuardForTesting ( fetchWithSsrFGuardMock ) ;
276+ mockLocalVideoResponses ( {
277+ promptId : "local-video-images-only" ,
278+ outputs : {
279+ "9" : {
280+ images : [
281+ { filename : "generated.png" , subfolder : "" , type : "output" } ,
282+ { filename : "generated.jpg" , subfolder : "" , type : "output" } ,
283+ ] ,
284+ } ,
285+ } ,
286+ } ) ;
287+
288+ await expect ( generateLocalVideo ( ) ) . rejects . toThrow (
289+ "Comfy workflow local-video-images-only completed without video outputs" ,
290+ ) ;
291+ expect ( fetchWithSsrFGuardMock ) . toHaveBeenCalledTimes ( 2 ) ;
292+ } ) ;
293+
294+ it ( "preserves legacy videos bucket output without filename filtering" , async ( ) => {
295+ setComfyFetchGuardForTesting ( fetchWithSsrFGuardMock ) ;
296+ mockLocalVideoResponses ( {
297+ promptId : "local-video-legacy" ,
298+ outputs : {
299+ "9" : {
300+ videos : [ { filename : "generated.mov" , subfolder : "" , type : "output" } ] ,
301+ } ,
302+ } ,
303+ download : {
304+ body : "legacy-video-data" ,
305+ contentType : "video/quicktime" ,
306+ } ,
307+ } ) ;
308+
309+ const result = await generateLocalVideo ( "9" ) ;
310+
311+ expect ( result . videos [ 0 ] ) . toEqual (
312+ expect . objectContaining ( {
313+ buffer : Buffer . from ( "legacy-video-data" ) ,
314+ mimeType : "video/quicktime" ,
315+ fileName : "generated.mov" ,
316+ } ) ,
317+ ) ;
318+ } ) ;
319+
146320 it ( "rejects generated video downloads that exceed the configured media cap" , async ( ) => {
147321 setComfyFetchGuardForTesting ( fetchWithSsrFGuardMock ) ;
148322 fetchWithSsrFGuardMock
0 commit comments