diff --git a/packages/cli/src/config/auth.test.ts b/packages/cli/src/config/auth.test.ts index 2360cf60e76..8daf5184efd 100644 --- a/packages/cli/src/config/auth.test.ts +++ b/packages/cli/src/config/auth.test.ts @@ -30,6 +30,7 @@ describe('validateAuthMethod', () => { vi.stubEnv('GOOGLE_CLOUD_PROJECT', undefined); vi.stubEnv('GOOGLE_CLOUD_LOCATION', undefined); vi.stubEnv('GOOGLE_API_KEY', undefined); + vi.stubEnv('GOOGLE_GEMINI_BASE_URL', ''); }); afterEach(() => { @@ -92,6 +93,22 @@ describe('validateAuthMethod', () => { '• GOOGLE_API_KEY environment variable (if using express mode).\n' + 'Update your environment and try again (no reload needed if using .env)!', }, + { + description: + 'should return null for GATEWAY if GOOGLE_GEMINI_BASE_URL is set', + authType: AuthType.GATEWAY, + envs: { + GOOGLE_GEMINI_BASE_URL: 'http://127.0.0.1:8080', + }, + expected: null, + }, + { + description: + 'should return an error message for GATEWAY if GOOGLE_GEMINI_BASE_URL is not set', + authType: AuthType.GATEWAY, + envs: {}, + expected: 'When using Gateway auth, GOOGLE_GEMINI_BASE_URL must be set.', + }, { description: 'should return an error message for an invalid auth method', // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/packages/cli/src/config/auth.ts b/packages/cli/src/config/auth.ts index 1ca07f98eb4..6fd7d5b0d2a 100644 --- a/packages/cli/src/config/auth.ts +++ b/packages/cli/src/config/auth.ts @@ -45,5 +45,13 @@ export async function validateAuthMethod( return null; } + if (authMethod === AuthType.GATEWAY) { + if (!process.env['GOOGLE_GEMINI_BASE_URL']) { + return 'When using Gateway auth, GOOGLE_GEMINI_BASE_URL must be set.'; + } + + return null; + } + return 'Invalid auth method selected.'; }