mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 03:54:43 -07:00
fix(core): enable numerical routing for api key users (#21977)
This commit is contained in:
@@ -492,6 +492,95 @@ describe('Server Config (config.ts)', () => {
|
||||
expect(await config.getUserCaching()).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getNumericalRoutingEnabled', () => {
|
||||
it('should return true by default if there are no experiments', async () => {
|
||||
const config = new Config(baseParams);
|
||||
expect(await config.getNumericalRoutingEnabled()).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if the remote flag is set to true', async () => {
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
experiments: {
|
||||
flags: {
|
||||
[ExperimentFlags.ENABLE_NUMERICAL_ROUTING]: {
|
||||
boolValue: true,
|
||||
},
|
||||
},
|
||||
experimentIds: [],
|
||||
},
|
||||
} as unknown as ConfigParameters);
|
||||
expect(await config.getNumericalRoutingEnabled()).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if the remote flag is explicitly set to false', async () => {
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
experiments: {
|
||||
flags: {
|
||||
[ExperimentFlags.ENABLE_NUMERICAL_ROUTING]: {
|
||||
boolValue: false,
|
||||
},
|
||||
},
|
||||
experimentIds: [],
|
||||
},
|
||||
} as unknown as ConfigParameters);
|
||||
expect(await config.getNumericalRoutingEnabled()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getResolvedClassifierThreshold', () => {
|
||||
it('should return 90 by default if there are no experiments', async () => {
|
||||
const config = new Config(baseParams);
|
||||
expect(await config.getResolvedClassifierThreshold()).toBe(90);
|
||||
});
|
||||
|
||||
it('should return the remote flag value if it is within range (0-100)', async () => {
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
experiments: {
|
||||
flags: {
|
||||
[ExperimentFlags.CLASSIFIER_THRESHOLD]: {
|
||||
intValue: '75',
|
||||
},
|
||||
},
|
||||
experimentIds: [],
|
||||
},
|
||||
} as unknown as ConfigParameters);
|
||||
expect(await config.getResolvedClassifierThreshold()).toBe(75);
|
||||
});
|
||||
|
||||
it('should return 90 if the remote flag is out of range (less than 0)', async () => {
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
experiments: {
|
||||
flags: {
|
||||
[ExperimentFlags.CLASSIFIER_THRESHOLD]: {
|
||||
intValue: '-10',
|
||||
},
|
||||
},
|
||||
experimentIds: [],
|
||||
},
|
||||
} as unknown as ConfigParameters);
|
||||
expect(await config.getResolvedClassifierThreshold()).toBe(90);
|
||||
});
|
||||
|
||||
it('should return 90 if the remote flag is out of range (greater than 100)', async () => {
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
experiments: {
|
||||
flags: {
|
||||
[ExperimentFlags.CLASSIFIER_THRESHOLD]: {
|
||||
intValue: '110',
|
||||
},
|
||||
},
|
||||
experimentIds: [],
|
||||
},
|
||||
} as unknown as ConfigParameters);
|
||||
expect(await config.getResolvedClassifierThreshold()).toBe(90);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('refreshAuth', () => {
|
||||
|
||||
@@ -2512,8 +2512,30 @@ export class Config implements McpContext, AgentLoopContext {
|
||||
async getNumericalRoutingEnabled(): Promise<boolean> {
|
||||
await this.ensureExperimentsLoaded();
|
||||
|
||||
return !!this.experiments?.flags[ExperimentFlags.ENABLE_NUMERICAL_ROUTING]
|
||||
?.boolValue;
|
||||
const flag =
|
||||
this.experiments?.flags[ExperimentFlags.ENABLE_NUMERICAL_ROUTING];
|
||||
return flag?.boolValue ?? true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resolved complexity threshold for routing.
|
||||
* If a remote threshold is provided and within range (0-100), it is returned.
|
||||
* Otherwise, the default threshold (90) is returned.
|
||||
*/
|
||||
async getResolvedClassifierThreshold(): Promise<number> {
|
||||
const remoteValue = await this.getClassifierThreshold();
|
||||
const defaultValue = 90;
|
||||
|
||||
if (
|
||||
remoteValue !== undefined &&
|
||||
!isNaN(remoteValue) &&
|
||||
remoteValue >= 0 &&
|
||||
remoteValue <= 100
|
||||
) {
|
||||
return remoteValue;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
async getClassifierThreshold(): Promise<number | undefined> {
|
||||
|
||||
Reference in New Issue
Block a user