From 2a9ca5538b9fe3a8bc0ea9cbebdd6466f0d1ccf6 Mon Sep 17 00:00:00 2001 From: deyim <31646720+deyim@users.noreply.github.com> Date: Thu, 8 Jan 2026 10:55:27 -0800 Subject: [PATCH] Add test for the new string handling --- .../core/src/core/contentGenerator.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/core/src/core/contentGenerator.test.ts b/packages/core/src/core/contentGenerator.test.ts index 42c72262c5..2131968c54 100644 --- a/packages/core/src/core/contentGenerator.test.ts +++ b/packages/core/src/core/contentGenerator.test.ts @@ -411,6 +411,45 @@ describe('createContentGenerator', () => { ); }); + it('should not include apiVersion when GOOGLE_GENAI_API_VERSION is an empty string', async () => { + const mockConfig = { + getModel: vi.fn().mockReturnValue('gemini-pro'), + getProxy: vi.fn().mockReturnValue(undefined), + getUsageStatisticsEnabled: () => false, + getPreviewFeatures: vi.fn().mockReturnValue(false), + } as unknown as Config; + + const mockGenerator = { + models: {}, + } as unknown as GoogleGenAI; + vi.mocked(GoogleGenAI).mockImplementation(() => mockGenerator as never); + vi.stubEnv('GOOGLE_GENAI_API_VERSION', ''); + + await createContentGenerator( + { + apiKey: 'test-api-key', + authType: AuthType.USE_GEMINI, + }, + mockConfig, + ); + + expect(GoogleGenAI).toHaveBeenCalledWith({ + apiKey: 'test-api-key', + vertexai: undefined, + httpOptions: { + headers: expect.objectContaining({ + 'User-Agent': expect.any(String), + }), + }, + }); + // Explicitly assert that apiVersion is NOT present when env var is empty string + expect(GoogleGenAI).toHaveBeenCalledWith( + expect.not.objectContaining({ + apiVersion: expect.any(String), + }), + ); + }); + it('should pass apiVersion for Vertex AI when GOOGLE_GENAI_API_VERSION is set', async () => { const mockConfig = { getModel: vi.fn().mockReturnValue('gemini-pro'),