@@ -194,6 +194,81 @@ describe("ollama provider models", () => {
194194 ) . toBe ( true ) ;
195195 } ) ;
196196
197+ it . each ( [
198+ {
199+ description : "retains authoritative list metadata when model inspection fails" ,
200+ showResponse : ( ) => jsonResponse ( { error : "inspection unavailable" } , 503 ) ,
201+ contextWindow : 32_768 ,
202+ supportsTools : true ,
203+ } ,
204+ {
205+ description : "retains list metadata omitted from a successful model inspection" ,
206+ showResponse : ( ) => jsonResponse ( { } ) ,
207+ contextWindow : 32_768 ,
208+ supportsTools : true ,
209+ } ,
210+ {
211+ description : "prefers explicit model-inspection metadata over the model list" ,
212+ showResponse : ( ) =>
213+ jsonResponse ( {
214+ model_info : { "gemma.context_length" : 65_536 } ,
215+ capabilities : [ "completion" ] ,
216+ } ) ,
217+ contextWindow : 65_536 ,
218+ supportsTools : false ,
219+ } ,
220+ ] ) ( "$description" , async ( { showResponse, contextWindow, supportsTools } ) => {
221+ vi . stubGlobal (
222+ "fetch" ,
223+ vi . fn ( async ( input : string | URL | Request ) =>
224+ requestUrl ( input ) . endsWith ( "/api/tags" )
225+ ? jsonResponse ( {
226+ models : [
227+ {
228+ name : "gemma4:e2b" ,
229+ details : { context_length : 32_768 } ,
230+ capabilities : [ "completion" , "tools" ] ,
231+ } ,
232+ ] ,
233+ } )
234+ : showResponse ( ) ,
235+ ) ,
236+ ) ;
237+
238+ const provider = await buildOllamaProvider ( "http://127.0.0.1:11434" ) ;
239+
240+ expect ( provider . models ) . toEqual ( [
241+ expect . objectContaining ( {
242+ id : "gemma4:e2b" ,
243+ contextWindow,
244+ compat : expect . objectContaining ( { supportsTools } ) ,
245+ } ) ,
246+ ] ) ;
247+ } ) ;
248+
249+ it ( "keeps an explicit empty model-inspection capability list authoritative" , async ( ) => {
250+ vi . stubGlobal (
251+ "fetch" ,
252+ vi . fn ( async ( input : string | URL | Request ) =>
253+ requestUrl ( input ) . endsWith ( "/api/tags" )
254+ ? jsonResponse ( {
255+ models : [
256+ {
257+ name : "gemma4:e2b" ,
258+ details : { context_length : 32_768 } ,
259+ capabilities : [ "completion" , "tools" ] ,
260+ } ,
261+ ] ,
262+ } )
263+ : jsonResponse ( { capabilities : [ ] } ) ,
264+ ) ,
265+ ) ;
266+
267+ await expect ( buildOllamaProvider ( "http://127.0.0.1:11434" ) ) . resolves . toMatchObject ( {
268+ models : [ ] ,
269+ } ) ;
270+ } ) ;
271+
197272 it ( "forwards remote auth to model listing and show probes" , async ( ) => {
198273 const fetchMock = vi . fn ( async ( input : string | URL | Request , init ?: RequestInit ) => {
199274 expect ( new Headers ( init ?. headers ) . get ( "Authorization" ) ) . toBe ( "Bearer cloud-key" ) ;
@@ -787,13 +862,29 @@ describe("ollama provider models", () => {
787862 }
788863 } ) ;
789864
790- it ( "keeps tools off after a live /api/show failure" , async ( ) => {
865+ it . each ( [
866+ {
867+ description : "keeps tools off after a live inspection failure without list metadata" ,
868+ listed : { name : "deepseek-r1:14b" , digest : "sha256:show-failure" } ,
869+ expected : { contextWindow : OLLAMA_DEFAULT_CONTEXT_WINDOW , supportsTools : false } ,
870+ } ,
871+ {
872+ description : "preserves authoritative list metadata after a live inspection failure" ,
873+ listed : {
874+ name : "gemma4:e2b" ,
875+ digest : "sha256:list-metadata" ,
876+ details : { context_length : 32_768 } ,
877+ capabilities : [ "completion" , "tools" ] ,
878+ } ,
879+ expected : { contextWindow : 32_768 , supportsTools : true } ,
880+ } ,
881+ ] ) ( "$description" , async ( { listed, expected } ) => {
791882 const server = createServer ( ( request , response ) => {
792883 response . setHeader ( "Content-Type" , "application/json" ) ;
793884 if ( request . url === "/api/tags" ) {
794885 response . end (
795886 JSON . stringify ( {
796- models : [ { name : "deepseek-r1:14b" , digest : "sha256:show-failure" } ] ,
887+ models : [ listed ] ,
797888 } ) ,
798889 ) ;
799890 return ;
@@ -819,9 +910,10 @@ describe("ollama provider models", () => {
819910 const provider = await buildOllamaProvider ( `http://127.0.0.1:${ address . port } ` ) ;
820911 const model = expectDefined ( provider . models ?. [ 0 ] , "show-failed Ollama model" ) ;
821912
822- expect ( model . id ) . toBe ( "deepseek-r1:14b" ) ;
823- expect ( model . compat ?. supportsTools ) . toBe ( false ) ;
824- expect ( model . reasoning ) . toBe ( true ) ;
913+ expect ( model . id ) . toBe ( listed . name ) ;
914+ expect ( model . contextWindow ) . toBe ( expected . contextWindow ) ;
915+ expect ( model . compat ?. supportsTools ) . toBe ( expected . supportsTools ) ;
916+ expect ( model . reasoning ) . toBe ( listed . name . startsWith ( "deepseek-r1" ) ) ;
825917 } finally {
826918 if ( server . listening ) {
827919 await new Promise < void > ( ( resolve , reject ) => {
0 commit comments