@@ -11,6 +11,7 @@ import {
1111 buildOllamaProvider ,
1212 buildOllamaModelDefinition ,
1313 capLocalOllamaProviderContext ,
14+ enrichOllamaCompletionModels ,
1415 enrichOllamaModelsWithContext ,
1516 fetchLoadedOllamaModelNames ,
1617 isOllamaCloudModel ,
@@ -269,6 +270,113 @@ describe("ollama provider models", () => {
269270 } ) ;
270271 } ) ;
271272
273+ it . each ( [
274+ {
275+ description : "remote host metadata" ,
276+ listed : {
277+ name : "deepseek-r1:671b" ,
278+ remote_host : "https://ollama.example" ,
279+ capabilities : [ "vision" ] ,
280+ } ,
281+ reasoning : true ,
282+ } ,
283+ {
284+ description : "upstream remote-model-only metadata" ,
285+ listed : {
286+ name : "remote-chat:latest" ,
287+ remote_model : "upstream-chat:latest" ,
288+ capabilities : [ "vision" ] ,
289+ } ,
290+ reasoning : false ,
291+ } ,
292+ {
293+ description : "the existing explicit cloud model contract" ,
294+ listed : { name : "remote-chat:cloud" , capabilities : [ "vision" ] } ,
295+ reasoning : false ,
296+ } ,
297+ ] ) (
298+ "keeps incomplete cloud metadata discoverable with $description" ,
299+ async ( { listed, reasoning } ) => {
300+ vi . stubGlobal (
301+ "fetch" ,
302+ vi . fn ( async ( input : string | URL | Request ) =>
303+ requestUrl ( input ) . endsWith ( "/api/tags" )
304+ ? jsonResponse ( { models : [ listed ] } )
305+ : jsonResponse ( { } ) ,
306+ ) ,
307+ ) ;
308+
309+ await expect ( buildOllamaProvider ( "http://127.0.0.1:11434" ) ) . resolves . toMatchObject ( {
310+ models : [
311+ {
312+ id : listed . name ,
313+ input : [ "text" , "image" ] ,
314+ reasoning,
315+ compat : { supportsTools : true } ,
316+ } ,
317+ ] ,
318+ } ) ;
319+ } ,
320+ ) ;
321+
322+ it . each ( [
323+ {
324+ description : "an explicitly empty inspection result" ,
325+ listed : {
326+ name : "remote-chat:cloud" ,
327+ remote_model : "upstream-chat" ,
328+ capabilities : [ "completion" , "tools" ] ,
329+ } ,
330+ inspected : { capabilities : [ ] } ,
331+ } ,
332+ {
333+ description : "an advertised remote embedding model" ,
334+ listed : {
335+ name : "remote-embedding:latest" ,
336+ remote_model : "upstream-embedding" ,
337+ capabilities : [ "embedding" ] ,
338+ } ,
339+ } ,
340+ {
341+ description : "an advertised local embedding model" ,
342+ listed : { name : "local-embedding:latest" , capabilities : [ "embedding" ] } ,
343+ } ,
344+ ] ) ( "does not expose $description as a completion model" , async ( { listed, inspected = { } } ) => {
345+ vi . stubGlobal (
346+ "fetch" ,
347+ vi . fn ( async ( input : string | URL | Request ) =>
348+ requestUrl ( input ) . endsWith ( "/api/tags" )
349+ ? jsonResponse ( { models : [ listed ] } )
350+ : jsonResponse ( inspected ) ,
351+ ) ,
352+ ) ;
353+
354+ await expect ( buildOllamaProvider ( "http://127.0.0.1:11434" ) ) . resolves . toMatchObject ( {
355+ models : [ ] ,
356+ } ) ;
357+ } ) ;
358+
359+ it ( "keeps strict node discovery closed when remote completion is only inferred" , async ( ) => {
360+ vi . stubGlobal (
361+ "fetch" ,
362+ vi . fn ( async ( ) => jsonResponse ( { } ) ) ,
363+ ) ;
364+
365+ await expect (
366+ enrichOllamaCompletionModels (
367+ "http://127.0.0.1:11434" ,
368+ [
369+ {
370+ name : "remote-chat:latest" ,
371+ remote_model : "upstream-chat:latest" ,
372+ capabilities : [ "tools" ] ,
373+ } ,
374+ ] ,
375+ { requireCompletionCapability : true } ,
376+ ) ,
377+ ) . resolves . toEqual ( [ ] ) ;
378+ } ) ;
379+
272380 it ( "forwards remote auth to model listing and show probes" , async ( ) => {
273381 const fetchMock = vi . fn ( async ( input : string | URL | Request , init ?: RequestInit ) => {
274382 expect ( new Headers ( init ?. headers ) . get ( "Authorization" ) ) . toBe ( "Bearer cloud-key" ) ;
@@ -878,7 +986,30 @@ describe("ollama provider models", () => {
878986 } ,
879987 expected : { contextWindow : 32_768 , supportsTools : true } ,
880988 } ,
881- ] ) ( "$description" , async ( { listed, expected } ) => {
989+ {
990+ description : "preserves remote-model-only list capabilities after a live inspection failure" ,
991+ listed : {
992+ name : "remote-chat:latest" ,
993+ remote_model : "upstream-chat:latest" ,
994+ digest : "sha256:remote-model-list-metadata" ,
995+ details : { context_length : 32_768 } ,
996+ capabilities : [ "tools" ] ,
997+ } ,
998+ expected : { contextWindow : 32_768 , supportsTools : true } ,
999+ } ,
1000+ {
1001+ description : "preserves remote-model-only metadata after a live incomplete inspection" ,
1002+ listed : {
1003+ name : "remote-incomplete:latest" ,
1004+ remote_model : "upstream-incomplete:latest" ,
1005+ digest : "sha256:remote-model-incomplete-inspection" ,
1006+ details : { context_length : 32_768 } ,
1007+ capabilities : [ "vision" ] ,
1008+ } ,
1009+ showFailed : false ,
1010+ expected : { contextWindow : 32_768 , supportsTools : true } ,
1011+ } ,
1012+ ] ) ( "$description" , async ( { listed, expected, showFailed = true } ) => {
8821013 const server = createServer ( ( request , response ) => {
8831014 response . setHeader ( "Content-Type" , "application/json" ) ;
8841015 if ( request . url === "/api/tags" ) {
@@ -890,8 +1021,8 @@ describe("ollama provider models", () => {
8901021 return ;
8911022 }
8921023 if ( request . url === "/api/show" ) {
893- response . statusCode = 500 ;
894- response . end ( JSON . stringify ( { error : "show failed" } ) ) ;
1024+ response . statusCode = showFailed ? 500 : 200 ;
1025+ response . end ( JSON . stringify ( showFailed ? { error : "show failed" } : { } ) ) ;
8951026 return ;
8961027 }
8971028 response . statusCode = 404 ;
0 commit comments