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
42 changes: 16 additions & 26 deletions packages/cli/src/config/trustedFolders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

// Mock 'os' first.
import * as osActual from 'node:os';
vi.mock('os', async (importOriginal) => {
const actualOs = await importOriginal<typeof osActual>();
return {
...actualOs,
homedir: vi.fn(() => '/mock/home/user'),
platform: vi.fn(() => 'linux'),
};
});

import { ideContextStore } from '@google/gemini-cli-core';
import {
describe,
it,
Expand All @@ -28,7 +19,6 @@ import {
import * as fs from 'node:fs';
import stripJsonComments from 'strip-json-comments';
import * as path from 'node:path';

import {
loadTrustedFolders,
USER_TRUSTED_FOLDERS_PATH,
Expand All @@ -37,6 +27,14 @@ import {
} from './trustedFolders.js';
import type { Settings } from './settings.js';

vi.mock('os', async (importOriginal) => {
const actualOs = await importOriginal<typeof osActual>();
return {
...actualOs,
homedir: vi.fn(() => '/mock/home/user'),
platform: vi.fn(() => 'linux'),
};
});
vi.mock('fs', async (importOriginal) => {
const actualFs = await importOriginal<typeof fs>();
return {
Expand All @@ -47,7 +45,6 @@ vi.mock('fs', async (importOriginal) => {
mkdirSync: vi.fn(),
};
});

vi.mock('strip-json-comments', () => ({
default: vi.fn((content) => content),
}));
Expand Down Expand Up @@ -256,17 +253,11 @@ describe('isWorkspaceTrusted', () => {
});
});

import { getIdeTrust } from '@google/gemini-cli-core';

vi.mock('@google/gemini-cli-core', async (importOriginal) => {
const actual = await importOriginal<Record<string, unknown>>();
return {
...actual,
getIdeTrust: vi.fn(),
};
});

describe('isWorkspaceTrusted with IDE override', () => {
afterEach(() => {
ideContextStore.clear();
});

const mockSettings: Settings = {
security: {
folderTrust: {
Expand All @@ -276,7 +267,7 @@ describe('isWorkspaceTrusted with IDE override', () => {
};

it('should return true when ideTrust is true, ignoring config', () => {
vi.mocked(getIdeTrust).mockReturnValue(true);
ideContextStore.set({ workspaceState: { isTrusted: true } });
// Even if config says don't trust, ideTrust should win.
vi.spyOn(fs, 'readFileSync').mockReturnValue(
JSON.stringify({ [process.cwd()]: TrustLevel.DO_NOT_TRUST }),
Expand All @@ -285,7 +276,7 @@ describe('isWorkspaceTrusted with IDE override', () => {
});

it('should return false when ideTrust is false, ignoring config', () => {
vi.mocked(getIdeTrust).mockReturnValue(false);
ideContextStore.set({ workspaceState: { isTrusted: false } });
// Even if config says trust, ideTrust should win.
vi.spyOn(fs, 'readFileSync').mockReturnValue(
JSON.stringify({ [process.cwd()]: TrustLevel.TRUST_FOLDER }),
Expand All @@ -294,7 +285,6 @@ describe('isWorkspaceTrusted with IDE override', () => {
});

it('should fall back to config when ideTrust is undefined', () => {
vi.mocked(getIdeTrust).mockReturnValue(undefined);
vi.spyOn(fs, 'existsSync').mockReturnValue(true);
vi.spyOn(fs, 'readFileSync').mockReturnValue(
JSON.stringify({ [process.cwd()]: TrustLevel.TRUST_FOLDER }),
Expand All @@ -310,7 +300,7 @@ describe('isWorkspaceTrusted with IDE override', () => {
},
},
};
vi.mocked(getIdeTrust).mockReturnValue(false);
ideContextStore.set({ workspaceState: { isTrusted: false } });
expect(isWorkspaceTrusted(settings)).toBe(true);
});
});
4 changes: 2 additions & 2 deletions packages/cli/src/config/trustedFolders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { homedir } from 'node:os';
import {
getErrorMessage,
isWithinRoot,
getIdeTrust,
ideContextStore,
} from '@google/gemini-cli-core';
import type { Settings } from './settings.js';
import stripJsonComments from 'strip-json-comments';
Expand Down Expand Up @@ -182,7 +182,7 @@ export function isWorkspaceTrusted(settings: Settings): boolean | undefined {
return true;
}

const ideTrust = getIdeTrust();
const ideTrust = ideContextStore.get()?.workspaceState?.isTrusted;
if (ideTrust !== undefined) {
return ideTrust;
}
Expand Down
14 changes: 13 additions & 1 deletion packages/cli/src/core/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { type Config } from '@google/gemini-cli-core';
import {
IdeClient,
IdeConnectionEvent,
IdeConnectionType,
logIdeConnection,
type Config,
} from '@google/gemini-cli-core';
import { type LoadedSettings } from '../config/settings.js';
import { performInitialAuth } from './auth.js';
import { validateTheme } from './theme.js';
Expand Down Expand Up @@ -36,6 +42,12 @@ export async function initializeApp(
const shouldOpenAuthDialog =
settings.merged.security?.auth?.selectedType === undefined || !!authError;

if (config.getIdeMode()) {
const ideClient = await IdeClient.getInstance();
await ideClient.connect();
logIdeConnection(config, new IdeConnectionEvent(IdeConnectionType.START));
}

return {
authError,
themeError,
Expand Down
1 change: 0 additions & 1 deletion packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export {
IdeConnectionType,
ExtensionInstallEvent,
} from './src/telemetry/types.js';
export { getIdeTrust } from './src/utils/ide-trust.js';
export { makeFakeConfig } from './src/test-utils/config.js';
export * from './src/utils/pathReader.js';
export { ClearcutLogger } from './src/telemetry/clearcut-logger/clearcut-logger.js';
13 changes: 1 addition & 12 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,14 @@ import {
} from './models.js';
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
import type { MCPOAuthConfig } from '../mcp/oauth-provider.js';
import { IdeClient } from '../ide/ide-client.js';
import { ideContextStore } from '../ide/ideContext.js';
import type { FileSystemService } from '../services/fileSystemService.js';
import { StandardFileSystemService } from '../services/fileSystemService.js';
import {
logCliConfiguration,
logIdeConnection,
logRipgrepFallback,
} from '../telemetry/loggers.js';
import {
IdeConnectionEvent,
IdeConnectionType,
RipgrepFallbackEvent,
} from '../telemetry/types.js';
import { RipgrepFallbackEvent } from '../telemetry/types.js';
import type { FallbackModelHandler } from '../fallback/types.js';
import { ModelRouterService } from '../routing/modelRouterService.js';
import { OutputFormat } from '../output/types.js';
Expand Down Expand Up @@ -439,11 +433,6 @@ export class Config {
}
this.initialized = true;

if (this.getIdeMode()) {
await (await IdeClient.getInstance()).connect();
logIdeConnection(this, new IdeConnectionEvent(IdeConnectionType.START));
}

// Initialize centralized FileDiscoveryService
this.getFileService();
if (this.getCheckpointingEnabled()) {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export * from './utils/errorParsing.js';
export * from './utils/workspaceContext.js';
export * from './utils/ignorePatterns.js';
export * from './utils/partUtils.js';
export * from './utils/ide-trust.js';
export * from './utils/promptIdContext.js';

// Export services
Expand Down
15 changes: 0 additions & 15 deletions packages/core/src/utils/ide-trust.ts

This file was deleted.

Loading