Refactor the logic for deciding whether to launch a browser into config (#4622)

This commit is contained in:
Marat Boshernitsan 2025-07-21 16:23:28 -07:00 committed by GitHub
parent 97cf26ec53
commit 5066bc5384
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 6 deletions

View File

@ -37,7 +37,6 @@ import {
logUserPrompt, logUserPrompt,
AuthType, AuthType,
getOauthClient, getOauthClient,
shouldAttemptBrowserLaunch,
} from '@google/gemini-cli-core'; } from '@google/gemini-cli-core';
import { validateAuthMethod } from './config/auth.js'; import { validateAuthMethod } from './config/auth.js';
import { setMaxSizedBoxDebugging } from './ui/components/shared/MaxSizedBox.js'; import { setMaxSizedBoxDebugging } from './ui/components/shared/MaxSizedBox.js';
@ -188,7 +187,7 @@ export async function main() {
if ( if (
settings.merged.selectedAuthType === AuthType.LOGIN_WITH_GOOGLE && settings.merged.selectedAuthType === AuthType.LOGIN_WITH_GOOGLE &&
(config.getNoBrowser() || !shouldAttemptBrowserLaunch()) config.isBrowserLaunchSuppressed()
) { ) {
// Do oauth before app renders to make copying the link possible. // Do oauth before app renders to make copying the link possible.
await getOauthClient(settings.merged.selectedAuthType, config); await getOauthClient(settings.merged.selectedAuthType, config);

View File

@ -11,7 +11,6 @@ import {
Config, Config,
clearCachedCredentialFile, clearCachedCredentialFile,
getErrorMessage, getErrorMessage,
shouldAttemptBrowserLaunch,
} from '@google/gemini-cli-core'; } from '@google/gemini-cli-core';
import { runExitCleanup } from '../../utils/cleanup.js'; import { runExitCleanup } from '../../utils/cleanup.js';
@ -60,7 +59,7 @@ export const useAuthCommand = (
settings.setValue(scope, 'selectedAuthType', authType); settings.setValue(scope, 'selectedAuthType', authType);
if ( if (
authType === AuthType.LOGIN_WITH_GOOGLE && authType === AuthType.LOGIN_WITH_GOOGLE &&
(config.getNoBrowser() || !shouldAttemptBrowserLaunch()) config.isBrowserLaunchSuppressed()
) { ) {
runExitCleanup(); runExitCleanup();
console.log( console.log(

View File

@ -38,6 +38,7 @@ vi.mock('../utils/browser.js', () => ({
const mockConfig = { const mockConfig = {
getNoBrowser: () => false, getNoBrowser: () => false,
getProxy: () => 'http://test.proxy.com:8080', getProxy: () => 'http://test.proxy.com:8080',
isBrowserLaunchSuppressed: () => false,
} as unknown as Config; } as unknown as Config;
// Mock fetch globally // Mock fetch globally
@ -180,6 +181,7 @@ describe('oauth2', () => {
const mockConfigWithNoBrowser = { const mockConfigWithNoBrowser = {
getNoBrowser: () => true, getNoBrowser: () => true,
getProxy: () => 'http://test.proxy.com:8080', getProxy: () => 'http://test.proxy.com:8080',
isBrowserLaunchSuppressed: () => true,
} as unknown as Config; } as unknown as Config;
const mockCodeVerifier = { const mockCodeVerifier = {

View File

@ -26,7 +26,6 @@ import {
clearCachedGoogleAccount, clearCachedGoogleAccount,
} from '../utils/user_account.js'; } from '../utils/user_account.js';
import { AuthType } from '../core/contentGenerator.js'; import { AuthType } from '../core/contentGenerator.js';
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
import readline from 'node:readline'; import readline from 'node:readline';
// OAuth Client ID used to initiate OAuth2Client class. // OAuth Client ID used to initiate OAuth2Client class.
@ -122,7 +121,7 @@ export async function getOauthClient(
} }
} }
if (config.getNoBrowser() || !shouldAttemptBrowserLaunch()) { if (config.isBrowserLaunchSuppressed()) {
let success = false; let success = false;
const maxRetries = 2; const maxRetries = 2;
for (let i = 0; !success && i < maxRetries; i++) { for (let i = 0; !success && i < maxRetries; i++) {

View File

@ -44,6 +44,7 @@ import {
DEFAULT_GEMINI_FLASH_MODEL, DEFAULT_GEMINI_FLASH_MODEL,
} from './models.js'; } from './models.js';
import { ClearcutLogger } from '../telemetry/clearcut-logger/clearcut-logger.js'; import { ClearcutLogger } from '../telemetry/clearcut-logger/clearcut-logger.js';
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
export enum ApprovalMode { export enum ApprovalMode {
DEFAULT = 'default', DEFAULT = 'default',
@ -542,6 +543,10 @@ export class Config {
return this.noBrowser; return this.noBrowser;
} }
isBrowserLaunchSuppressed(): boolean {
return this.getNoBrowser() || !shouldAttemptBrowserLaunch();
}
getSummarizeToolOutputConfig(): getSummarizeToolOutputConfig():
| Record<string, SummarizeToolOutputSettings> | Record<string, SummarizeToolOutputSettings>
| undefined { | undefined {