@@ -108,10 +108,10 @@ describe("Ollama Fetcher", () => {
108108			const  result  =  await  getOllamaModels ( baseUrl ) 
109109
110110			expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 ) 
111- 			expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl }  ) 
111+ 			expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl }  ,   {   headers :  { }   } ) 
112112
113113			expect ( mockedAxios . post ) . toHaveBeenCalledTimes ( 1 ) 
114- 			expect ( mockedAxios . post ) . toHaveBeenCalledWith ( `${ baseUrl }  ,  {  model : modelName  } ) 
114+ 			expect ( mockedAxios . post ) . toHaveBeenCalledWith ( `${ baseUrl }  ,  {  model : modelName  } ,   {   headers :  { }   } ) 
115115
116116			expect ( typeof  result ) . toBe ( "object" ) 
117117			expect ( result ) . not . toBeInstanceOf ( Array ) 
@@ -130,7 +130,7 @@ describe("Ollama Fetcher", () => {
130130			const  result  =  await  getOllamaModels ( baseUrl ) 
131131
132132			expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 ) 
133- 			expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl }  ) 
133+ 			expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl }  ,   {   headers :  { }   } ) 
134134			expect ( mockedAxios . post ) . not . toHaveBeenCalled ( ) 
135135			expect ( result ) . toEqual ( { } ) 
136136		} ) 
@@ -146,7 +146,7 @@ describe("Ollama Fetcher", () => {
146146			const  result  =  await  getOllamaModels ( baseUrl ) 
147147
148148			expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 ) 
149- 			expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl }  ) 
149+ 			expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl }  ,   {   headers :  { }   } ) 
150150			expect ( mockedAxios . post ) . not . toHaveBeenCalled ( ) 
151151			expect ( consoleInfoSpy ) . toHaveBeenCalledWith ( `Failed connecting to Ollama at ${ baseUrl }  ) 
152152			expect ( result ) . toEqual ( { } ) 
@@ -204,10 +204,10 @@ describe("Ollama Fetcher", () => {
204204			const  result  =  await  getOllamaModels ( baseUrl ) 
205205
206206			expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 ) 
207- 			expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl }  ) 
207+ 			expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl }  ,   {   headers :  { }   } ) 
208208
209209			expect ( mockedAxios . post ) . toHaveBeenCalledTimes ( 1 ) 
210- 			expect ( mockedAxios . post ) . toHaveBeenCalledWith ( `${ baseUrl }  ,  {  model : modelName  } ) 
210+ 			expect ( mockedAxios . post ) . toHaveBeenCalledWith ( `${ baseUrl }  ,  {  model : modelName  } ,   {   headers :  { }   } ) 
211211
212212			expect ( typeof  result ) . toBe ( "object" ) 
213213			expect ( result ) . not . toBeInstanceOf ( Array ) 
@@ -217,5 +217,73 @@ describe("Ollama Fetcher", () => {
217217			// Verify the model was parsed correctly despite null families 
218218			expect ( result [ modelName ] . description ) . toBe ( "Family: llama, Context: 4096, Size: 23.6B" ) 
219219		} ) 
220+ 
221+ 		it ( "should include Authorization header when API key is provided" ,  async  ( )  =>  { 
222+ 			const  baseUrl  =  "http://localhost:11434" 
223+ 			const  apiKey  =  "test-api-key-123" 
224+ 			const  modelName  =  "test-model:latest" 
225+ 
226+ 			const  mockApiTagsResponse  =  { 
227+ 				models : [ 
228+ 					{ 
229+ 						name : modelName , 
230+ 						model : modelName , 
231+ 						modified_at : "2025-06-03T09:23:22.610222878-04:00" , 
232+ 						size : 14333928010 , 
233+ 						digest : "6a5f0c01d2c96c687d79e32fdd25b87087feb376bf9838f854d10be8cf3c10a5" , 
234+ 						details : { 
235+ 							family : "llama" , 
236+ 							families : [ "llama" ] , 
237+ 							format : "gguf" , 
238+ 							parameter_size : "23.6B" , 
239+ 							parent_model : "" , 
240+ 							quantization_level : "Q4_K_M" , 
241+ 						} , 
242+ 					} , 
243+ 				] , 
244+ 			} 
245+ 			const  mockApiShowResponse  =  { 
246+ 				license : "Mock License" , 
247+ 				modelfile : "FROM /path/to/blob\nTEMPLATE {{ .Prompt }}" , 
248+ 				parameters : "num_ctx 4096\nstop_token <eos>" , 
249+ 				template : "{{ .System }}USER: {{ .Prompt }}ASSISTANT:" , 
250+ 				modified_at : "2025-06-03T09:23:22.610222878-04:00" , 
251+ 				details : { 
252+ 					parent_model : "" , 
253+ 					format : "gguf" , 
254+ 					family : "llama" , 
255+ 					families : [ "llama" ] , 
256+ 					parameter_size : "23.6B" , 
257+ 					quantization_level : "Q4_K_M" , 
258+ 				} , 
259+ 				model_info : { 
260+ 					"ollama.context_length" : 4096 , 
261+ 					"some.other.info" : "value" , 
262+ 				} , 
263+ 				capabilities : [ "completion" ] , 
264+ 			} 
265+ 
266+ 			mockedAxios . get . mockResolvedValueOnce ( {  data : mockApiTagsResponse  } ) 
267+ 			mockedAxios . post . mockResolvedValueOnce ( {  data : mockApiShowResponse  } ) 
268+ 
269+ 			const  result  =  await  getOllamaModels ( baseUrl ,  apiKey ) 
270+ 
271+ 			const  expectedHeaders  =  {  Authorization : `Bearer ${ apiKey }   } 
272+ 
273+ 			expect ( mockedAxios . get ) . toHaveBeenCalledTimes ( 1 ) 
274+ 			expect ( mockedAxios . get ) . toHaveBeenCalledWith ( `${ baseUrl }  ,  {  headers : expectedHeaders  } ) 
275+ 
276+ 			expect ( mockedAxios . post ) . toHaveBeenCalledTimes ( 1 ) 
277+ 			expect ( mockedAxios . post ) . toHaveBeenCalledWith ( 
278+ 				`${ baseUrl }  , 
279+ 				{  model : modelName  } , 
280+ 				{  headers : expectedHeaders  } , 
281+ 			) 
282+ 
283+ 			expect ( typeof  result ) . toBe ( "object" ) 
284+ 			expect ( result ) . not . toBeInstanceOf ( Array ) 
285+ 			expect ( Object . keys ( result ) . length ) . toBe ( 1 ) 
286+ 			expect ( result [ modelName ] ) . toBeDefined ( ) 
287+ 		} ) 
220288	} ) 
221289} ) 
0 commit comments