From 4cf239f165c1fc96dc153ca19b2fbf0c6d9d173c Mon Sep 17 00:00:00 2001 From: icarus Date: Sat, 30 Aug 2025 02:18:46 +0800 Subject: [PATCH] =?UTF-8?q?test(aiCore):=20=E6=9B=B4=E6=96=B0=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E5=85=BC=E5=AE=B9=E6=80=A7=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=9A=84mock=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加isOpenAIModel等mock函数用于测试 修复AnthropicVertexClient的mock路径 添加注释说明服务层不应调用React Hook --- .../__tests__/index.clientCompatibilityTypes.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/aiCore/legacy/clients/__tests__/index.clientCompatibilityTypes.test.ts b/src/renderer/src/aiCore/legacy/clients/__tests__/index.clientCompatibilityTypes.test.ts index f8a169496..48bd230d8 100644 --- a/src/renderer/src/aiCore/legacy/clients/__tests__/index.clientCompatibilityTypes.test.ts +++ b/src/renderer/src/aiCore/legacy/clients/__tests__/index.clientCompatibilityTypes.test.ts @@ -21,6 +21,7 @@ vi.mock('@renderer/config/models', () => ({ anthropic: [], gemini: [] }, + isOpenAIModel: vi.fn().mockReturnValue(true), isOpenAILLMModel: vi.fn().mockReturnValue(true), isOpenAIChatCompletionOnlyModel: vi.fn().mockReturnValue(false), isAnthropicLLMModel: vi.fn().mockReturnValue(false), @@ -73,6 +74,7 @@ vi.mock('@logger', () => ({ } })) +// 到底是谁想出来的在服务层调用 React Hook ????????? // Mock additional services and hooks that might be imported vi.mock('@renderer/hooks/useVertexAI', () => ({ getVertexAILocation: vi.fn().mockReturnValue('us-central1'), @@ -80,7 +82,9 @@ vi.mock('@renderer/hooks/useVertexAI', () => ({ getVertexAIServiceAccount: vi.fn().mockReturnValue({ privateKey: 'test-key', clientEmail: 'test@example.com' - }) + }), + isVertexAIConfigured: vi.fn().mockReturnValue(true), + isVertexProvider: vi.fn().mockReturnValue(true) })) vi.mock('@renderer/hooks/useSettings', () => ({ @@ -124,7 +128,7 @@ vi.mock('@google-cloud/vertexai', () => ({ })) // Mock the circular dependency between VertexAPIClient and AnthropicVertexClient -vi.mock('@renderer/aiCore/clients/anthropic/AnthropicVertexClient', () => { +vi.mock('@renderer/aiCore/legacy/clients/anthropic/AnthropicVertexClient', () => { const MockAnthropicVertexClient = vi.fn() MockAnthropicVertexClient.prototype.getClientCompatibilityType = vi.fn().mockReturnValue(['AnthropicVertexAPIClient']) return {