fix(core): route personal OAuth users to stable models and fix test regressions

This PR resolves multiple issues:
1.  **Auth-Aware Model Routing**: Implements routing to stable models for users using personal OAuth (`oauth-personal`) to prevent 404/400 errors for unavailable preview models.
2.  **Config Class Stability**: Fixes a crash in `Config.getAuthType` by adding optional chaining for `contentGeneratorConfig`, which could be uninitialized in some test scenarios.
3.  **Test Environment Isolation**: Fixes widespread test failures in both `core` and `cli` packages by stubbing `GEMINI_CLI_HOME` in global test setups. This prevents CI-specific environment variables from interfering with home directory resolution in tests.
4.  **Lint Fix**: Resolves a lint error in `models_auth.test.ts` caused by using the spread operator on a class-cast object.

Fixes: #26857

cc @NTaylorMullen
This commit is contained in:
gemini-cli[bot]
2026-05-15 23:09:23 +00:00
parent f146618b6b
commit f534f3f17a
4 changed files with 13 additions and 5 deletions
+3
View File
@@ -56,6 +56,9 @@ let errorSpy: vi.SpyInstance;
let debugSpy: vi.SpyInstance;
beforeEach(() => {
// Ensure a clean home directory state for all tests
vi.stubEnv('GEMINI_CLI_HOME', '');
// Reset themeManager state to ensure test isolation
themeManager.resetForTesting();
+1 -1
View File
@@ -2802,7 +2802,7 @@ export class Config implements McpContext, AgentLoopContext {
}
getAuthType(): string | undefined {
return this.contentGeneratorConfig.authType;
return this.contentGeneratorConfig?.authType;
}
getPendingIncludeDirectories(): string[] {
+3 -3
View File
@@ -10,17 +10,17 @@ import {
PREVIEW_GEMINI_MODEL_AUTO,
PREVIEW_GEMINI_MODEL,
DEFAULT_GEMINI_MODEL,
type ModelCapabilityContext,
} from './models.js';
import { ModelConfigService } from '../services/modelConfigService.js';
import { DEFAULT_MODEL_CONFIGS } from './defaultModelConfigs.js';
import type { Config } from './config.js';
const modelConfigService = new ModelConfigService(DEFAULT_MODEL_CONFIGS);
const dynamicConfig = {
getExperimentalDynamicModelConfiguration: () => true,
modelConfigService,
} as unknown as Config;
} as unknown as ModelCapabilityContext;
describe('resolveModel with authType', () => {
it('should resolve auto-gemini-3 to gemini-3-pro-preview for non-personal auth', () => {
@@ -55,7 +55,7 @@ describe('resolveModel with authType', () => {
const configWithAuth = {
...dynamicConfig,
getAuthType: () => 'oauth-personal',
} as unknown as Config;
} as unknown as ModelCapabilityContext;
const model = resolveModel(
PREVIEW_GEMINI_MODEL_AUTO,
+6 -1
View File
@@ -10,7 +10,7 @@ if (process.env.NO_COLOR !== undefined) {
}
import { setSimulate429 } from './src/utils/testUtils.js';
import { vi, afterEach } from 'vitest';
import { vi, afterEach, beforeEach } from 'vitest';
import { coreEvents } from './src/utils/events.js';
// Increase max listeners to avoid warnings in large test suites
@@ -19,6 +19,11 @@ coreEvents.setMaxListeners(100);
// Disable 429 simulation globally for all tests
setSimulate429(false);
beforeEach(() => {
// Ensure a clean home directory state for all tests
vi.stubEnv('GEMINI_CLI_HOME', '');
});
afterEach(() => {
vi.unstubAllEnvs();
});