@@ -109,10 +109,14 @@ describe("Ollama Fetcher", () => {
109109 const result = await getOllamaModels ( baseUrl )
110110
111111 expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 )
112- expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /api/tags` )
112+ expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /api/tags` , { timeout : 10000 } )
113113
114114 expect ( mockedAxios . post ) . toHaveBeenCalledTimes ( 1 )
115- expect ( mockedAxios . post ) . toHaveBeenCalledWith ( `${ baseUrl } /api/show` , { model : modelName } )
115+ expect ( mockedAxios . post ) . toHaveBeenCalledWith (
116+ `${ baseUrl } /api/show` ,
117+ { model : modelName } ,
118+ { timeout : 10000 } ,
119+ )
116120
117121 expect ( typeof result ) . toBe ( "object" )
118122 expect ( result ) . not . toBeInstanceOf ( Array )
@@ -131,7 +135,7 @@ describe("Ollama Fetcher", () => {
131135 const result = await getOllamaModels ( baseUrl )
132136
133137 expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 )
134- expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /api/tags` )
138+ expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /api/tags` , { timeout : 10000 } )
135139 expect ( mockedAxios . post ) . not . toHaveBeenCalled ( )
136140 expect ( result ) . toEqual ( { } )
137141 } )
@@ -147,14 +151,33 @@ describe("Ollama Fetcher", () => {
147151 const result = await getOllamaModels ( baseUrl )
148152
149153 expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 )
150- expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /api/tags` )
154+ expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /api/tags` , { timeout : 10000 } )
151155 expect ( mockedAxios . post ) . not . toHaveBeenCalled ( )
152156 expect ( consoleInfoSpy ) . toHaveBeenCalledWith ( `Failed connecting to Ollama at ${ baseUrl } ` )
153157 expect ( result ) . toEqual ( { } )
154158
155159 consoleInfoSpy . mockRestore ( ) // Restore original console.info
156160 } )
157161
162+ it ( "should log a warning message and return an empty object on timeout" , async ( ) => {
163+ const baseUrl = "http://localhost:11434"
164+ const consoleWarnSpy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) // Spy and suppress output
165+
166+ const timeoutError = new Error ( "timeout of 10000ms exceeded" ) as any
167+ timeoutError . code = "ECONNABORTED"
168+ mockedAxios . get . mockRejectedValueOnce ( timeoutError )
169+
170+ const result = await getOllamaModels ( baseUrl )
171+
172+ expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 )
173+ expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /api/tags` , { timeout : 10000 } )
174+ expect ( mockedAxios . post ) . not . toHaveBeenCalled ( )
175+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith ( `Connection to Ollama at ${ baseUrl } timed out after 10 seconds` )
176+ expect ( result ) . toEqual ( { } )
177+
178+ consoleWarnSpy . mockRestore ( ) // Restore original console.warn
179+ } )
180+
158181 it ( "should handle models with null families field in API response" , async ( ) => {
159182 const baseUrl = "http://localhost:11434"
160183 const modelName = "test-model:latest"
@@ -205,10 +228,14 @@ describe("Ollama Fetcher", () => {
205228 const result = await getOllamaModels ( baseUrl )
206229
207230 expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 )
208- expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /api/tags` )
231+ expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl } /api/tags` , { timeout : 10000 } )
209232
210233 expect ( mockedAxios . post ) . toHaveBeenCalledTimes ( 1 )
211- expect ( mockedAxios . post ) . toHaveBeenCalledWith ( `${ baseUrl } /api/show` , { model : modelName } )
234+ expect ( mockedAxios . post ) . toHaveBeenCalledWith (
235+ `${ baseUrl } /api/show` ,
236+ { model : modelName } ,
237+ { timeout : 10000 } ,
238+ )
212239
213240 expect ( typeof result ) . toBe ( "object" )
214241 expect ( result ) . not . toBeInstanceOf ( Array )
0 commit comments