@@ -80,6 +80,90 @@ describe("CodeIndexOllamaEmbedder", () => {
8080 const embedderWithDefaults = new CodeIndexOllamaEmbedder ( { } )
8181 expect ( embedderWithDefaults . embedderInfo . name ) . toBe ( "ollama" )
8282 } )
83+
84+ it ( "should normalize URLs with trailing slashes" , async ( ) => {
85+ // Create embedder with URL that has a trailing slash
86+ const embedderWithTrailingSlash = new CodeIndexOllamaEmbedder ( {
87+ ollamaBaseUrl : "http://localhost:11434/" ,
88+ ollamaModelId : "nomic-embed-text" ,
89+ } )
90+
91+ // Mock successful /api/tags call to test the normalized URL
92+ mockFetch . mockImplementationOnce ( ( ) =>
93+ Promise . resolve ( {
94+ ok : true ,
95+ status : 200 ,
96+ json : ( ) => Promise . resolve ( { models : [ { name : "nomic-embed-text" } ] } ) ,
97+ } as Response ) ,
98+ )
99+
100+ // Call a method that uses the baseUrl
101+ await embedderWithTrailingSlash . validateConfiguration ( )
102+
103+ // Verify the URL used in the fetch call doesn't have a trailing slash
104+ expect ( mockFetch ) . toHaveBeenCalledWith (
105+ "http://localhost:11434/api/tags" ,
106+ expect . objectContaining ( {
107+ method : "GET" ,
108+ } ) ,
109+ )
110+ } )
111+
112+ it ( "should not modify URLs without trailing slashes" , async ( ) => {
113+ // Create embedder with URL that doesn't have a trailing slash
114+ const embedderWithoutTrailingSlash = new CodeIndexOllamaEmbedder ( {
115+ ollamaBaseUrl : "http://localhost:11434" ,
116+ ollamaModelId : "nomic-embed-text" ,
117+ } )
118+
119+ // Mock successful /api/tags call
120+ mockFetch . mockImplementationOnce ( ( ) =>
121+ Promise . resolve ( {
122+ ok : true ,
123+ status : 200 ,
124+ json : ( ) => Promise . resolve ( { models : [ { name : "nomic-embed-text" } ] } ) ,
125+ } as Response ) ,
126+ )
127+
128+ // Call a method that uses the baseUrl
129+ await embedderWithoutTrailingSlash . validateConfiguration ( )
130+
131+ // Verify the URL used in the fetch call is correct
132+ expect ( mockFetch ) . toHaveBeenCalledWith (
133+ "http://localhost:11434/api/tags" ,
134+ expect . objectContaining ( {
135+ method : "GET" ,
136+ } ) ,
137+ )
138+ } )
139+
140+ it ( "should handle multiple trailing slashes" , async ( ) => {
141+ // Create embedder with URL that has multiple trailing slashes
142+ const embedderWithMultipleTrailingSlashes = new CodeIndexOllamaEmbedder ( {
143+ ollamaBaseUrl : "http://localhost:11434///" ,
144+ ollamaModelId : "nomic-embed-text" ,
145+ } )
146+
147+ // Mock successful /api/tags call
148+ mockFetch . mockImplementationOnce ( ( ) =>
149+ Promise . resolve ( {
150+ ok : true ,
151+ status : 200 ,
152+ json : ( ) => Promise . resolve ( { models : [ { name : "nomic-embed-text" } ] } ) ,
153+ } as Response ) ,
154+ )
155+
156+ // Call a method that uses the baseUrl
157+ await embedderWithMultipleTrailingSlashes . validateConfiguration ( )
158+
159+ // Verify the URL used in the fetch call doesn't have trailing slashes
160+ expect ( mockFetch ) . toHaveBeenCalledWith (
161+ "http://localhost:11434/api/tags" ,
162+ expect . objectContaining ( {
163+ method : "GET" ,
164+ } ) ,
165+ )
166+ } )
83167 } )
84168
85169 describe ( "validateConfiguration" , ( ) => {
0 commit comments