@@ -5,38 +5,6 @@ import { CodeIndexOllamaEmbedder } from "../ollama"
55// Mock fetch
66global . fetch = vitest . fn ( ) as MockedFunction < typeof fetch >
77
8- // Mock i18n
9- vitest . mock ( "../../../../i18n" , ( ) => ( {
10- t : ( key : string , params ?: Record < string , any > ) => {
11- const translations : Record < string , string > = {
12- "embeddings:validation.serviceUnavailable" :
13- "The embedder service is not available. Please ensure it is running and accessible." ,
14- "embeddings:validation.modelNotAvailable" :
15- "The specified model is not available. Please check your model configuration." ,
16- "embeddings:validation.connectionFailed" :
17- "Failed to connect to the embedder service. Please check your connection settings and ensure the service is running." ,
18- "embeddings:validation.configurationError" : "Invalid embedder configuration. Please review your settings." ,
19- "embeddings:errors.ollama.serviceNotRunning" :
20- "Ollama service is not running at {{baseUrl}}. Please start Ollama first." ,
21- "embeddings:errors.ollama.serviceUnavailable" :
22- "Ollama service is unavailable at {{baseUrl}}. HTTP status: {{status}}" ,
23- "embeddings:errors.ollama.modelNotFound" :
24- "Model '{{model}}' not found. Available models: {{availableModels}}" ,
25- "embeddings:errors.ollama.modelNotEmbedding" : "Model '{{model}}' is not embedding capable" ,
26- "embeddings:errors.ollama.hostNotFound" : "Ollama host not found: {{baseUrl}}" ,
27- "embeddings:errors.ollama.connectionTimeout" : "Connection to Ollama timed out at {{baseUrl}}" ,
28- }
29- // Handle parameter substitution
30- let result = translations [ key ] || key
31- if ( params ) {
32- Object . entries ( params ) . forEach ( ( [ param , value ] ) => {
33- result = result . replace ( new RegExp ( `{{${ param } }}` , "g" ) , String ( value ) )
34- } )
35- }
36- return result
37- } ,
38- } ) )
39-
408// Mock console methods
419const consoleMocks = {
4210 error : vitest . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ,
@@ -127,7 +95,7 @@ describe("CodeIndexOllamaEmbedder", () => {
12795 const result = await embedder . validateConfiguration ( )
12896
12997 expect ( result . valid ) . toBe ( false )
130- expect ( result . error ) . toBe ( "embeddings: ollama.serviceNotRunning" )
98+ expect ( result . error ) . toBe ( "ollama.serviceNotRunning" )
13199 } )
132100
133101 it ( "should fail validation when tags endpoint returns 404" , async ( ) => {
@@ -141,7 +109,7 @@ describe("CodeIndexOllamaEmbedder", () => {
141109 const result = await embedder . validateConfiguration ( )
142110
143111 expect ( result . valid ) . toBe ( false )
144- expect ( result . error ) . toBe ( "embeddings: ollama.serviceNotRunning" )
112+ expect ( result . error ) . toBe ( "ollama.serviceNotRunning" )
145113 } )
146114
147115 it ( "should fail validation when tags endpoint returns other error" , async ( ) => {
@@ -155,7 +123,7 @@ describe("CodeIndexOllamaEmbedder", () => {
155123 const result = await embedder . validateConfiguration ( )
156124
157125 expect ( result . valid ) . toBe ( false )
158- expect ( result . error ) . toBe ( "embeddings: ollama.serviceUnavailable" )
126+ expect ( result . error ) . toBe ( "ollama.serviceUnavailable" )
159127 } )
160128
161129 it ( "should fail validation when model does not exist" , async ( ) => {
@@ -174,7 +142,7 @@ describe("CodeIndexOllamaEmbedder", () => {
174142 const result = await embedder . validateConfiguration ( )
175143
176144 expect ( result . valid ) . toBe ( false )
177- expect ( result . error ) . toBe ( "embeddings: ollama.modelNotFound" )
145+ expect ( result . error ) . toBe ( "ollama.modelNotFound" )
178146 } )
179147
180148 it ( "should fail validation when model exists but doesn't support embeddings" , async ( ) => {
@@ -201,7 +169,7 @@ describe("CodeIndexOllamaEmbedder", () => {
201169 const result = await embedder . validateConfiguration ( )
202170
203171 expect ( result . valid ) . toBe ( false )
204- expect ( result . error ) . toBe ( "embeddings: ollama.modelNotEmbeddingCapable" )
172+ expect ( result . error ) . toBe ( "ollama.modelNotEmbeddingCapable" )
205173 } )
206174
207175 it ( "should handle ECONNREFUSED errors" , async ( ) => {
@@ -210,7 +178,7 @@ describe("CodeIndexOllamaEmbedder", () => {
210178 const result = await embedder . validateConfiguration ( )
211179
212180 expect ( result . valid ) . toBe ( false )
213- expect ( result . error ) . toBe ( "embeddings: ollama.serviceNotRunning" )
181+ expect ( result . error ) . toBe ( "ollama.serviceNotRunning" )
214182 } )
215183
216184 it ( "should handle ENOTFOUND errors" , async ( ) => {
@@ -219,7 +187,7 @@ describe("CodeIndexOllamaEmbedder", () => {
219187 const result = await embedder . validateConfiguration ( )
220188
221189 expect ( result . valid ) . toBe ( false )
222- expect ( result . error ) . toBe ( "embeddings: ollama.hostNotFound" )
190+ expect ( result . error ) . toBe ( "ollama.hostNotFound" )
223191 } )
224192
225193 it ( "should handle generic network errors" , async ( ) => {
@@ -228,7 +196,7 @@ describe("CodeIndexOllamaEmbedder", () => {
228196 const result = await embedder . validateConfiguration ( )
229197
230198 expect ( result . valid ) . toBe ( false )
231- expect ( result . error ) . toBe ( "Network timeout " )
199+ expect ( result . error ) . toBe ( "embeddings:validation.configurationError " )
232200 } )
233201 } )
234202} )
0 commit comments