mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 22:14:52 -07:00
feat(core): remove unnecessary login verbiage from Code Assist auth (#19861)
This commit is contained in:
@@ -271,7 +271,7 @@ async function initOauthClient(
|
|||||||
|
|
||||||
await triggerPostAuthCallbacks(client.credentials);
|
await triggerPostAuthCallbacks(client.credentials);
|
||||||
} else {
|
} else {
|
||||||
const userConsent = await getConsentForOauth('Code Assist login required.');
|
const userConsent = await getConsentForOauth('');
|
||||||
if (!userConsent) {
|
if (!userConsent) {
|
||||||
throw new FatalCancellationError('Authentication cancelled by user.');
|
throw new FatalCancellationError('Authentication cancelled by user.');
|
||||||
}
|
}
|
||||||
@@ -281,8 +281,7 @@ async function initOauthClient(
|
|||||||
coreEvents.emit(CoreEvent.UserFeedback, {
|
coreEvents.emit(CoreEvent.UserFeedback, {
|
||||||
severity: 'info',
|
severity: 'info',
|
||||||
message:
|
message:
|
||||||
`\n\nCode Assist login required.\n` +
|
`\n\nAttempting to open authentication page in your browser.\n` +
|
||||||
`Attempting to open authentication page in your browser.\n` +
|
|
||||||
`Otherwise navigate to:\n\n${webLogin.authUrl}\n\n\n`,
|
`Otherwise navigate to:\n\n${webLogin.authUrl}\n\n\n`,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -56,6 +56,25 @@ describe('getConsentForOauth', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle empty prompt correctly', async () => {
|
||||||
|
const mockEmitConsentRequest = vi.spyOn(coreEvents, 'emitConsentRequest');
|
||||||
|
vi.spyOn(coreEvents, 'listenerCount').mockReturnValue(1);
|
||||||
|
|
||||||
|
mockEmitConsentRequest.mockImplementation((payload) => {
|
||||||
|
payload.onConfirm(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
await getConsentForOauth('');
|
||||||
|
|
||||||
|
expect(mockEmitConsentRequest).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
prompt: expect.stringMatching(
|
||||||
|
/^Opening authentication page in your browser\./,
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return false when user declines via UI', async () => {
|
it('should return false when user declines via UI', async () => {
|
||||||
const mockEmitConsentRequest = vi.spyOn(coreEvents, 'emitConsentRequest');
|
const mockEmitConsentRequest = vi.spyOn(coreEvents, 'emitConsentRequest');
|
||||||
vi.spyOn(coreEvents, 'listenerCount').mockReturnValue(1);
|
vi.spyOn(coreEvents, 'listenerCount').mockReturnValue(1);
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import { isHeadlessMode } from './headless.js';
|
|||||||
* Handles both interactive and non-interactive (headless) modes.
|
* Handles both interactive and non-interactive (headless) modes.
|
||||||
*/
|
*/
|
||||||
export async function getConsentForOauth(prompt: string): Promise<boolean> {
|
export async function getConsentForOauth(prompt: string): Promise<boolean> {
|
||||||
const finalPrompt = prompt + ' Opening authentication page in your browser. ';
|
const finalPrompt =
|
||||||
|
(prompt ? prompt + ' ' : '') +
|
||||||
|
'Opening authentication page in your browser. ';
|
||||||
|
|
||||||
if (isHeadlessMode()) {
|
if (isHeadlessMode()) {
|
||||||
return getOauthConsentNonInteractive(finalPrompt);
|
return getOauthConsentNonInteractive(finalPrompt);
|
||||||
|
|||||||
Reference in New Issue
Block a user