fix(core): restore auth consent in headless mode and add unit tests (#19689)

This commit is contained in:
Emily Hedlund
2026-02-20 15:31:43 -05:00
committed by GitHub
parent 27ff19fc2c
commit 2cd726a7c2
4 changed files with 133 additions and 64 deletions
+9 -10
View File
@@ -12,22 +12,21 @@ import { isHeadlessMode } from './headless.js';
/**
* Requests consent from the user for OAuth login.
* Handles both TTY and non-TTY environments.
* Handles both interactive and non-interactive (headless) modes.
*/
export async function getConsentForOauth(prompt: string): Promise<boolean> {
const finalPrompt = prompt + ' Opening authentication page in your browser. ';
if (coreEvents.listenerCount(CoreEvent.ConsentRequest) === 0) {
if (isHeadlessMode()) {
throw new FatalAuthenticationError(
'Interactive consent could not be obtained.\n' +
'Please run Gemini CLI in an interactive terminal to authenticate, or use NO_BROWSER=true for manual authentication.',
);
}
if (isHeadlessMode()) {
return getOauthConsentNonInteractive(finalPrompt);
} else if (coreEvents.listenerCount(CoreEvent.ConsentRequest) > 0) {
return getOauthConsentInteractive(finalPrompt);
}
return getOauthConsentInteractive(finalPrompt);
throw new FatalAuthenticationError(
'Authentication consent could not be obtained.\n' +
'Please run Gemini CLI in an interactive terminal to authenticate, ' +
'or use NO_BROWSER=true for manual authentication.',
);
}
async function getOauthConsentNonInteractive(prompt: string) {