mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-23 00:01:24 -07:00
chore(core): remove legacy fallback flags and migrate loop detection (#15213)
This commit is contained in:
@@ -344,10 +344,6 @@ describe('Server Config (config.ts)', () => {
|
||||
mockContentConfig,
|
||||
);
|
||||
|
||||
// Set fallback mode to true to ensure it gets reset
|
||||
config.setFallbackMode(true);
|
||||
expect(config.isInFallbackMode()).toBe(true);
|
||||
|
||||
await config.refreshAuth(authType);
|
||||
|
||||
expect(createContentGeneratorConfig).toHaveBeenCalledWith(
|
||||
@@ -357,8 +353,6 @@ describe('Server Config (config.ts)', () => {
|
||||
// Verify that contentGeneratorConfig is updated
|
||||
expect(config.getContentGeneratorConfig()).toEqual(mockContentConfig);
|
||||
expect(GeminiClient).toHaveBeenCalledWith(config);
|
||||
// Verify that fallback mode is reset
|
||||
expect(config.isInFallbackMode()).toBe(false);
|
||||
});
|
||||
|
||||
it('should reset model availability status', async () => {
|
||||
@@ -1569,40 +1563,32 @@ describe('Config getHooks', () => {
|
||||
});
|
||||
|
||||
describe('setModel', () => {
|
||||
it('should allow setting a pro (any) model and disable fallback mode', () => {
|
||||
it('should allow setting a pro (any) model and reset availability', () => {
|
||||
const config = new Config(baseParams);
|
||||
const service = config.getModelAvailabilityService();
|
||||
const spy = vi.spyOn(service, 'reset');
|
||||
|
||||
config.setFallbackMode(true);
|
||||
expect(config.isInFallbackMode()).toBe(true);
|
||||
|
||||
const proModel = 'gemini-2.5-pro';
|
||||
config.setModel(proModel);
|
||||
|
||||
expect(config.getModel()).toBe(proModel);
|
||||
expect(config.isInFallbackMode()).toBe(false);
|
||||
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith(proModel);
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should allow setting auto model from non-auto model and disable fallback mode', () => {
|
||||
it('should allow setting auto model from non-auto model and reset availability', () => {
|
||||
const config = new Config(baseParams);
|
||||
const service = config.getModelAvailabilityService();
|
||||
const spy = vi.spyOn(service, 'reset');
|
||||
|
||||
config.setFallbackMode(true);
|
||||
expect(config.isInFallbackMode()).toBe(true);
|
||||
|
||||
config.setModel('auto');
|
||||
|
||||
expect(config.getModel()).toBe('auto');
|
||||
expect(config.isInFallbackMode()).toBe(false);
|
||||
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith('auto');
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should allow setting auto model from auto model if it is in the fallback mode', () => {
|
||||
it('should allow setting auto model from auto model and reset availability', () => {
|
||||
const config = new Config({
|
||||
cwd: '/tmp',
|
||||
targetDir: '/path/to/target',
|
||||
@@ -1614,16 +1600,25 @@ describe('Config getHooks', () => {
|
||||
const service = config.getModelAvailabilityService();
|
||||
const spy = vi.spyOn(service, 'reset');
|
||||
|
||||
config.setFallbackMode(true);
|
||||
expect(config.isInFallbackMode()).toBe(true);
|
||||
|
||||
config.setModel('auto');
|
||||
|
||||
expect(config.getModel()).toBe('auto');
|
||||
expect(config.isInFallbackMode()).toBe(false);
|
||||
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith('auto');
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should reset active model when setModel is called with the current model after a fallback', () => {
|
||||
const config = new Config(baseParams);
|
||||
const originalModel = config.getModel();
|
||||
const fallbackModel = 'fallback-model';
|
||||
|
||||
config.setActiveModel(fallbackModel);
|
||||
expect(config.getActiveModel()).toBe(fallbackModel);
|
||||
|
||||
config.setModel(originalModel);
|
||||
|
||||
expect(config.getModel()).toBe(originalModel);
|
||||
expect(config.getActiveModel()).toBe(originalModel);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -388,7 +388,6 @@ export class Config {
|
||||
private readonly folderTrust: boolean;
|
||||
private ideMode: boolean;
|
||||
|
||||
private inFallbackMode = false;
|
||||
private _activeModel: string;
|
||||
private readonly maxSessionTurns: number;
|
||||
private readonly listSessions: boolean;
|
||||
@@ -447,8 +446,6 @@ export class Config {
|
||||
private experimentsPromise: Promise<void> | undefined;
|
||||
private hookSystem?: HookSystem;
|
||||
|
||||
private previewModelFallbackMode = false;
|
||||
private previewModelBypassMode = false;
|
||||
private readonly enableAgents: boolean;
|
||||
|
||||
private readonly experimentalJitContext: boolean;
|
||||
@@ -774,9 +771,6 @@ export class Config {
|
||||
this.setHasAccessToPreviewModel(true);
|
||||
}
|
||||
|
||||
// Reset the session flag since we're explicitly changing auth and using default model
|
||||
this.inFallbackMode = false;
|
||||
|
||||
// Update model if user no longer has access to the preview model
|
||||
if (!this.hasAccessToPreviewModel && isPreviewModel(this.model)) {
|
||||
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
|
||||
@@ -847,13 +841,12 @@ export class Config {
|
||||
}
|
||||
|
||||
setModel(newModel: string): void {
|
||||
if (this.model !== newModel || this.inFallbackMode) {
|
||||
if (this.model !== newModel || this._activeModel !== newModel) {
|
||||
this.model = newModel;
|
||||
// When the user explicitly sets a model, that becomes the active model.
|
||||
this._activeModel = newModel;
|
||||
coreEvents.emitModelChanged(newModel);
|
||||
}
|
||||
this.setFallbackMode(false);
|
||||
this.modelAvailabilityService.reset();
|
||||
}
|
||||
|
||||
@@ -867,18 +860,6 @@ export class Config {
|
||||
}
|
||||
}
|
||||
|
||||
resetTurn(): void {
|
||||
this.modelAvailabilityService.resetTurn();
|
||||
}
|
||||
|
||||
isInFallbackMode(): boolean {
|
||||
return this.inFallbackMode;
|
||||
}
|
||||
|
||||
setFallbackMode(active: boolean): void {
|
||||
this.inFallbackMode = active;
|
||||
}
|
||||
|
||||
setFallbackModelHandler(handler: FallbackModelHandler): void {
|
||||
this.fallbackModelHandler = handler;
|
||||
}
|
||||
@@ -887,20 +868,8 @@ export class Config {
|
||||
return this.fallbackModelHandler;
|
||||
}
|
||||
|
||||
isPreviewModelFallbackMode(): boolean {
|
||||
return this.previewModelFallbackMode;
|
||||
}
|
||||
|
||||
setPreviewModelFallbackMode(active: boolean): void {
|
||||
this.previewModelFallbackMode = active;
|
||||
}
|
||||
|
||||
isPreviewModelBypassMode(): boolean {
|
||||
return this.previewModelBypassMode;
|
||||
}
|
||||
|
||||
setPreviewModelBypassMode(active: boolean): void {
|
||||
this.previewModelBypassMode = active;
|
||||
resetTurn(): void {
|
||||
this.modelAvailabilityService.resetTurn();
|
||||
}
|
||||
|
||||
getMaxSessionTurns(): number {
|
||||
|
||||
@@ -37,27 +37,6 @@ describe('Flash Model Fallback Configuration', () => {
|
||||
};
|
||||
});
|
||||
|
||||
// These tests do not actually test fallback. isInFallbackMode() only returns true,
|
||||
// when setFallbackMode is marked as true. This is to decouple setting a model
|
||||
// with the fallback mechanism. This will be necessary we introduce more
|
||||
// intelligent model routing.
|
||||
describe('setModel', () => {
|
||||
it('should only mark as switched if contentGeneratorConfig exists', () => {
|
||||
// Create config without initializing contentGeneratorConfig
|
||||
const newConfig = new Config({
|
||||
sessionId: 'test-session-2',
|
||||
targetDir: '/test',
|
||||
debugMode: false,
|
||||
cwd: '/test',
|
||||
model: DEFAULT_GEMINI_MODEL,
|
||||
});
|
||||
|
||||
// Should not crash when contentGeneratorConfig is undefined
|
||||
newConfig.setModel(DEFAULT_GEMINI_FLASH_MODEL);
|
||||
expect(newConfig.isInFallbackMode()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getModel', () => {
|
||||
it('should return contentGeneratorConfig model if available', () => {
|
||||
// Simulate initialized content generator config
|
||||
@@ -78,26 +57,4 @@ describe('Flash Model Fallback Configuration', () => {
|
||||
expect(newConfig.getModel()).toBe('custom-model');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isInFallbackMode', () => {
|
||||
it('should start as false for new session', () => {
|
||||
expect(config.isInFallbackMode()).toBe(false);
|
||||
});
|
||||
|
||||
it('should remain false if no model switch occurs', () => {
|
||||
// Perform other operations that don't involve model switching
|
||||
expect(config.isInFallbackMode()).toBe(false);
|
||||
});
|
||||
|
||||
it('should persist switched state throughout session', () => {
|
||||
config.setModel(DEFAULT_GEMINI_FLASH_MODEL);
|
||||
// Setting state for fallback mode as is expected of clients
|
||||
config.setFallbackMode(true);
|
||||
expect(config.isInFallbackMode()).toBe(true);
|
||||
|
||||
// Should remain true even after getting model
|
||||
config.getModel();
|
||||
expect(config.isInFallbackMode()).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user