@@ -165,6 +165,76 @@ describe("discoverOpenAICompatibleLocalModels raw discovery", () => {
165165 ) . toBe ( 8 ) ;
166166 } ) ;
167167
168+ it ( "bounds concurrent property probes and keeps results associated by model" , async ( ) => {
169+ const models = Array . from ( { length : 10 } , ( _ , index ) => ( {
170+ id : `model-${ index } ` ,
171+ status : { value : "loaded" } ,
172+ } ) ) ;
173+ let active = 0 ;
174+ let maxActive = 0 ;
175+ fetchWithSsrFGuardMock . mockImplementation ( async ( { url } : { url : string } ) => {
176+ if ( url . endsWith ( "/health" ) ) {
177+ return guarded ( new Response ( null , { status : 200 } ) ) ;
178+ }
179+ if ( url . endsWith ( "/models" ) ) {
180+ return guarded ( new Response ( JSON . stringify ( { data : models } ) ) ) ;
181+ }
182+ const modelId = new URL ( url ) . searchParams . get ( "model" ) ;
183+ const index = Number ( modelId ?. replace ( "model-" , "" ) ) ;
184+ active += 1 ;
185+ maxActive = Math . max ( maxActive , active ) ;
186+ await new Promise < void > ( ( resolve ) => {
187+ setTimeout ( resolve , 10 - index ) ;
188+ } ) ;
189+ active -= 1 ;
190+ return guarded ( new Response ( JSON . stringify ( { n_ctx : 8_000 + index } ) ) ) ;
191+ } ) ;
192+
193+ const result = await discoverOpenAICompatibleLocalModels ( {
194+ baseUrl : "http://127.0.0.1:8080/v1" ,
195+ label : "llama-server" ,
196+ healthPath : "/health" ,
197+ modelsPathOrder : "server-first" ,
198+ routerModelProps : true ,
199+ rawResult : true ,
200+ } ) ;
201+
202+ expect ( maxActive ) . toBe ( 8 ) ;
203+ expect ( result . kind === "success" ? result . rows . map ( ( row ) => row . props ?. n_ctx ) : [ ] ) . toEqual (
204+ models . map ( ( _ , index ) => 8_000 + index ) ,
205+ ) ;
206+ } ) ;
207+
208+ it ( "caps property probes at 200 models" , async ( ) => {
209+ const models = Array . from ( { length : 201 } , ( _ , index ) => ( {
210+ id : `model-${ index } ` ,
211+ status : { value : "loaded" } ,
212+ } ) ) ;
213+ fetchWithSsrFGuardMock . mockImplementation ( async ( { url } : { url : string } ) => {
214+ if ( url . endsWith ( "/health" ) ) {
215+ return guarded ( new Response ( null , { status : 200 } ) ) ;
216+ }
217+ if ( url . endsWith ( "/models" ) ) {
218+ return guarded ( new Response ( JSON . stringify ( { data : models } ) ) ) ;
219+ }
220+ return guarded ( new Response ( JSON . stringify ( { n_ctx : 8192 } ) ) ) ;
221+ } ) ;
222+
223+ const result = await discoverOpenAICompatibleLocalModels ( {
224+ baseUrl : "http://127.0.0.1:8080/v1" ,
225+ label : "llama-server" ,
226+ healthPath : "/health" ,
227+ modelsPathOrder : "server-first" ,
228+ routerModelProps : true ,
229+ rawResult : true ,
230+ } ) ;
231+
232+ expect ( result . kind === "success" ? result . rows : [ ] ) . toHaveLength ( 201 ) ;
233+ expect (
234+ fetchWithSsrFGuardMock . mock . calls . filter ( ( [ call ] ) => call . url . includes ( "/props?" ) ) . length ,
235+ ) . toBe ( 200 ) ;
236+ } ) ;
237+
168238 it ( "keeps explicit Authorization ahead of ambient API-key discovery" , async ( ) => {
169239 fetchWithSsrFGuardMock
170240 . mockResolvedValueOnce ( guarded ( new Response ( null , { status : 200 } ) ) )
0 commit comments