From aa5eefa19337427ef3cb5888acd41dd7170551de Mon Sep 17 00:00:00 2001 From: mkorwel Date: Fri, 20 Feb 2026 19:04:24 +0000 Subject: [PATCH] refactor(config): revert experiment getter names and async signatures --- packages/cli/src/test-utils/mockConfig.ts | 2 +- .../src/config/config.cli_override.test.ts | 8 +++---- packages/core/src/config/config.ts | 22 +++++++++---------- .../src/routing/modelRouterService.test.ts | 15 ++++++++----- .../core/src/routing/modelRouterService.ts | 6 +++-- .../strategies/classifierStrategy.test.ts | 6 ++--- .../routing/strategies/classifierStrategy.ts | 5 ++++- .../numericalClassifierStrategy.test.ts | 17 ++++++++++---- .../strategies/numericalClassifierStrategy.ts | 6 ++--- 9 files changed, 52 insertions(+), 35 deletions(-) diff --git a/packages/cli/src/test-utils/mockConfig.ts b/packages/cli/src/test-utils/mockConfig.ts index f65475bd04..f3a6e6e673 100644 --- a/packages/cli/src/test-utils/mockConfig.ts +++ b/packages/cli/src/test-utils/mockConfig.ts @@ -120,7 +120,7 @@ export const createMockConfig = (overrides: Partial = {}): Config => isTrustedFolder: vi.fn().mockReturnValue(true), getCompressionThreshold: vi.fn().mockResolvedValue(undefined), getUserCaching: vi.fn().mockResolvedValue(false), - isNumericalRoutingEnabled: vi.fn().mockReturnValue(false), + getNumericalRoutingEnabled: vi.fn().mockResolvedValue(false), isAwesomeEnabled: vi.fn().mockReturnValue(false), getClassifierThreshold: vi.fn().mockResolvedValue(undefined), getBannerTextNoCapacityIssues: vi.fn().mockResolvedValue(''), diff --git a/packages/core/src/config/config.cli_override.test.ts b/packages/core/src/config/config.cli_override.test.ts index 04524b1d62..6b7061c036 100644 --- a/packages/core/src/config/config.cli_override.test.ts +++ b/packages/core/src/config/config.cli_override.test.ts @@ -14,7 +14,7 @@ describe('Config CLI Override', () => { const cwd = process.cwd(); const model = 'gemini-pro'; - it('should prioritize CLI argument over local setting', () => { + it('should prioritize CLI argument over local setting', async () => { const config = new Config({ sessionId, targetDir, @@ -25,10 +25,10 @@ describe('Config CLI Override', () => { experimentalSettings: { 'enable-numerical-routing': false }, }); - expect(config.isNumericalRoutingEnabled()).toBe(true); + expect(await config.getNumericalRoutingEnabled()).toBe(true); }); - it('should prioritize CLI argument over remote experiment', () => { + it('should prioritize CLI argument over remote experiment', async () => { const config = new Config({ sessionId, targetDir, @@ -44,6 +44,6 @@ describe('Config CLI Override', () => { }, }); - expect(config.isNumericalRoutingEnabled()).toBe(true); + expect(await config.getNumericalRoutingEnabled()).toBe(true); }); }); diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 4908f9753f..753efc0172 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -3020,15 +3020,15 @@ export class Config implements McpContext, AgentLoopContext { return remoteThreshold; } - getUserCaching(): boolean | undefined { + async getUserCaching(): Promise { return this.getExperimentValue(ExperimentFlags.USER_CACHING); } - getPlanModeRoutingEnabled(): boolean { + async getPlanModeRoutingEnabled(): Promise { return this.planModeRoutingEnabled; } - isNumericalRoutingEnabled(): boolean { + async getNumericalRoutingEnabled(): Promise { return ( this.getExperimentValue( ExperimentFlags.ENABLE_NUMERICAL_ROUTING, @@ -3041,8 +3041,8 @@ export class Config implements McpContext, AgentLoopContext { * If a remote threshold is provided and within range (0-100), it is returned. * Otherwise, the default threshold (90) is returned. */ - getResolvedClassifierThreshold(): number { - const remoteValue = this.getClassifierThreshold(); + async getResolvedClassifierThreshold(): Promise { + const remoteValue = await this.getClassifierThreshold(); const defaultValue = 90; if ( @@ -3057,13 +3057,13 @@ export class Config implements McpContext, AgentLoopContext { return defaultValue; } - getClassifierThreshold(): number | undefined { + async getClassifierThreshold(): Promise { return this.getExperimentValue( ExperimentFlags.CLASSIFIER_THRESHOLD, ); } - getBannerTextNoCapacityIssues(): string { + async getBannerTextNoCapacityIssues(): Promise { return ( this.getExperimentValue( ExperimentFlags.BANNER_TEXT_NO_CAPACITY_ISSUES, @@ -3071,7 +3071,7 @@ export class Config implements McpContext, AgentLoopContext { ); } - getBannerTextCapacityIssues(): string { + async getBannerTextCapacityIssues(): Promise { return ( this.getExperimentValue( ExperimentFlags.BANNER_TEXT_CAPACITY_ISSUES, @@ -3079,7 +3079,6 @@ export class Config implements McpContext, AgentLoopContext { ); } -<<<<<<< HEAD /** * Returns whether the user has access to Pro models. * This is determined by the PRO_MODEL_NO_ACCESS experiment flag. @@ -3198,11 +3197,12 @@ export class Config implements McpContext, AgentLoopContext { return ( this.experiments?.flags[ExperimentFlags.GEMINI_3_1_FLASH_LITE_LAUNCHED] ?.boolValue ?? false -======= + ); + } + isAwesomeEnabled(): boolean { return ( this.getExperimentValue(ExperimentFlags.ENABLE_AWESOME) ?? false ->>>>>>> d2ce1460f (feat(config): add enable-awesome experiment to show custom ASCII art) ); } diff --git a/packages/core/src/routing/modelRouterService.test.ts b/packages/core/src/routing/modelRouterService.test.ts index 348637c36a..4e0c32c62f 100644 --- a/packages/core/src/routing/modelRouterService.test.ts +++ b/packages/core/src/routing/modelRouterService.test.ts @@ -51,12 +51,15 @@ describe('ModelRouterService', () => { mockBaseLlmClient = {} as BaseLlmClient; mockLocalLiteRtLmClient = {} as LocalLiteRtLmClient; vi.spyOn(mockConfig, 'getBaseLlmClient').mockReturnValue(mockBaseLlmClient); -vi.spyOn(mockConfig, 'getLocalLiteRtLmClient').mockReturnValue( - mockLocalLiteRtLmClient, -); -vi.spyOn(mockConfig, 'isNumericalRoutingEnabled').mockReturnValue(true); -vi.spyOn(mockConfig, 'getResolvedClassifierThreshold').mockReturnValue(90); -vi.spyOn(mockConfig, 'getClassifierThreshold').mockReturnValue(undefined); vi.spyOn(mockConfig, 'getGemmaModelRouterSettings').mockReturnValue({ + vi.spyOn(mockConfig, 'getLocalLiteRtLmClient').mockReturnValue( + mockLocalLiteRtLmClient, + ); + vi.spyOn(mockConfig, 'getNumericalRoutingEnabled').mockResolvedValue(true); + vi.spyOn(mockConfig, 'getResolvedClassifierThreshold').mockResolvedValue( + 90, + ); + vi.spyOn(mockConfig, 'getClassifierThreshold').mockResolvedValue(undefined); + vi.spyOn(mockConfig, 'getGemmaModelRouterSettings').mockReturnValue({ enabled: false, classifier: { host: 'http://localhost:1234', diff --git a/packages/core/src/routing/modelRouterService.ts b/packages/core/src/routing/modelRouterService.ts index 34553fcc1f..a62deacd31 100644 --- a/packages/core/src/routing/modelRouterService.ts +++ b/packages/core/src/routing/modelRouterService.ts @@ -76,8 +76,10 @@ export class ModelRouterService { const startTime = Date.now(); let decision: RoutingDecision; - const enableNumericalRouting = this.config.isNumericalRoutingEnabled(); - const thresholdValue = this.config.getResolvedClassifierThreshold(); + const [enableNumericalRouting, thresholdValue] = await Promise.all([ + this.config.getNumericalRoutingEnabled(), + this.config.getResolvedClassifierThreshold(), + ]); const classifierThreshold = String(thresholdValue); let failed = false; diff --git a/packages/core/src/routing/strategies/classifierStrategy.test.ts b/packages/core/src/routing/strategies/classifierStrategy.test.ts index 506be0e795..373da6f144 100644 --- a/packages/core/src/routing/strategies/classifierStrategy.test.ts +++ b/packages/core/src/routing/strategies/classifierStrategy.test.ts @@ -57,7 +57,7 @@ describe('ClassifierStrategy', () => { getResolvedConfig: vi.fn().mockReturnValue(mockResolvedConfig), }, getModel: vi.fn().mockReturnValue(DEFAULT_GEMINI_MODEL_AUTO), - isNumericalRoutingEnabled: vi.fn().mockReturnValue(false), + getNumericalRoutingEnabled: vi.fn().mockResolvedValue(false), getGemini31Launched: vi.fn().mockResolvedValue(false), getGemini31FlashLiteLaunched: vi.fn().mockResolvedValue(false), getUseCustomToolModel: vi.fn().mockImplementation(async () => { @@ -78,7 +78,7 @@ describe('ClassifierStrategy', () => { }); it('should return null if numerical routing is enabled and model is Gemini 3', async () => { - vi.mocked(mockConfig.isNumericalRoutingEnabled).mockReturnValue(true); + vi.mocked(mockConfig.getNumericalRoutingEnabled).mockResolvedValue(true); vi.mocked(mockConfig.getModel).mockReturnValue(PREVIEW_GEMINI_MODEL_AUTO); const decision = await strategy.route( @@ -93,7 +93,7 @@ describe('ClassifierStrategy', () => { }); it('should NOT return null if numerical routing is enabled but model is NOT Gemini 3', async () => { - vi.mocked(mockConfig.isNumericalRoutingEnabled).mockReturnValue(true); + vi.mocked(mockConfig.getNumericalRoutingEnabled).mockResolvedValue(true); vi.mocked(mockConfig.getModel).mockReturnValue(DEFAULT_GEMINI_MODEL_AUTO); vi.mocked(mockBaseLlmClient.generateJson).mockResolvedValue({ reasoning: 'test', diff --git a/packages/core/src/routing/strategies/classifierStrategy.ts b/packages/core/src/routing/strategies/classifierStrategy.ts index 1fa4c29ca1..1dd09f4596 100644 --- a/packages/core/src/routing/strategies/classifierStrategy.ts +++ b/packages/core/src/routing/strategies/classifierStrategy.ts @@ -137,7 +137,10 @@ export class ClassifierStrategy implements RoutingStrategy { const startTime = Date.now(); try { const model = context.requestedModel ?? config.getModel(); - if (config.isNumericalRoutingEnabled() && isGemini3Model(model, config)) { + if ( + (await config.getNumericalRoutingEnabled()) && + isGemini3Model(model, config) + ) { return null; } diff --git a/packages/core/src/routing/strategies/numericalClassifierStrategy.test.ts b/packages/core/src/routing/strategies/numericalClassifierStrategy.test.ts index 7db2aa7c90..3e0b94ff27 100644 --- a/packages/core/src/routing/strategies/numericalClassifierStrategy.test.ts +++ b/packages/core/src/routing/strategies/numericalClassifierStrategy.test.ts @@ -55,9 +55,9 @@ describe('NumericalClassifierStrategy', () => { }, getModel: vi.fn().mockReturnValue(PREVIEW_GEMINI_MODEL_AUTO), getSessionId: vi.fn().mockReturnValue('control-group-id'), // Default to Control Group (Hash 71 >= 50) - isNumericalRoutingEnabled: vi.fn().mockReturnValue(true), - getResolvedClassifierThreshold: vi.fn().mockReturnValue(90), - getClassifierThreshold: vi.fn().mockReturnValue(undefined), + getNumericalRoutingEnabled: vi.fn().mockResolvedValue(true), + getResolvedClassifierThreshold: vi.fn().mockResolvedValue(90), + getClassifierThreshold: vi.fn().mockResolvedValue(undefined), getGemini31Launched: vi.fn().mockResolvedValue(false), getGemini31FlashLiteLaunched: vi.fn().mockResolvedValue(false), getUseCustomToolModel: vi.fn().mockImplementation(async () => { @@ -82,7 +82,7 @@ describe('NumericalClassifierStrategy', () => { }); it('should return null if numerical routing is disabled', async () => { - vi.mocked(mockConfig.isNumericalRoutingEnabled).mockReturnValue(false); + vi.mocked(mockConfig.getNumericalRoutingEnabled).mockResolvedValue(false); const decision = await strategy.route( mockContext, @@ -211,9 +211,12 @@ describe('NumericalClassifierStrategy', () => { describe('Remote Threshold Logic', () => { it('should use the remote CLASSIFIER_THRESHOLD if provided (int value)', async () => { vi.mocked(mockConfig.getClassifierThreshold).mockResolvedValue(70); +<<<<<<< HEAD vi.mocked(mockConfig.getResolvedClassifierThreshold).mockResolvedValue( 70, ); +======= +>>>>>>> b9035a18d (refactor(config): revert experiment getter names and async signatures) const mockApiResponse = { complexity_reasoning: 'Test task', complexity_score: 60, @@ -241,9 +244,12 @@ describe('NumericalClassifierStrategy', () => { it('should use the remote CLASSIFIER_THRESHOLD if provided (float value)', async () => { vi.mocked(mockConfig.getClassifierThreshold).mockResolvedValue(45.5); +<<<<<<< HEAD vi.mocked(mockConfig.getResolvedClassifierThreshold).mockResolvedValue( 45.5, ); +======= +>>>>>>> b9035a18d (refactor(config): revert experiment getter names and async signatures) const mockApiResponse = { complexity_reasoning: 'Test task', complexity_score: 40, @@ -271,9 +277,12 @@ describe('NumericalClassifierStrategy', () => { it('should use PRO model if score >= remote CLASSIFIER_THRESHOLD', async () => { vi.mocked(mockConfig.getClassifierThreshold).mockResolvedValue(30); +<<<<<<< HEAD vi.mocked(mockConfig.getResolvedClassifierThreshold).mockResolvedValue( 30, ); +======= +>>>>>>> b9035a18d (refactor(config): revert experiment getter names and async signatures) const mockApiResponse = { complexity_reasoning: 'Test task', complexity_score: 35, diff --git a/packages/core/src/routing/strategies/numericalClassifierStrategy.ts b/packages/core/src/routing/strategies/numericalClassifierStrategy.ts index e3cb2eefbc..8bcfb3da67 100644 --- a/packages/core/src/routing/strategies/numericalClassifierStrategy.ts +++ b/packages/core/src/routing/strategies/numericalClassifierStrategy.ts @@ -105,7 +105,7 @@ export class NumericalClassifierStrategy implements RoutingStrategy { const startTime = Date.now(); try { const model = context.requestedModel ?? config.getModel(); - if (!config.isNumericalRoutingEnabled()) { + if (!(await config.getNumericalRoutingEnabled())) { return null; } @@ -187,8 +187,8 @@ export class NumericalClassifierStrategy implements RoutingStrategy { groupLabel: string; modelAlias: typeof FLASH_MODEL | typeof PRO_MODEL; }> { - const threshold = config.getResolvedClassifierThreshold(); - const remoteThresholdValue = config.getClassifierThreshold(); + const threshold = await config.getResolvedClassifierThreshold(); + const remoteThresholdValue = await config.getClassifierThreshold(); let groupLabel: string; if (threshold === remoteThresholdValue) {