From 890982a811e22de9525148e6c28f39bfbf10a49a Mon Sep 17 00:00:00 2001 From: Yuki Okita <44797866+y-okt@users.noreply.github.com> Date: Sun, 13 Jul 2025 04:13:22 +0900 Subject: [PATCH] fix(core): make the commented-out test workable (#3885) --- packages/core/src/config/config.test.ts | 54 ++++++++++++++----------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/packages/core/src/config/config.test.ts b/packages/core/src/config/config.test.ts index c9debdbe..c9965e87 100644 --- a/packages/core/src/config/config.test.ts +++ b/packages/core/src/config/config.test.ts @@ -12,7 +12,11 @@ import { DEFAULT_TELEMETRY_TARGET, DEFAULT_OTLP_ENDPOINT, } from '../telemetry/index.js'; - +import { + AuthType, + createContentGeneratorConfig, +} from '../core/contentGenerator.js'; +import { GeminiClient } from '../core/client.js'; import { loadServerHierarchicalMemory } from '../utils/memoryDiscovery.js'; // Mock dependencies that might be called during Config construction or createServerConfig @@ -59,7 +63,7 @@ vi.mock('../core/contentGenerator.js', async (importOriginal) => { vi.mock('../core/client.js', () => ({ GeminiClient: vi.fn().mockImplementation(() => ({ - // Mock any methods on GeminiClient that might be used. + initialize: vi.fn().mockResolvedValue(undefined), })), })); @@ -104,31 +108,33 @@ describe('Server Config (config.ts)', () => { vi.clearAllMocks(); }); - // i can't get vi mocking to import in core. only in cli. can't fix it now. - // describe('refreshAuth', () => { - // it('should refresh auth and update config', async () => { - // const config = new Config(baseParams); - // const newModel = 'gemini-ultra'; - // const authType = AuthType.USE_GEMINI; - // const mockContentConfig = { - // model: newModel, - // apiKey: 'test-key', - // }; + describe('refreshAuth', () => { + it('should refresh auth and update config', async () => { + const config = new Config(baseParams); + const authType = AuthType.USE_GEMINI; + const newModel = 'gemini-flash'; + const mockContentConfig = { + model: newModel, + apiKey: 'test-key', + }; - // (createContentGeneratorConfig as vi.Mock).mockResolvedValue( - // mockContentConfig, - // ); + (createContentGeneratorConfig as Mock).mockResolvedValue( + mockContentConfig, + ); - // await config.refreshAuth(authType); + await config.refreshAuth(authType); - // expect(createContentGeneratorConfig).toHaveBeenCalledWith( - // newModel, - // authType, - // ); - // expect(config.getContentGeneratorConfig()).toEqual(mockContentConfig); - // expect(GeminiClient).toHaveBeenCalledWith(config); - // }); - // }); + expect(createContentGeneratorConfig).toHaveBeenCalledWith( + MODEL, // Should be called with the original model 'gemini-pro' + authType, + ); + // Verify that contentGeneratorConfig is updated with the new model + expect(config.getContentGeneratorConfig()).toEqual(mockContentConfig); + expect(config.getContentGeneratorConfig().model).toBe(newModel); + expect(config.getModel()).toBe(newModel); // getModel() should return the updated model + expect(GeminiClient).toHaveBeenCalledWith(config); + }); + }); it('Config constructor should store userMemory correctly', () => { const config = new Config(baseParams);