Skip to content

Commit 794b17c

Browse files
committed
chore: Extract '.gemini' to GEMINI_DIR constant
1 parent 8cd2ec7 commit 794b17c

33 files changed

+171
-151
lines changed

integration-tests/globalSetup.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,14 @@ import {
1919
} from 'node:fs/promises';
2020
import { join, dirname } from 'node:path';
2121
import { fileURLToPath } from 'node:url';
22-
import * as os from 'node:os';
23-
24-
import {
25-
GEMINI_CONFIG_DIR,
26-
DEFAULT_CONTEXT_FILENAME,
27-
} from '../packages/core/src/tools/memoryTool.js';
22+
import { getGlobalMemoryFilePath } from '../packages/core/src/tools/memoryTool.js';
2823

2924
const __dirname = dirname(fileURLToPath(import.meta.url));
3025
const rootDir = join(__dirname, '..');
3126
const integrationTestsDir = join(rootDir, '.integration-tests');
3227
let runDir = ''; // Make runDir accessible in teardown
3328

34-
const memoryFilePath = join(
35-
os.homedir(),
36-
GEMINI_CONFIG_DIR,
37-
DEFAULT_CONTEXT_FILENAME,
38-
);
29+
const memoryFilePath = getGlobalMemoryFilePath();
3930
let originalMemoryContent: string | null = null;
4031

