summaryrefslogtreecommitdiff
path: root/packages/core/src
diff options
context:
space:
mode:
authorTommaso Sciortino <[email protected]>2025-07-25 14:29:54 -0700
committerGitHub <[email protected]>2025-07-25 21:29:54 +0000
commit65aabfede8b7f842fa37abf1ac36afe4b4881e50 (patch)
tree3c92d191a95eaba206940e669bae9c3965e562db /packages/core/src
parenteb65034117f7722554a717de034e891ba1996e93 (diff)
Make oauth2 test windows compatible. (#4895)
Diffstat (limited to 'packages/core/src')
-rw-r--r--packages/core/src/code_assist/oauth2.test.ts53
1 files changed, 16 insertions, 37 deletions
diff --git a/packages/core/src/code_assist/oauth2.test.ts b/packages/core/src/code_assist/oauth2.test.ts
index 0dc77867..32c8ad3c 100644
--- a/packages/core/src/code_assist/oauth2.test.ts
+++ b/packages/core/src/code_assist/oauth2.test.ts
@@ -255,13 +255,6 @@ describe('oauth2', () => {
let mockComputeClient: Compute;
beforeEach(() => {
- vi.spyOn(os, 'homedir').mockReturnValue('/user/home');
- vi.spyOn(fs.promises, 'mkdir').mockResolvedValue(undefined);
- vi.spyOn(fs.promises, 'writeFile').mockResolvedValue(undefined);
- vi.spyOn(fs.promises, 'readFile').mockRejectedValue(
- new Error('File not found'),
- ); // Default to no cached creds
-
mockGetAccessToken.mockResolvedValue({ token: 'test-access-token' });
mockComputeClient = {
credentials: { refresh_token: 'test-refresh-token' },
@@ -273,9 +266,9 @@ describe('oauth2', () => {
it('should attempt to load cached credentials first', async () => {
const cachedCreds = { refresh_token: 'cached-token' };
- vi.spyOn(fs.promises, 'readFile').mockResolvedValue(
- JSON.stringify(cachedCreds),
- );
+ const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
+ await fs.promises.mkdir(path.dirname(credsPath), { recursive: true });
+ await fs.promises.writeFile(credsPath, JSON.stringify(cachedCreds));
const mockClient = {
setCredentials: vi.fn(),
@@ -291,10 +284,6 @@ describe('oauth2', () => {
await getOauthClient(AuthType.LOGIN_WITH_GOOGLE, mockConfig);
- expect(fs.promises.readFile).toHaveBeenCalledWith(
- '/user/home/.gemini/oauth_creds.json',
- 'utf-8',
- );
expect(mockClient.setCredentials).toHaveBeenCalledWith(cachedCreds);
expect(mockClient.getAccessToken).toHaveBeenCalled();
expect(mockClient.getTokenInfo).toHaveBeenCalled();
@@ -315,7 +304,8 @@ describe('oauth2', () => {
await getOauthClient(AuthType.CLOUD_SHELL, mockConfig);
- expect(fs.promises.writeFile).not.toHaveBeenCalled();
+ const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
+ expect(fs.existsSync(credsPath)).toBe(false);
});
it('should return the Compute client on successful ADC authentication', async () => {
@@ -361,10 +351,6 @@ describe('oauth2', () => {
.mockResolvedValue({ email: '[email protected]' }),
} as unknown as Response);
- const writeFileSpy = vi
- .spyOn(fs.promises, 'writeFile')
- .mockResolvedValue(undefined);
-
const client = await getOauthClient(
AuthType.LOGIN_WITH_GOOGLE,
mockConfig,
@@ -392,18 +378,11 @@ describe('oauth2', () => {
'.gemini',
'google_accounts.json',
);
- expect(writeFileSpy).toHaveBeenCalledWith(
- googleAccountPath,
- JSON.stringify(
- {
- active: '[email protected]',
- old: [],
- },
- null,
- 2,
- ),
- 'utf-8',
- );
+ const cachedContent = fs.readFileSync(googleAccountPath, 'utf-8');
+ expect(JSON.parse(cachedContent)).toEqual({
+ active: '[email protected]',
+ old: [],
+ });
});
it('should not use GCP token if GOOGLE_CLOUD_ACCESS_TOKEN is not set', async () => {
@@ -426,9 +405,9 @@ describe('oauth2', () => {
// Make it fall through to cached credentials path
const cachedCreds = { refresh_token: 'cached-token' };
- vi.spyOn(fs.promises, 'readFile').mockResolvedValue(
- JSON.stringify(cachedCreds),
- );
+ const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
+ await fs.promises.mkdir(path.dirname(credsPath), { recursive: true });
+ await fs.promises.writeFile(credsPath, JSON.stringify(cachedCreds));
await getOauthClient(AuthType.LOGIN_WITH_GOOGLE, mockConfig);
@@ -457,9 +436,9 @@ describe('oauth2', () => {
// Make it fall through to cached credentials path
const cachedCreds = { refresh_token: 'cached-token' };
- vi.spyOn(fs.promises, 'readFile').mockResolvedValue(
- JSON.stringify(cachedCreds),
- );
+ const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
+ await fs.promises.mkdir(path.dirname(credsPath), { recursive: true });
+ await fs.promises.writeFile(credsPath, JSON.stringify(cachedCreds));
await getOauthClient(AuthType.LOGIN_WITH_GOOGLE, mockConfig);