mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
feat: reset availabilityService on /auth
This commit is contained in:
committed by
Tommaso Sciortino
parent
17bf02b901
commit
4b3d858f31
@@ -123,6 +123,10 @@ export class ModelAvailabilityService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.health.clear();
|
||||||
|
}
|
||||||
|
|
||||||
private setState(model: ModelId, nextState: HealthState) {
|
private setState(model: ModelId, nextState: HealthState) {
|
||||||
this.health.set(model, nextState);
|
this.health.set(model, nextState);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,6 +351,21 @@ describe('Server Config (config.ts)', () => {
|
|||||||
expect(config.isInFallbackMode()).toBe(false);
|
expect(config.isInFallbackMode()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should reset model availability status', async () => {
|
||||||
|
const config = new Config(baseParams);
|
||||||
|
const service = config.getModelAvailabilityService();
|
||||||
|
const spy = vi.spyOn(service, 'reset');
|
||||||
|
|
||||||
|
vi.mocked(createContentGeneratorConfig).mockImplementation(
|
||||||
|
async (_: Config, authType: AuthType | undefined) =>
|
||||||
|
({ authType }) as unknown as ContentGeneratorConfig,
|
||||||
|
);
|
||||||
|
|
||||||
|
await config.refreshAuth(AuthType.USE_GEMINI);
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should strip thoughts when switching from GenAI to Vertex', async () => {
|
it('should strip thoughts when switching from GenAI to Vertex', async () => {
|
||||||
const config = new Config(baseParams);
|
const config = new Config(baseParams);
|
||||||
|
|
||||||
@@ -1488,6 +1503,9 @@ describe('Config getHooks', () => {
|
|||||||
describe('setModel', () => {
|
describe('setModel', () => {
|
||||||
it('should allow setting a pro (any) model and disable fallback mode', () => {
|
it('should allow setting a pro (any) model and disable fallback mode', () => {
|
||||||
const config = new Config(baseParams);
|
const config = new Config(baseParams);
|
||||||
|
const service = config.getModelAvailabilityService();
|
||||||
|
const spy = vi.spyOn(service, 'reset');
|
||||||
|
|
||||||
config.setFallbackMode(true);
|
config.setFallbackMode(true);
|
||||||
expect(config.isInFallbackMode()).toBe(true);
|
expect(config.isInFallbackMode()).toBe(true);
|
||||||
|
|
||||||
@@ -1497,10 +1515,14 @@ describe('Config getHooks', () => {
|
|||||||
expect(config.getModel()).toBe(proModel);
|
expect(config.getModel()).toBe(proModel);
|
||||||
expect(config.isInFallbackMode()).toBe(false);
|
expect(config.isInFallbackMode()).toBe(false);
|
||||||
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith(proModel);
|
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 disable fallback mode', () => {
|
||||||
const config = new Config(baseParams);
|
const config = new Config(baseParams);
|
||||||
|
const service = config.getModelAvailabilityService();
|
||||||
|
const spy = vi.spyOn(service, 'reset');
|
||||||
|
|
||||||
config.setFallbackMode(true);
|
config.setFallbackMode(true);
|
||||||
expect(config.isInFallbackMode()).toBe(true);
|
expect(config.isInFallbackMode()).toBe(true);
|
||||||
|
|
||||||
@@ -1509,6 +1531,7 @@ describe('Config getHooks', () => {
|
|||||||
expect(config.getModel()).toBe('auto');
|
expect(config.getModel()).toBe('auto');
|
||||||
expect(config.isInFallbackMode()).toBe(false);
|
expect(config.isInFallbackMode()).toBe(false);
|
||||||
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith('auto');
|
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 if it is in the fallback mode', () => {
|
||||||
@@ -1520,6 +1543,9 @@ describe('Config getHooks', () => {
|
|||||||
model: 'auto',
|
model: 'auto',
|
||||||
usageStatisticsEnabled: false,
|
usageStatisticsEnabled: false,
|
||||||
});
|
});
|
||||||
|
const service = config.getModelAvailabilityService();
|
||||||
|
const spy = vi.spyOn(service, 'reset');
|
||||||
|
|
||||||
config.setFallbackMode(true);
|
config.setFallbackMode(true);
|
||||||
expect(config.isInFallbackMode()).toBe(true);
|
expect(config.isInFallbackMode()).toBe(true);
|
||||||
|
|
||||||
@@ -1528,6 +1554,7 @@ describe('Config getHooks', () => {
|
|||||||
expect(config.getModel()).toBe('auto');
|
expect(config.getModel()).toBe('auto');
|
||||||
expect(config.isInFallbackMode()).toBe(false);
|
expect(config.isInFallbackMode()).toBe(false);
|
||||||
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith('auto');
|
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith('auto');
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -694,6 +694,9 @@ export class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async refreshAuth(authMethod: AuthType) {
|
async refreshAuth(authMethod: AuthType) {
|
||||||
|
// Reset availability service when switching auth
|
||||||
|
this.modelAvailabilityService.reset();
|
||||||
|
|
||||||
// Vertex and Genai have incompatible encryption and sending history with
|
// Vertex and Genai have incompatible encryption and sending history with
|
||||||
// thoughtSignature from Genai to Vertex will fail, we need to strip them
|
// thoughtSignature from Genai to Vertex will fail, we need to strip them
|
||||||
if (
|
if (
|
||||||
@@ -819,6 +822,7 @@ export class Config {
|
|||||||
coreEvents.emitModelChanged(newModel);
|
coreEvents.emitModelChanged(newModel);
|
||||||
}
|
}
|
||||||
this.setFallbackMode(false);
|
this.setFallbackMode(false);
|
||||||
|
this.modelAvailabilityService.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
getActiveModel(): string {
|
getActiveModel(): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user