@@ -49,6 +49,18 @@ function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0): Record<
4949 return call [ 0 ] as Record < string , unknown > ;
5050}
5151
52+ function streamedAudioResponse ( bytes : string ) : Response {
53+ return new Response (
54+ new ReadableStream ( {
55+ start ( controller ) {
56+ controller . enqueue ( new TextEncoder ( ) . encode ( bytes ) ) ;
57+ controller . close ( ) ;
58+ } ,
59+ } ) ,
60+ { headers : { "content-type" : "audio/mpeg" } } ,
61+ ) ;
62+ }
63+
5264describe ( "minimax music generation provider" , ( ) => {
5365 it ( "declares explicit mode capabilities" , ( ) => {
5466 expectExplicitMusicGenerationCapabilities ( buildMinimaxMusicGenerationProvider ( ) ) ;
@@ -161,6 +173,58 @@ describe("minimax music generation provider", () => {
161173 expect ( result . tracks [ 0 ] ?. buffer ) . toEqual ( terminalAudio ) ;
162174 } ) ;
163175
176+ it ( "rejects streamed generated music that exceeds the configured media cap" , async ( ) => {
177+ postJsonRequestMock . mockResolvedValue ( {
178+ response : new Response (
179+ `data: ${ JSON . stringify ( {
180+ data : { status : 2 , audio : Buffer . from ( "too-large" ) . toString ( "hex" ) } ,
181+ base_resp : { status_code : 0 } ,
182+ } ) } `,
183+ {
184+ headers : { "content-type" : "text/event-stream" } ,
185+ } ,
186+ ) ,
187+ release : vi . fn ( async ( ) => { } ) ,
188+ } ) ;
189+
190+ const provider = buildMinimaxMusicGenerationProvider ( ) ;
191+ await expect (
192+ provider . generateMusic ( {
193+ provider : "minimax" ,
194+ model : "music-2.6" ,
195+ prompt : "short track" ,
196+ cfg : { agents : { defaults : { mediaMaxMb : 0.000001 } } } ,
197+ } ) ,
198+ ) . rejects . toThrow ( "MiniMax generated music download exceeds 1 bytes" ) ;
199+ } ) ;
200+
201+ it ( "rejects inline generated music that exceeds the configured media cap before decoding" , async ( ) => {
202+ postJsonRequestMock . mockResolvedValue ( {
203+ response : new Response (
204+ JSON . stringify ( {
205+ data : {
206+ audio : Buffer . from ( "too-large" ) . toString ( "hex" ) ,
207+ } ,
208+ base_resp : { status_code : 0 } ,
209+ } ) ,
210+ {
211+ headers : { "content-type" : "application/json" } ,
212+ } ,
213+ ) ,
214+ release : vi . fn ( async ( ) => { } ) ,
215+ } ) ;
216+
217+ const provider = buildMinimaxMusicGenerationProvider ( ) ;
218+ await expect (
219+ provider . generateMusic ( {
220+ provider : "minimax" ,
221+ model : "music-2.6" ,
222+ prompt : "short track" ,
223+ cfg : { agents : { defaults : { mediaMaxMb : 0.000001 } } } ,
224+ } ) ,
225+ ) . rejects . toThrow ( "MiniMax generated music download exceeds 1 bytes" ) ;
226+ } ) ;
227+
164228 it ( "downloads tracks when url output is returned in data.audio" , async ( ) => {
165229 mockMusicGenerationResponse ( {
166230 task_id : "task-url" ,
@@ -192,6 +256,32 @@ describe("minimax music generation provider", () => {
192256 expect ( result . metadata ?. audioUrl ) . toBe ( "https://example.com/url-audio.mp3" ) ;
193257 } ) ;
194258
259+ it ( "rejects generated music downloads that exceed the configured media cap" , async ( ) => {
260+ postJsonRequestMock . mockResolvedValue ( {
261+ response : new Response (
262+ JSON . stringify ( {
263+ data : {
264+ audio : "https://example.com/too-large.mp3" ,
265+ } ,
266+ base_resp : { status_code : 0 } ,
267+ } ) ,
268+ { headers : { "content-type" : "application/json" } } ,
269+ ) ,
270+ release : vi . fn ( async ( ) => { } ) ,
271+ } ) ;
272+ fetchWithTimeoutMock . mockResolvedValueOnce ( streamedAudioResponse ( "too-large" ) ) ;
273+
274+ const provider = buildMinimaxMusicGenerationProvider ( ) ;
275+ await expect (
276+ provider . generateMusic ( {
277+ provider : "minimax" ,
278+ model : "music-2.6" ,
279+ prompt : "short track" ,
280+ cfg : { agents : { defaults : { mediaMaxMb : 0.000001 } } } ,
281+ } ) ,
282+ ) . rejects . toThrow ( "MiniMax generated music download exceeds 1 bytes" ) ;
283+ } ) ;
284+
195285 it ( "honors explicit long caller timeouts for request and download fallbacks" , async ( ) => {
196286 mockMusicGenerationResponse ( {
197287 data : {
0 commit comments