4132
export async function setup() {

integration-tests/test-helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import fs from 'node:fs';
1414
import * as pty from '@lydell/node-pty';
1515
import stripAnsi from 'strip-ansi';
1616
import * as os from 'node:os';
17+
import { GEMINI_DIR } from '../packages/core/src/utils/paths.js';
1718

1819
const __dirname = dirname(fileURLToPath(import.meta.url));
1920

@@ -169,7 +170,7 @@ export class TestRig {
169170
mkdirSync(this.testDir, { recursive: true });
170171

171172
// Create a settings file to point the CLI to the local collector
172-
const geminiDir = join(this.testDir, '.gemini');
173+
const geminiDir = join(this.testDir, GEMINI_DIR);
173174
mkdirSync(geminiDir, { recursive: true });
174175
// In sandbox mode, use an absolute path for telemetry inside the container
175176
// The container mounts the test directory at the same path as the host

packages/a2a-server/src/config/config.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
FileDiscoveryService,
1818
ApprovalMode,
1919
loadServerHierarchicalMemory,
20-
GEMINI_CONFIG_DIR,
20+
GEMINI_DIR,
2121
DEFAULT_GEMINI_EMBEDDING_MODEL,
2222
DEFAULT_GEMINI_MODEL,
2323
} from '@google/gemini-cli-core';
@@ -175,7 +175,7 @@ function findEnvFile(startDir: string): string | null {
175175
let currentDir = path.resolve(startDir);
176176
while (true) {
177177
// prefer gemini-specific .env under GEMINI_DIR
178-
const geminiEnvPath = path.join(currentDir, GEMINI_CONFIG_DIR, '.env');
178+
const geminiEnvPath = path.join(currentDir, GEMINI_DIR, '.env');
179179
if (fs.existsSync(geminiEnvPath)) {
180180
return geminiEnvPath;
181181
}
@@ -186,11 +186,7 @@ function findEnvFile(startDir: string): string | null {
186186
const parentDir = path.dirname(currentDir);
187187
if (parentDir === currentDir || !parentDir) {
188188
// check .env under home as fallback, again preferring gemini-specific .env
189-
const homeGeminiEnvPath = path.join(
190-
process.cwd(),
191-
GEMINI_CONFIG_DIR,
192-
'.env',
193-
);
189+
const homeGeminiEnvPath = path.join(process.cwd(), GEMINI_DIR, '.env');
194190
if (fs.existsSync(homeGeminiEnvPath)) {
195191
return homeGeminiEnvPath;
196192
}

packages/a2a-server/src/config/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
// Copied exactly from packages/cli/src/config/extension.ts, last PR #1026
88

9-
import type { MCPServerConfig } from '@google/gemini-cli-core';
9+
import { GEMINI_DIR, type MCPServerConfig } from '@google/gemini-cli-core';
1010
import * as fs from 'node:fs';
1111
import * as path from 'node:path';
1212
import * as os from 'node:os';
1313
import { logger } from '../utils/logger.js';
1414

15-
export const EXTENSIONS_DIRECTORY_NAME = path.join('.gemini', 'extensions');
15+
export const EXTENSIONS_DIRECTORY_NAME = path.join(GEMINI_DIR, 'extensions');
1616
export const EXTENSIONS_CONFIG_FILENAME = 'gemini-extension.json';
1717

1818
export interface Extension {

packages/a2a-server/src/config/settings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { homedir } from 'node:os';
1010

1111
import type { MCPServerConfig } from '@google/gemini-cli-core';
1212
import {
13+
GEMINI_DIR,
1314
getErrorMessage,
1415
type TelemetrySettings,
1516
} from '@google/gemini-cli-core';
1617
import stripJsonComments from 'strip-json-comments';
1718

18-
export const SETTINGS_DIRECTORY_NAME = '.gemini';
19-
export const USER_SETTINGS_DIR = path.join(homedir(), SETTINGS_DIRECTORY_NAME);
19+
export const USER_SETTINGS_DIR = path.join(homedir(), GEMINI_DIR);
2020
export const USER_SETTINGS_PATH = path.join(USER_SETTINGS_DIR, 'settings.json');
2121

2222
// Reconcile with https://github.com/google-gemini/gemini-cli/blob/b09bc6656080d4d12e1d06734aae2ec33af5c1ed/packages/cli/src/config/settings.ts#L53
@@ -76,7 +76,7 @@ export function loadSettings(workspaceDir: string): Settings {
7676

7777
const workspaceSettingsPath = path.join(
7878
workspaceDir,
79-
SETTINGS_DIRECTORY_NAME,
79+
GEMINI_DIR,
8080
'settings.json',
8181
);
8282

packages/cli/src/commands/mcp/list.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ vi.mock('@google/gemini-cli-core', () => ({
3232
getWorkspaceSettingsPath: () => '/tmp/gemini/workspace-settings.json',
3333
getProjectTempDir: () => '/test/home/.gemini/tmp/mocked_hash',
3434
})),
35-
GEMINI_CONFIG_DIR: '.gemini',
35+
GEMINI_DIR: '.gemini',
3636
getErrorMessage: (e: unknown) => (e instanceof Error ? e.message : String(e)),
3737
}));
3838
vi.mock('@modelcontextprotocol/sdk/client/index.js');

packages/cli/src/config/config.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,10 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => {
11681168
// 3. Spies on console functions (for logger output) are correctly set up if needed.
11691169
// Example of a previously failing test structure:
11701170
it.skip('should correctly use mocked homedir for global path', async () => {
1171-
const MOCK_GEMINI_DIR_LOCAL = path.join('/mock/home/user', '.gemini');
1171+
const MOCK_GEMINI_DIR_LOCAL = path.join(
1172+
'/mock/home/user',
1173+
ServerConfig.GEMINI_DIR,
1174+
);
11721175
const MOCK_GLOBAL_PATH_LOCAL = path.join(
11731176
MOCK_GEMINI_DIR_LOCAL,
11741177
'GEMINI.md',

packages/cli/src/config/extensions/extensionEnablement.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import os from 'node:os';
1010
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
1111
import { ExtensionEnablementManager, Override } from './extensionEnablement.js';
1212
import type { Extension } from '../extension.js';
13+
import { GEMINI_DIR } from '@google/gemini-cli-core';
1314

1415
// Helper to create a temporary directory for testing
1516
function createTestDir() {
@@ -27,7 +28,7 @@ let manager: ExtensionEnablementManager;
2728
describe('ExtensionEnablementManager', () => {
2829
beforeEach(() => {
2930
testDir = createTestDir();
30-
configDir = path.join(testDir.path, '.gemini');
31+
configDir = path.join(testDir.path, GEMINI_DIR);
3132
manager = new ExtensionEnablementManager(configDir);
3233
});
3334

packages/cli/src/config/settings.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import {
5959
USER_SETTINGS_PATH, // This IS the mocked path.
6060
getSystemSettingsPath,
6161
getSystemDefaultsPath,
62-
SETTINGS_DIRECTORY_NAME, // This is from the original module, but used by the mock.
6362
migrateSettingsToV1,
6463
needsMigration,
6564
type Settings,
@@ -70,10 +69,10 @@ import {
7069
import { FatalConfigError, GEMINI_DIR } from '@google/gemini-cli-core';
7170

7271
const MOCK_WORKSPACE_DIR = '/mock/workspace';
73-
// Use the (mocked) SETTINGS_DIRECTORY_NAME for consistency
72+
// Use the (mocked) GEMINI_DIR for consistency
7473
const MOCK_WORKSPACE_SETTINGS_PATH = pathActual.join(
7574
MOCK_WORKSPACE_DIR,
76-
SETTINGS_DIRECTORY_NAME,
75+
GEMINI_DIR,
7776
'settings.json',
7877
);
7978

packages/cli/src/config/settings.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as dotenv from 'dotenv';
1111
import process from 'node:process';
1212
import {
1313
FatalConfigError,
14-
GEMINI_CONFIG_DIR as GEMINI_DIR,
14+
GEMINI_DIR,
1515
getErrorMessage,
1616
Storage,
1717
} from '@google/gemini-cli-core';
@@ -49,8 +49,6 @@ function getMergeStrategyForPath(path: string[]): MergeStrategy | undefined {
4949

5050
export type { Settings, MemoryImportFormat };
5151

52-
export const SETTINGS_DIRECTORY_NAME = '.gemini';
53-
5452
export const USER_SETTINGS_PATH = Storage.getGlobalSettingsPath();
5553
export const USER_SETTINGS_DIR = path.dirname(USER_SETTINGS_PATH);
5654
export const DEFAULT_EXCLUDED_ENV_VARS = ['DEBUG', 'DEBUG_MODE'];

0 commit comments

Comments
 (0)