mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-17 01:21:10 -07:00
chore: Extract '.gemini' to GEMINI_DIR constant (#10540)
Co-authored-by: Richie Foreman <richie.foreman@gmail.com>
This commit is contained in:
committed by
GitHub
parent
7beaa368a9
commit
518caae62e
@@ -11,8 +11,8 @@ import type { OAuthCredentials } from '../mcp/token-storage/types.js';
|
||||
import * as path from 'node:path';
|
||||
import * as os from 'node:os';
|
||||
import { promises as fs } from 'node:fs';
|
||||
import { GEMINI_DIR } from '../utils/paths.js';
|
||||
|
||||
const GEMINI_DIR = '.gemini';
|
||||
const KEYCHAIN_SERVICE_NAME = 'gemini-cli-oauth';
|
||||
const MAIN_ACCOUNT_KEY = 'main-account';
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import { AuthType } from '../core/contentGenerator.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import readline from 'node:readline';
|
||||
import { FORCE_ENCRYPTED_FILE_ENV_VAR } from '../mcp/token-storage/index.js';
|
||||
import { GEMINI_DIR } from '../utils/paths.js';
|
||||
|
||||
vi.mock('os', async (importOriginal) => {
|
||||
const os = await importOriginal<typeof import('os')>();
|
||||
@@ -182,7 +183,7 @@ describe('oauth2', () => {
|
||||
// Verify Google Account was cached
|
||||
const googleAccountPath = path.join(
|
||||
tempHomeDir,
|
||||
'.gemini',
|
||||
GEMINI_DIR,
|
||||
'google_accounts.json',
|
||||
);
|
||||
expect(fs.existsSync(googleAccountPath)).toBe(true);
|
||||
@@ -290,7 +291,11 @@ describe('oauth2', () => {
|
||||
|
||||
it('should attempt to load cached credentials first', async () => {
|
||||
const cachedCreds = { refresh_token: 'cached-token' };
|
||||
const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
|
||||
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));
|
||||
|
||||
@@ -328,7 +333,11 @@ describe('oauth2', () => {
|
||||
|
||||
await getOauthClient(AuthType.CLOUD_SHELL, mockConfig);
|
||||
|
||||
const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
|
||||
const credsPath = path.join(
|
||||
tempHomeDir,
|
||||
GEMINI_DIR,
|
||||
'oauth_creds.json',
|
||||
);
|
||||
expect(fs.existsSync(credsPath)).toBe(false);
|
||||
});
|
||||
|
||||
@@ -355,7 +364,7 @@ describe('oauth2', () => {
|
||||
const defaultCreds = { refresh_token: 'default-cached-token' };
|
||||
const defaultCredsPath = path.join(
|
||||
tempHomeDir,
|
||||
'.gemini',
|
||||
GEMINI_DIR,
|
||||
'oauth_creds.json',
|
||||
);
|
||||
await fs.promises.mkdir(path.dirname(defaultCredsPath), {
|
||||
@@ -463,7 +472,7 @@ describe('oauth2', () => {
|
||||
// Verify Google Account was cached
|
||||
const googleAccountPath = path.join(
|
||||
tempHomeDir,
|
||||
'.gemini',
|
||||
GEMINI_DIR,
|
||||
'google_accounts.json',
|
||||
);
|
||||
const cachedContent = fs.readFileSync(googleAccountPath, 'utf-8');
|
||||
@@ -493,7 +502,11 @@ describe('oauth2', () => {
|
||||
|
||||
// Make it fall through to cached credentials path
|
||||
const cachedCreds = { refresh_token: 'cached-token' };
|
||||
const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
|
||||
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));
|
||||
|
||||
@@ -524,7 +537,11 @@ describe('oauth2', () => {
|
||||
|
||||
// Make it fall through to cached credentials path
|
||||
const cachedCreds = { refresh_token: 'cached-token' };
|
||||
const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
|
||||
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));
|
||||
|
||||
@@ -916,13 +933,17 @@ describe('oauth2', () => {
|
||||
describe('clearCachedCredentialFile', () => {
|
||||
it('should clear cached credentials and Google account', async () => {
|
||||
const cachedCreds = { refresh_token: 'test-token' };
|
||||
const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
|
||||
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));
|
||||
|
||||
const googleAccountPath = path.join(
|
||||
tempHomeDir,
|
||||
'.gemini',
|
||||
GEMINI_DIR,
|
||||
'google_accounts.json',
|
||||
);
|
||||
const accountData = { active: 'test@example.com', old: [] };
|
||||
@@ -965,7 +986,11 @@ describe('oauth2', () => {
|
||||
);
|
||||
|
||||
// Pre-populate credentials to make getOauthClient resolve quickly
|
||||
const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
|
||||
const credsPath = path.join(
|
||||
tempHomeDir,
|
||||
GEMINI_DIR,
|
||||
'oauth_creds.json',
|
||||
);
|
||||
await fs.promises.mkdir(path.dirname(credsPath), { recursive: true });
|
||||
await fs.promises.writeFile(
|
||||
credsPath,
|
||||
@@ -1104,7 +1129,7 @@ describe('oauth2', () => {
|
||||
expect(
|
||||
OAuthCredentialStorage.saveCredentials as Mock,
|
||||
).toHaveBeenCalledWith(mockTokens);
|
||||
const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
|
||||
const credsPath = path.join(tempHomeDir, GEMINI_DIR, 'oauth_creds.json');
|
||||
expect(fs.existsSync(credsPath)).toBe(false);
|
||||
});
|
||||
|
||||
@@ -1120,7 +1145,7 @@ describe('oauth2', () => {
|
||||
// Create a dummy unencrypted credential file.
|
||||
// If the logic is correct, this file should be ignored.
|
||||
const unencryptedCreds = { refresh_token: 'unencrypted-token' };
|
||||
const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
|
||||
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(unencryptedCreds));
|
||||
|
||||
@@ -1150,7 +1175,7 @@ describe('oauth2', () => {
|
||||
);
|
||||
|
||||
// Create a dummy unencrypted credential file. It should not be deleted.
|
||||
const credsPath = path.join(tempHomeDir, '.gemini', 'oauth_creds.json');
|
||||
const credsPath = path.join(tempHomeDir, GEMINI_DIR, 'oauth_creds.json');
|
||||
await fs.promises.mkdir(path.dirname(credsPath), { recursive: true });
|
||||
await fs.promises.writeFile(credsPath, '{}');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user