From 5a571fa549cea66d0d92bc66b46233c655fff63b Mon Sep 17 00:00:00 2001 From: Daniel Riccio Date: Thu, 10 Jul 2025 16:32:52 -0500 Subject: [PATCH] fix: update ollama tests to expect correct translation keys without prefix --- .../embedders/__tests__/ollama.spec.ts | 48 ++++--------------- .../code-index/shared/validation-helpers.ts | 12 +---- 2 files changed, 9 insertions(+), 51 deletions(-) diff --git a/src/services/code-index/embedders/__tests__/ollama.spec.ts b/src/services/code-index/embedders/__tests__/ollama.spec.ts index 7d625a83fe..25a3b3865b 100644 --- a/src/services/code-index/embedders/__tests__/ollama.spec.ts +++ b/src/services/code-index/embedders/__tests__/ollama.spec.ts @@ -5,38 +5,6 @@ import { CodeIndexOllamaEmbedder } from "../ollama" // Mock fetch global.fetch = vitest.fn() as MockedFunction -// Mock i18n -vitest.mock("../../../../i18n", () => ({ - t: (key: string, params?: Record) => { - const translations: Record = { - "embeddings:validation.serviceUnavailable": - "The embedder service is not available. Please ensure it is running and accessible.", - "embeddings:validation.modelNotAvailable": - "The specified model is not available. Please check your model configuration.", - "embeddings:validation.connectionFailed": - "Failed to connect to the embedder service. Please check your connection settings and ensure the service is running.", - "embeddings:validation.configurationError": "Invalid embedder configuration. Please review your settings.", - "embeddings:errors.ollama.serviceNotRunning": - "Ollama service is not running at {{baseUrl}}. Please start Ollama first.", - "embeddings:errors.ollama.serviceUnavailable": - "Ollama service is unavailable at {{baseUrl}}. HTTP status: {{status}}", - "embeddings:errors.ollama.modelNotFound": - "Model '{{model}}' not found. Available models: {{availableModels}}", - "embeddings:errors.ollama.modelNotEmbedding": "Model '{{model}}' is not embedding capable", - "embeddings:errors.ollama.hostNotFound": "Ollama host not found: {{baseUrl}}", - "embeddings:errors.ollama.connectionTimeout": "Connection to Ollama timed out at {{baseUrl}}", - } - // Handle parameter substitution - let result = translations[key] || key - if (params) { - Object.entries(params).forEach(([param, value]) => { - result = result.replace(new RegExp(`{{${param}}}`, "g"), String(value)) - }) - } - return result - }, -})) - // Mock console methods const consoleMocks = { error: vitest.spyOn(console, "error").mockImplementation(() => {}), @@ -127,7 +95,7 @@ describe("CodeIndexOllamaEmbedder", () => { const result = await embedder.validateConfiguration() expect(result.valid).toBe(false) - expect(result.error).toBe("embeddings:ollama.serviceNotRunning") + expect(result.error).toBe("ollama.serviceNotRunning") }) it("should fail validation when tags endpoint returns 404", async () => { @@ -141,7 +109,7 @@ describe("CodeIndexOllamaEmbedder", () => { const result = await embedder.validateConfiguration() expect(result.valid).toBe(false) - expect(result.error).toBe("embeddings:ollama.serviceNotRunning") + expect(result.error).toBe("ollama.serviceNotRunning") }) it("should fail validation when tags endpoint returns other error", async () => { @@ -155,7 +123,7 @@ describe("CodeIndexOllamaEmbedder", () => { const result = await embedder.validateConfiguration() expect(result.valid).toBe(false) - expect(result.error).toBe("embeddings:ollama.serviceUnavailable") + expect(result.error).toBe("ollama.serviceUnavailable") }) it("should fail validation when model does not exist", async () => { @@ -174,7 +142,7 @@ describe("CodeIndexOllamaEmbedder", () => { const result = await embedder.validateConfiguration() expect(result.valid).toBe(false) - expect(result.error).toBe("embeddings:ollama.modelNotFound") + expect(result.error).toBe("ollama.modelNotFound") }) it("should fail validation when model exists but doesn't support embeddings", async () => { @@ -201,7 +169,7 @@ describe("CodeIndexOllamaEmbedder", () => { const result = await embedder.validateConfiguration() expect(result.valid).toBe(false) - expect(result.error).toBe("embeddings:ollama.modelNotEmbeddingCapable") + expect(result.error).toBe("ollama.modelNotEmbeddingCapable") }) it("should handle ECONNREFUSED errors", async () => { @@ -210,7 +178,7 @@ describe("CodeIndexOllamaEmbedder", () => { const result = await embedder.validateConfiguration() expect(result.valid).toBe(false) - expect(result.error).toBe("embeddings:ollama.serviceNotRunning") + expect(result.error).toBe("ollama.serviceNotRunning") }) it("should handle ENOTFOUND errors", async () => { @@ -219,7 +187,7 @@ describe("CodeIndexOllamaEmbedder", () => { const result = await embedder.validateConfiguration() expect(result.valid).toBe(false) - expect(result.error).toBe("embeddings:ollama.hostNotFound") + expect(result.error).toBe("ollama.hostNotFound") }) it("should handle generic network errors", async () => { @@ -228,7 +196,7 @@ describe("CodeIndexOllamaEmbedder", () => { const result = await embedder.validateConfiguration() expect(result.valid).toBe(false) - expect(result.error).toBe("Network timeout") + expect(result.error).toBe("embeddings:validation.configurationError") }) }) }) diff --git a/src/services/code-index/shared/validation-helpers.ts b/src/services/code-index/shared/validation-helpers.ts index ed26d82030..6f3ee7670a 100644 --- a/src/services/code-index/shared/validation-helpers.ts +++ b/src/services/code-index/shared/validation-helpers.ts @@ -146,17 +146,7 @@ export function handleValidationError( } } - // For generic errors, check if it's a meaningful error message - if (errorMessage && errorMessage !== "Unknown error") { - // For LMStudio, we need to return the translation key - if (embedderType === "lmstudio") { - return { valid: false, error: "embeddings:validation.configurationError" } - } - // For other embedders, preserve the original error message - return { valid: false, error: errorMessage } - } - - // Fallback to generic error + // For generic errors, always return the translation key for consistency return { valid: false, error: "embeddings:validation.configurationError" } }