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
13 changes: 2 additions & 11 deletions integration-tests/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,14 @@ import {
} from 'node:fs/promises';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import * as os from 'node:os';

import {
GEMINI_CONFIG_DIR,
DEFAULT_CONTEXT_FILENAME,
} from '../packages/core/src/tools/memoryTool.js';
import { getGlobalMemoryFilePath } from '../packages/core/src/tools/memoryTool.js';

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

const memoryFilePath = join(
os.homedir(),
GEMINI_CONFIG_DIR,
DEFAULT_CONTEXT_FILENAME,
);
const memoryFilePath = getGlobalMemoryFilePath();
let originalMemoryContent: string | null = null;

export async function setup() {
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import fs from 'node:fs';
import * as pty from '@lydell/node-pty';
import stripAnsi from 'strip-ansi';
import * as os from 'node:os';
import { GEMINI_DIR } from '../packages/core/src/utils/paths.js';

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

Expand Down Expand Up @@ -244,7 +245,7 @@ export class TestRig {
mkdirSync(this.testDir, { recursive: true });

// Create a settings file to point the CLI to the local collector
const geminiDir = join(this.testDir, '.gemini');
const geminiDir = join(this.testDir, GEMINI_DIR);
mkdirSync(geminiDir, { recursive: true });
// In sandbox mode, use an absolute path for telemetry inside the container
// The container mounts the test directory at the same path as the host
Expand Down
10 changes: 3 additions & 7 deletions packages/a2a-server/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
FileDiscoveryService,
ApprovalMode,
loadServerHierarchicalMemory,
GEMINI_CONFIG_DIR,
GEMINI_DIR,
DEFAULT_GEMINI_EMBEDDING_MODEL,
DEFAULT_GEMINI_MODEL,
type GeminiCLIExtension,
Expand Down Expand Up @@ -176,7 +176,7 @@ function findEnvFile(startDir: string): string | null {
let currentDir = path.resolve(startDir);
while (true) {
// prefer gemini-specific .env under GEMINI_DIR
const geminiEnvPath = path.join(currentDir, GEMINI_CONFIG_DIR, '.env');
const geminiEnvPath = path.join(currentDir, GEMINI_DIR, '.env');
if (fs.existsSync(geminiEnvPath)) {
return geminiEnvPath;
}
Expand All @@ -187,11 +187,7 @@ function findEnvFile(startDir: string): string | null {
const parentDir = path.dirname(currentDir);
if (parentDir === currentDir || !parentDir) {
// check .env under home as fallback, again preferring gemini-specific .env
const homeGeminiEnvPath = path.join(
process.cwd(),
GEMINI_CONFIG_DIR,
'.env',
);
const homeGeminiEnvPath = path.join(process.cwd(), GEMINI_DIR, '.env');
if (fs.existsSync(homeGeminiEnvPath)) {
return homeGeminiEnvPath;
}
Expand Down
11 changes: 6 additions & 5 deletions packages/a2a-server/src/config/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

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

import type {
MCPServerConfig,
ExtensionInstallMetadata,
GeminiCLIExtension,
import {
GEMINI_DIR,
type MCPServerConfig,
type ExtensionInstallMetadata,
type GeminiCLIExtension,
} from '@google/gemini-cli-core';
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as os from 'node:os';
import { logger } from '../utils/logger.js';

export const EXTENSIONS_DIRECTORY_NAME = path.join('.gemini', 'extensions');
export const EXTENSIONS_DIRECTORY_NAME = path.join(GEMINI_DIR, 'extensions');
export const EXTENSIONS_CONFIG_FILENAME = 'gemini-extension.json';
export const INSTALL_METADATA_FILENAME = '.gemini-extension-install.json';

Expand Down
6 changes: 3 additions & 3 deletions packages/a2a-server/src/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { homedir } from 'node:os';

import type { MCPServerConfig } from '@google/gemini-cli-core';
import {
GEMINI_DIR,
getErrorMessage,
type TelemetrySettings,
} from '@google/gemini-cli-core';
import stripJsonComments from 'strip-json-comments';

export const SETTINGS_DIRECTORY_NAME = '.gemini';
export const USER_SETTINGS_DIR = path.join(homedir(), SETTINGS_DIRECTORY_NAME);
export const USER_SETTINGS_DIR = path.join(homedir(), GEMINI_DIR);
export const USER_SETTINGS_PATH = path.join(USER_SETTINGS_DIR, 'settings.json');

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

const workspaceSettingsPath = path.join(
workspaceDir,
SETTINGS_DIRECTORY_NAME,
GEMINI_DIR,
'settings.json',
);

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/mcp/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ vi.mock('@google/gemini-cli-core', () => ({
getWorkspaceSettingsPath: () => '/tmp/gemini/workspace-settings.json',
getProjectTempDir: () => '/test/home/.gemini/tmp/mocked_hash',
})),
GEMINI_CONFIG_DIR: '.gemini',
GEMINI_DIR: '.gemini',
getErrorMessage: (e: unknown) => (e instanceof Error ? e.message : String(e)),
}));
vi.mock('@modelcontextprotocol/sdk/client/index.js');
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/mcp/remove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { removeCommand } from './remove.js';
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as os from 'node:os';
import { GEMINI_DIR } from '@google/gemini-cli-core';

vi.mock('fs/promises', () => ({
readFile: vi.fn(),
Expand Down Expand Up @@ -80,7 +81,7 @@ describe('mcp remove command', () => {
vi.restoreAllMocks();

tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mcp-remove-test-'));
settingsDir = path.join(tempDir, '.gemini');
settingsDir = path.join(tempDir, GEMINI_DIR);
settingsPath = path.join(settingsDir, 'settings.json');
fs.mkdirSync(settingsDir, { recursive: true });

Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,10 @@
// 3. Spies on console functions (for logger output) are correctly set up if needed.
// Example of a previously failing test structure:
it.skip('should correctly use mocked homedir for global path', async () => {
const MOCK_GEMINI_DIR_LOCAL = path.join('/mock/home/user', '.gemini');
const MOCK_GEMINI_DIR_LOCAL = path.join(
'/mock/home/user',
ServerConfig.GEMINI_DIR,
);
const MOCK_GLOBAL_PATH_LOCAL = path.join(
MOCK_GEMINI_DIR_LOCAL,
'GEMINI.md',
Expand Down Expand Up @@ -2036,7 +2039,7 @@
const config = await loadCliConfig(
{
model: {
name: 'gemini-9001-ultra',

Check warning on line 2042 in packages/cli/src/config/config.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-9001". Please make sure this change is appropriate to submit.
},
},
[],
Expand All @@ -2048,7 +2051,7 @@
argv,
);

expect(config.getModel()).toBe('gemini-9001-ultra');

Check warning on line 2054 in packages/cli/src/config/config.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-9001". Please make sure this change is appropriate to submit.
});

it('uses the default gemini model if nothing is set', async () => {
Expand All @@ -2071,12 +2074,12 @@
});

it('always prefers model from argvs', async () => {
process.argv = ['node', 'script.js', '--model', 'gemini-8675309-ultra'];

Check warning on line 2077 in packages/cli/src/config/config.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-8675309". Please make sure this change is appropriate to submit.
const argv = await parseArguments({} as Settings);
const config = await loadCliConfig(
{
model: {
name: 'gemini-9001-ultra',

Check warning on line 2082 in packages/cli/src/config/config.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-9001". Please make sure this change is appropriate to submit.
},
},
[],
Expand All @@ -2088,11 +2091,11 @@
argv,
);

expect(config.getModel()).toBe('gemini-8675309-ultra');

Check warning on line 2094 in packages/cli/src/config/config.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-8675309". Please make sure this change is appropriate to submit.
});

it('selects the model from argvs if provided', async () => {
process.argv = ['node', 'script.js', '--model', 'gemini-8675309-ultra'];

Check warning on line 2098 in packages/cli/src/config/config.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-8675309". Please make sure this change is appropriate to submit.
const argv = await parseArguments({} as Settings);
const config = await loadCliConfig(
{
Expand All @@ -2107,7 +2110,7 @@
argv,
);

expect(config.getModel()).toBe('gemini-8675309-ultra');

Check warning on line 2113 in packages/cli/src/config/config.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-8675309". Please make sure this change is appropriate to submit.
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import fs from 'node:fs';
import os from 'node:os';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { ExtensionEnablementManager, Override } from './extensionEnablement.js';
import type { GeminiCLIExtension } from '@google/gemini-cli-core';

import { GEMINI_DIR, type GeminiCLIExtension } from '@google/gemini-cli-core';

// Helper to create a temporary directory for testing
function createTestDir() {
Expand All @@ -27,7 +28,7 @@ let manager: ExtensionEnablementManager;
describe('ExtensionEnablementManager', () => {
beforeEach(() => {
testDir = createTestDir();
configDir = path.join(testDir.path, '.gemini');
configDir = path.join(testDir.path, GEMINI_DIR);
manager = new ExtensionEnablementManager(configDir);
});

Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/config/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import {
USER_SETTINGS_PATH, // This IS the mocked path.
getSystemSettingsPath,
getSystemDefaultsPath,
SETTINGS_DIRECTORY_NAME, // This is from the original module, but used by the mock.
migrateSettingsToV1,
needsMigration,
type Settings,
Expand All @@ -70,10 +69,10 @@ import {
import { FatalConfigError, GEMINI_DIR } from '@google/gemini-cli-core';

const MOCK_WORKSPACE_DIR = '/mock/workspace';
// Use the (mocked) SETTINGS_DIRECTORY_NAME for consistency
// Use the (mocked) GEMINI_DIR for consistency
const MOCK_WORKSPACE_SETTINGS_PATH = pathActual.join(
MOCK_WORKSPACE_DIR,
SETTINGS_DIRECTORY_NAME,
GEMINI_DIR,
'settings.json',
);

Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as dotenv from 'dotenv';
import process from 'node:process';
import {
FatalConfigError,
GEMINI_CONFIG_DIR as GEMINI_DIR,
GEMINI_DIR,
getErrorMessage,
Storage,
} from '@google/gemini-cli-core';
Expand Down Expand Up @@ -49,8 +49,6 @@ function getMergeStrategyForPath(path: string[]): MergeStrategy | undefined {

export type { Settings, MemoryImportFormat };

export const SETTINGS_DIRECTORY_NAME = '.gemini';

export const USER_SETTINGS_PATH = Storage.getGlobalSettingsPath();
export const USER_SETTINGS_DIR = path.dirname(USER_SETTINGS_PATH);
export const DEFAULT_EXCLUDED_ENV_VARS = ['DEBUG', 'DEBUG_MODE'];
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/config/trustedFolders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {
getErrorMessage,
isWithinRoot,
ideContextStore,
GEMINI_DIR,
} from '@google/gemini-cli-core';
import type { Settings } from './settings.js';
import stripJsonComments from 'strip-json-comments';

export const TRUSTED_FOLDERS_FILENAME = 'trustedFolders.json';
export const SETTINGS_DIRECTORY_NAME = '.gemini';
export const USER_SETTINGS_DIR = path.join(homedir(), SETTINGS_DIRECTORY_NAME);
export const USER_SETTINGS_DIR = path.join(homedir(), GEMINI_DIR);

export function getTrustedFoldersPath(): string {
if (process.env['GEMINI_CLI_TRUSTED_FOLDERS_PATH']) {
Expand Down
29 changes: 22 additions & 7 deletions packages/cli/src/services/FileCommandLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import * as path from 'node:path';
import type { Config } from '@google/gemini-cli-core';
import { Storage } from '@google/gemini-cli-core';
import { GEMINI_DIR, Storage } from '@google/gemini-cli-core';
import mock from 'mock-fs';
import { FileCommandLoader } from './FileCommandLoader.js';
import { assert, vi } from 'vitest';
Expand Down Expand Up @@ -529,7 +529,9 @@ describe('FileCommandLoader', () => {
).getProjectCommandsDir();
const extensionDir = path.join(
process.cwd(),
'.gemini/extensions/test-ext',
GEMINI_DIR,
'extensions',
'test-ext',
);

mock({
Expand Down Expand Up @@ -582,7 +584,9 @@ describe('FileCommandLoader', () => {
).getProjectCommandsDir();
const extensionDir = path.join(
process.cwd(),
'.gemini/extensions/test-ext',
GEMINI_DIR,
'extensions',
'test-ext',
);

mock({
Expand Down Expand Up @@ -678,11 +682,15 @@ describe('FileCommandLoader', () => {
it('only loads commands from active extensions', async () => {
const extensionDir1 = path.join(
process.cwd(),
'.gemini/extensions/active-ext',
GEMINI_DIR,
'extensions',
'active-ext',
);
const extensionDir2 = path.join(
process.cwd(),
'.gemini/extensions/inactive-ext',
GEMINI_DIR,
'extensions',
'inactive-ext',
);

mock({
Expand Down Expand Up @@ -737,7 +745,9 @@ describe('FileCommandLoader', () => {
it('handles missing extension commands directory gracefully', async () => {
const extensionDir = path.join(
process.cwd(),
'.gemini/extensions/no-commands',
GEMINI_DIR,
'extensions',
'no-commands',
);

mock({
Expand Down Expand Up @@ -769,7 +779,12 @@ describe('FileCommandLoader', () => {
});

it('handles nested command structure in extensions', async () => {
const extensionDir = path.join(process.cwd(), '.gemini/extensions/a');
const extensionDir = path.join(
process.cwd(),
GEMINI_DIR,
'extensions',
'a',
);

mock({
[extensionDir]: {
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/ui/commands/restoreCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import * as path from 'node:path';
import { restoreCommand } from './restoreCommand.js';
import { type CommandContext } from './types.js';
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
import type { Config, GitService } from '@google/gemini-cli-core';
import {
GEMINI_DIR,
type Config,
type GitService,
} from '@google/gemini-cli-core';

describe('restoreCommand', () => {
let mockContext: CommandContext;
Expand All @@ -26,7 +30,7 @@ describe('restoreCommand', () => {
testRootDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'restore-command-test-'),
);
geminiTempDir = path.join(testRootDir, '.gemini');
geminiTempDir = path.join(testRootDir, GEMINI_DIR);
checkpointsDir = path.join(geminiTempDir, 'checkpoints');
// The command itself creates this, but for tests it's easier to have it ready.
// Some tests might remove it to test error paths.
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/ui/components/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { theme } from '../semantic-colors.js';
import { StreamingState } from '../types.js';
import { UpdateNotification } from './UpdateNotification.js';

import { GEMINI_DIR } from '@google/gemini-cli-core';
import { homedir } from 'node:os';
import path from 'node:path';

const settingsPath = path.join(homedir(), '.gemini', 'settings.json');
const settingsPath = path.join(homedir(), GEMINI_DIR, 'settings.json');

export const Notifications = () => {
const { startupWarnings } = useAppContext();
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/ui/hooks/useFlickerDetector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ vi.mock('../contexts/ConfigContext.js');
vi.mock('../contexts/UIStateContext.js');
vi.mock('@google/gemini-cli-core', () => ({
recordFlickerFrame: vi.fn(),
GEMINI_DIR: '.gemini',
}));
vi.mock('ink', async (importOriginal) => {
const original = await importOriginal<typeof import('ink')>();
Expand Down
Loading