diff --git a/packages/cli/test-setup.ts b/packages/cli/test-setup.ts index e64e553ede..b7a6a1863e 100644 --- a/packages/cli/test-setup.ts +++ b/packages/cli/test-setup.ts @@ -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(); diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index bae1fe483e..d5105b2fd5 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -2802,7 +2802,7 @@ export class Config implements McpContext, AgentLoopContext { } getAuthType(): string | undefined { - return this.contentGeneratorConfig.authType; + return this.contentGeneratorConfig?.authType; } getPendingIncludeDirectories(): string[] { diff --git a/packages/core/src/config/models_auth.test.ts b/packages/core/src/config/models_auth.test.ts index 68e01c839e..0363750cc4 100644 --- a/packages/core/src/config/models_auth.test.ts +++ b/packages/core/src/config/models_auth.test.ts @@ -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, diff --git a/packages/core/test-setup.ts b/packages/core/test-setup.ts index d730369578..cd8b67ffd9 100644 --- a/packages/core/test-setup.ts +++ b/packages/core/test-setup.ts @@ -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(); });