fix(core): make the commented-out test workable (#3885)

This commit is contained in:
Yuki Okita 2025-07-13 04:13:22 +09:00 committed by GitHub
parent b3cbde5cf3
commit 890982a811
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 30 additions and 24 deletions

View File

@ -12,7 +12,11 @@ import {
DEFAULT_TELEMETRY_TARGET, DEFAULT_TELEMETRY_TARGET,
DEFAULT_OTLP_ENDPOINT, DEFAULT_OTLP_ENDPOINT,
} from '../telemetry/index.js'; } from '../telemetry/index.js';
import {
AuthType,
createContentGeneratorConfig,
} from '../core/contentGenerator.js';
import { GeminiClient } from '../core/client.js';
import { loadServerHierarchicalMemory } from '../utils/memoryDiscovery.js'; import { loadServerHierarchicalMemory } from '../utils/memoryDiscovery.js';
// Mock dependencies that might be called during Config construction or createServerConfig // 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', () => ({ vi.mock('../core/client.js', () => ({
GeminiClient: vi.fn().mockImplementation(() => ({ 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(); vi.clearAllMocks();
}); });
// i can't get vi mocking to import in core. only in cli. can't fix it now. describe('refreshAuth', () => {
// describe('refreshAuth', () => { it('should refresh auth and update config', async () => {
// it('should refresh auth and update config', async () => { const config = new Config(baseParams);
// const config = new Config(baseParams); const authType = AuthType.USE_GEMINI;
// const newModel = 'gemini-ultra'; const newModel = 'gemini-flash';
// const authType = AuthType.USE_GEMINI; const mockContentConfig = {
// const mockContentConfig = { model: newModel,
// model: newModel, apiKey: 'test-key',
// apiKey: 'test-key', };
// };
// (createContentGeneratorConfig as vi.Mock).mockResolvedValue( (createContentGeneratorConfig as Mock).mockResolvedValue(
// mockContentConfig, mockContentConfig,
// ); );
// await config.refreshAuth(authType); await config.refreshAuth(authType);
// expect(createContentGeneratorConfig).toHaveBeenCalledWith( expect(createContentGeneratorConfig).toHaveBeenCalledWith(
// newModel, MODEL, // Should be called with the original model 'gemini-pro'
// authType, authType,
// ); );
// expect(config.getContentGeneratorConfig()).toEqual(mockContentConfig); // Verify that contentGeneratorConfig is updated with the new model
// expect(GeminiClient).toHaveBeenCalledWith(config); 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', () => { it('Config constructor should store userMemory correctly', () => {
const config = new Config(baseParams); const config = new Config(baseParams);