From 0178e1ef001debab78012c3db23b21edeb4e9e62 Mon Sep 17 00:00:00 2001 From: Srinath Padmanabhan Date: Thu, 5 Mar 2026 17:37:48 -0800 Subject: [PATCH] add test for non-GCP Auth types --- packages/core/src/code_assist/oauth2.test.ts | 36 ++++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/packages/core/src/code_assist/oauth2.test.ts b/packages/core/src/code_assist/oauth2.test.ts index 134244c294..16cc36fed7 100644 --- a/packages/core/src/code_assist/oauth2.test.ts +++ b/packages/core/src/code_assist/oauth2.test.ts @@ -1419,20 +1419,28 @@ describe('oauth2', () => { expect(recordGoogleAuthEnd).toHaveBeenCalledWith(mockConfig); }); - it('should NOT record onboarding events for other auth types', async () => { - // Mock getOauthClient behavior for other auth types if needed, - // or just rely on the fact that existing tests cover them. - // But here we want to explicitly verify the absence of calls. - // For simplicity, let's reuse the cached creds scenario but with a different AuthType if possible, - // or mock the flow to succeed without LOGIN_WITH_GOOGLE. - // However, getOauthClient logic is specific to AuthType. - // Let's test with AuthType.USE_GEMINI which might have a different flow. - // Actually, initOauthClient is what we modified. - // Let's just verify that standard calls don't trigger it if we can. - // Since we modified initOauthClient, we can check that function directly if exposed, - // but it is not. - // Let's just stick to the positive case for now as negative cases would require - // setting up different valid auth flows which might be complex. + it('should NOT record google auth events for non-LOGIN_WITH_GOOGLE auth types', async () => { + const mockOAuth2Client = { + setCredentials: vi.fn(), + getAccessToken: vi.fn().mockResolvedValue({ token: 'mock-token' }), + getTokenInfo: vi.fn().mockResolvedValue({}), + on: vi.fn(), + } as unknown as OAuth2Client; + vi.mocked(OAuth2Client).mockImplementation(() => mockOAuth2Client); + + const cachedCreds = { refresh_token: 'test-token' }; + const credsPath = path.join( + tempHomeDir, + GEMINI_DIR, + 'oauth_creds.json', + ); + await fs.promises.mkdir(path.dirname(credsPath), { recursive: true }); + await fs.promises.writeFile(credsPath, JSON.stringify(cachedCreds)); + + await getOauthClient(AuthType.COMPUTE_ADC, mockConfig); + + expect(recordGoogleAuthStart).not.toHaveBeenCalled(); + expect(recordGoogleAuthEnd).not.toHaveBeenCalled(); }); });