Skip to content

Commit 5a571fa

Browse files
committed
fix: update ollama tests to expect correct translation keys without prefix
1 parent a46cf10 commit 5a571fa

File tree

2 files changed

+9
-51
lines changed

2 files changed

+9
-51
lines changed

src/services/code-index/embedders/__tests__/ollama.spec.ts

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,6 @@ import { CodeIndexOllamaEmbedder } from "../ollama"
55
// Mock fetch
66
global.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
419
const 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
})

src/services/code-index/shared/validation-helpers.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,7 @@ export function handleValidationError(
146146
}
147147
}
148148

149-
// For generic errors, check if it's a meaningful error message
150-
if (errorMessage && errorMessage !== "Unknown error") {
151-
// For LMStudio, we need to return the translation key
152-
if (embedderType === "lmstudio") {
153-
return { valid: false, error: "embeddings:validation.configurationError" }
154-
}
155-
// For other embedders, preserve the original error message
156-
return { valid: false, error: errorMessage }
157-
}
158-
159-
// Fallback to generic error
149+
// For generic errors, always return the translation key for consistency
160150
return { valid: false, error: "embeddings:validation.configurationError" }
161151
}
162152

0 commit comments

Comments
 (0)