Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/core/src/code_assist/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async function initOauthClient(

await triggerPostAuthCallbacks(client.credentials);
} else {
const userConsent = await getConsentForOauth('Code Assist login required.');
const userConsent = await getConsentForOauth('');
if (!userConsent) {
throw new FatalCancellationError('Authentication cancelled by user.');
}
Expand All @@ -281,8 +281,7 @@ async function initOauthClient(
coreEvents.emit(CoreEvent.UserFeedback, {
severity: 'info',
message:
`\n\nCode Assist login required.\n` +
`Attempting to open authentication page in your browser.\n` +
`\n\nAttempting to open authentication page in your browser.\n` +
`Otherwise navigate to:\n\n${webLogin.authUrl}\n\n\n`,
});
try {
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/utils/authConsent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
const mockEmitConsentRequest = vi.spyOn(coreEvents, 'emitConsentRequest');
vi.spyOn(coreEvents, 'listenerCount').mockReturnValue(1);
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/utils/authConsent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { isHeadlessMode } from './headless.js';
* 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. ';
const finalPrompt =
(prompt ? prompt + ' ' : '') +
'Opening authentication page in your browser. ';

if (isHeadlessMode()) {
return getOauthConsentNonInteractive(finalPrompt);
Expand Down
Loading