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_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);