Skip to content

Commit 890982a

Browse files
authored
fix(core): make the commented-out test workable (google-gemini#3885)
1 parent b3cbde5 commit 890982a

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

packages/core/src/config/config.test.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
DEFAULT_TELEMETRY_TARGET,
1313
DEFAULT_OTLP_ENDPOINT,
1414
} from '../telemetry/index.js';
15-
15+
import {
16+
AuthType,
17+
createContentGeneratorConfig,
18+
} from '../core/contentGenerator.js';
19+
import { GeminiClient } from '../core/client.js';
1620
import { loadServerHierarchicalMemory } from '../utils/memoryDiscovery.js';
1721

1822
// Mock dependencies that might be called during Config construction or createServerConfig
@@ -59,7 +63,7 @@ vi.mock('../core/contentGenerator.js', async (importOriginal) => {
5963

6064
vi.mock('../core/client.js', () => ({
6165
GeminiClient: vi.fn().mockImplementation(() => ({
62-
// Mock any methods on GeminiClient that might be used.
66+
initialize: vi.fn().mockResolvedValue(undefined),
6367
})),
6468
}));
6569

@@ -104,31 +108,33 @@ describe('Server Config (config.ts)', () => {
104108
vi.clearAllMocks();
105109
});
106110

107-
// i can't get vi mocking to import in core. only in cli. can't fix it now.
108-
// describe('refreshAuth', () => {
109-
// it('should refresh auth and update config', async () => {
110-
// const config = new Config(baseParams);
111-
// const newModel = 'gemini-ultra';
112-
// const authType = AuthType.USE_GEMINI;
113-
// const mockContentConfig = {
114-
// model: newModel,
115-
// apiKey: 'test-key',
116-
// };
117-
118-
// (createContentGeneratorConfig as vi.Mock).mockResolvedValue(
119-
// mockContentConfig,
120-
// );
121-
122-
// await config.refreshAuth(authType);
123-
124-
// expect(createContentGeneratorConfig).toHaveBeenCalledWith(
125-
// newModel,
126-
// authType,
127-
// );
128-
// expect(config.getContentGeneratorConfig()).toEqual(mockContentConfig);
129-
// expect(GeminiClient).toHaveBeenCalledWith(config);
130-
// });
131-
// });
111+
describe('refreshAuth', () => {
112+
it('should refresh auth and update config', async () => {
113+
const config = new Config(baseParams);
114+
const authType = AuthType.USE_GEMINI;
115+
const newModel = 'gemini-flash';
116+
const mockContentConfig = {
117+
model: newModel,
118+
apiKey: 'test-key',
119+
};
120+
121+
(createContentGeneratorConfig as Mock).mockResolvedValue(
122+
mockContentConfig,
123+
);
124+
125+
await config.refreshAuth(authType);
126+
127+
expect(createContentGeneratorConfig).toHaveBeenCalledWith(
128+
MODEL, // Should be called with the original model 'gemini-pro'
129+
authType,
130+
);
131+
// Verify that contentGeneratorConfig is updated with the new model
132+
expect(config.getContentGeneratorConfig()).toEqual(mockContentConfig);
133+
expect(config.getContentGeneratorConfig().model).toBe(newModel);
134+
expect(config.getModel()).toBe(newModel); // getModel() should return the updated model
135+
expect(GeminiClient).toHaveBeenCalledWith(config);
136+
});
137+
});
132138

133139
it('Config constructor should store userMemory correctly', () => {
134140
const config = new Config(baseParams);

0 commit comments

Comments
 (0)