Skip to content

Commit 0de7874

Browse files
committed
Move init.
1 parent 0308267 commit 0de7874

File tree

7 files changed

+32
-58
lines changed

7 files changed

+32
-58
lines changed

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

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
// Mock 'os' first.
87
import * as osActual from 'node:os';
9-
vi.mock('os', async (importOriginal) => {
10-
const actualOs = await importOriginal<typeof osActual>();
11-
return {
12-
...actualOs,
13-
homedir: vi.fn(() => '/mock/home/user'),
14-
platform: vi.fn(() => 'linux'),
15-
};
16-
});
17-
8+
import { ideContextStore } from '@google/gemini-cli-core';
189
import {
1910
describe,
2011
it,
@@ -28,7 +19,6 @@ import {
2819
import * as fs from 'node:fs';
2920
import stripJsonComments from 'strip-json-comments';
3021
import * as path from 'node:path';
31-
3222
import {
3323
loadTrustedFolders,
3424
USER_TRUSTED_FOLDERS_PATH,
@@ -37,6 +27,14 @@ import {
3727
} from './trustedFolders.js';
3828
import type { Settings } from './settings.js';
3929

30+
vi.mock('os', async (importOriginal) => {
31+
const actualOs = await importOriginal<typeof osActual>();
32+
return {
33+
...actualOs,
34+
homedir: vi.fn(() => '/mock/home/user'),
35+
platform: vi.fn(() => 'linux'),
36+
};
37+
});
4038
vi.mock('fs', async (importOriginal) => {
4139
const actualFs = await importOriginal<typeof fs>();
4240
return {
@@ -47,7 +45,6 @@ vi.mock('fs', async (importOriginal) => {
4745
mkdirSync: vi.fn(),
4846
};
4947
});
50-
5148
vi.mock('strip-json-comments', () => ({
5249
default: vi.fn((content) => content),
5350
}));
@@ -256,17 +253,11 @@ describe('isWorkspaceTrusted', () => {
256253
});
257254
});
258255

259-
import { getIdeTrust } from '@google/gemini-cli-core';
260-
261-
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
262-
const actual = await importOriginal<Record<string, unknown>>();
263-
return {
264-
...actual,
265-
getIdeTrust: vi.fn(),
266-
};
267-
});
268-
269256
describe('isWorkspaceTrusted with IDE override', () => {
257+
afterEach(() => {
258+
ideContextStore.clear();
259+
});
260+
270261
const mockSettings: Settings = {
271262
security: {
272263
folderTrust: {
@@ -276,7 +267,7 @@ describe('isWorkspaceTrusted with IDE override', () => {
276267
};
277268

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

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

296287
it('should fall back to config when ideTrust is undefined', () => {
297-
vi.mocked(getIdeTrust).mockReturnValue(undefined);
298288
vi.spyOn(fs, 'existsSync').mockReturnValue(true);
299289
vi.spyOn(fs, 'readFileSync').mockReturnValue(
300290
JSON.stringify({ [process.cwd()]: TrustLevel.TRUST_FOLDER }),
@@ -310,7 +300,7 @@ describe('isWorkspaceTrusted with IDE override', () => {
310300
},
311301
},
312302
};
313-
vi.mocked(getIdeTrust).mockReturnValue(false);
303+
ideContextStore.set({ workspaceState: { isTrusted: false } });
314304
expect(isWorkspaceTrusted(settings)).toBe(true);
315305
});
316306
});

packages/cli/src/config/trustedFolders.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { homedir } from 'node:os';
1010
import {
1111
getErrorMessage,
1212
isWithinRoot,
13-
getIdeTrust,
13+
ideContextStore,
1414
} from '@google/gemini-cli-core';
1515
import type { Settings } from './settings.js';
1616
import stripJsonComments from 'strip-json-comments';
@@ -182,7 +182,7 @@ export function isWorkspaceTrusted(settings: Settings): boolean | undefined {
182182
return true;
183183
}
184184

185-
const ideTrust = getIdeTrust();
185+
const ideTrust = ideContextStore.get()?.workspaceState?.isTrusted;
186186
if (ideTrust !== undefined) {
187187
return ideTrust;
188188
}

packages/cli/src/core/initializer.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { type Config } from '@google/gemini-cli-core';
7+
import {
8+
IdeClient,
9+
IdeConnectionEvent,
10+
IdeConnectionType,
11+
logIdeConnection,
12+
type Config,
13+
} from '@google/gemini-cli-core';
814
import { type LoadedSettings } from '../config/settings.js';
915
import { performInitialAuth } from './auth.js';
1016
import { validateTheme } from './theme.js';
@@ -36,6 +42,12 @@ export async function initializeApp(
3642
const shouldOpenAuthDialog =
3743
settings.merged.security?.auth?.selectedType === undefined || !!authError;
3844

45+
if (config.getIdeMode()) {
46+
const ideClient = await IdeClient.getInstance();
47+
await ideClient.connect();
48+
logIdeConnection(config, new IdeConnectionEvent(IdeConnectionType.START));
49+
}
50+
3951
return {
4052
authError,
4153
themeError,

packages/core/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export {
2323
IdeConnectionType,
2424
ExtensionInstallEvent,
2525
} from './src/telemetry/types.js';
26-
export { getIdeTrust } from './src/utils/ide-trust.js';
2726
export { makeFakeConfig } from './src/test-utils/config.js';
2827
export * from './src/utils/pathReader.js';
2928
export { ClearcutLogger } from './src/telemetry/clearcut-logger/clearcut-logger.js';

packages/core/src/config/config.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,14 @@ import {
4848
} from './models.js';
4949
import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
5050
import type { MCPOAuthConfig } from '../mcp/oauth-provider.js';
51-
import { IdeClient } from '../ide/ide-client.js';
5251
import { ideContextStore } from '../ide/ideContext.js';
5352
import type { FileSystemService } from '../services/fileSystemService.js';
5453
import { StandardFileSystemService } from '../services/fileSystemService.js';
5554
import {
5655
logCliConfiguration,
57-
logIdeConnection,
5856
logRipgrepFallback,
5957
} from '../telemetry/loggers.js';
60-
import {
61-
IdeConnectionEvent,
62-
IdeConnectionType,
63-
RipgrepFallbackEvent,
64-
} from '../telemetry/types.js';
58+
import { RipgrepFallbackEvent } from '../telemetry/types.js';
6559
import type { FallbackModelHandler } from '../fallback/types.js';
6660
import { ModelRouterService } from '../routing/modelRouterService.js';
6761
import { OutputFormat } from '../output/types.js';
@@ -439,11 +433,6 @@ export class Config {
439433
}
440434
this.initialized = true;
441435

442-
if (this.getIdeMode()) {
443-
await (await IdeClient.getInstance()).connect();
444-
logIdeConnection(this, new IdeConnectionEvent(IdeConnectionType.START));
445-
}
446-
447436
// Initialize centralized FileDiscoveryService
448437
this.getFileService();
449438
if (this.getCheckpointingEnabled()) {

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export * from './utils/errorParsing.js';
5151
export * from './utils/workspaceContext.js';
5252
export * from './utils/ignorePatterns.js';
5353
export * from './utils/partUtils.js';
54-
export * from './utils/ide-trust.js';
5554
export * from './utils/promptIdContext.js';
5655

5756
// Export services

packages/core/src/utils/ide-trust.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)