4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
6
6
7
- // Mock 'os' first.
8
7
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' ;
18
9
import {
19
10
describe ,
20
11
it ,
@@ -28,7 +19,6 @@ import {
28
19
import * as fs from 'node:fs' ;
29
20
import stripJsonComments from 'strip-json-comments' ;
30
21
import * as path from 'node:path' ;
31
-
32
22
import {
33
23
loadTrustedFolders ,
34
24
USER_TRUSTED_FOLDERS_PATH ,
@@ -37,6 +27,14 @@ import {
37
27
} from './trustedFolders.js' ;
38
28
import type { Settings } from './settings.js' ;
39
29
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
+ } ) ;
40
38
vi . mock ( 'fs' , async ( importOriginal ) => {
41
39
const actualFs = await importOriginal < typeof fs > ( ) ;
42
40
return {
@@ -47,7 +45,6 @@ vi.mock('fs', async (importOriginal) => {
47
45
mkdirSync : vi . fn ( ) ,
48
46
} ;
49
47
} ) ;
50
-
51
48
vi . mock ( 'strip-json-comments' , ( ) => ( {
52
49
default : vi . fn ( ( content ) => content ) ,
53
50
} ) ) ;
@@ -256,17 +253,11 @@ describe('isWorkspaceTrusted', () => {
256
253
} ) ;
257
254
} ) ;
258
255
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
-
269
256
describe ( 'isWorkspaceTrusted with IDE override' , ( ) => {
257
+ afterEach ( ( ) => {
258
+ ideContextStore . clear ( ) ;
259
+ } ) ;
260
+
270
261
const mockSettings : Settings = {
271
262
security : {
272
263
folderTrust : {
@@ -276,7 +267,7 @@ describe('isWorkspaceTrusted with IDE override', () => {
276
267
} ;
277
268
278
269
it ( 'should return true when ideTrust is true, ignoring config' , ( ) => {
279
- vi . mocked ( getIdeTrust ) . mockReturnValue ( true ) ;
270
+ ideContextStore . set ( { workspaceState : { isTrusted : true } } ) ;
280
271
// Even if config says don't trust, ideTrust should win.
281
272
vi . spyOn ( fs , 'readFileSync' ) . mockReturnValue (
282
273
JSON . stringify ( { [ process . cwd ( ) ] : TrustLevel . DO_NOT_TRUST } ) ,
@@ -285,7 +276,7 @@ describe('isWorkspaceTrusted with IDE override', () => {
285
276
} ) ;
286
277
287
278
it ( 'should return false when ideTrust is false, ignoring config' , ( ) => {
288
- vi . mocked ( getIdeTrust ) . mockReturnValue ( false ) ;
279
+ ideContextStore . set ( { workspaceState : { isTrusted : false } } ) ;
289
280
// Even if config says trust, ideTrust should win.
290
281
vi . spyOn ( fs , 'readFileSync' ) . mockReturnValue (
291
282
JSON . stringify ( { [ process . cwd ( ) ] : TrustLevel . TRUST_FOLDER } ) ,
@@ -294,7 +285,6 @@ describe('isWorkspaceTrusted with IDE override', () => {
294
285
} ) ;
295
286
296
287
it ( 'should fall back to config when ideTrust is undefined' , ( ) => {
297
- vi . mocked ( getIdeTrust ) . mockReturnValue ( undefined ) ;
298
288
vi . spyOn ( fs , 'existsSync' ) . mockReturnValue ( true ) ;
299
289
vi . spyOn ( fs , 'readFileSync' ) . mockReturnValue (
300
290
JSON . stringify ( { [ process . cwd ( ) ] : TrustLevel . TRUST_FOLDER } ) ,
@@ -310,7 +300,7 @@ describe('isWorkspaceTrusted with IDE override', () => {
310
300
} ,
311
301
} ,
312
302
} ;
313
- vi . mocked ( getIdeTrust ) . mockReturnValue ( false ) ;
303
+ ideContextStore . set ( { workspaceState : { isTrusted : false } } ) ;
314
304
expect ( isWorkspaceTrusted ( settings ) ) . toBe ( true ) ;
315
305
} ) ;
316
306
} ) ;
0 commit comments