@@ -8,13 +8,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
88import * as fs from 'node:fs' ;
99import * as path from 'node:path' ;
1010import * as os from 'node:os' ;
11- import {
12- resolveWorkspacePolicyState ,
13- autoAcceptWorkspacePolicies ,
14- setAutoAcceptWorkspacePolicies ,
15- disableWorkspacePolicies ,
16- setDisableWorkspacePolicies ,
17- } from './policy.js' ;
11+ import { resolveWorkspacePolicyState } from './policy.js' ;
1812import { writeToStderr } from '@google/gemini-cli-core' ;
1913
2014// Mock debugLogger to avoid noise in test output
@@ -47,9 +41,6 @@ describe('resolveWorkspacePolicyState', () => {
4741 fs . mkdirSync ( workspaceDir ) ;
4842 policiesDir = path . join ( workspaceDir , '.gemini' , 'policies' ) ;
4943
50- // Enable policies for these tests to verify loading logic
51- setDisableWorkspacePolicies ( false ) ;
52-
5344 vi . clearAllMocks ( ) ;
5445 } ) ;
5546
@@ -72,13 +63,6 @@ describe('resolveWorkspacePolicyState', () => {
7263 } ) ;
7364 } ) ;
7465
75- it ( 'should have disableWorkspacePolicies set to true by default' , ( ) => {
76- // We explicitly set it to false in beforeEach for other tests,
77- // so here we test that setting it to true works.
78- setDisableWorkspacePolicies ( true ) ;
79- expect ( disableWorkspacePolicies ) . toBe ( true ) ;
80- } ) ;
81-
8266 it ( 'should return policy directory if integrity matches' , async ( ) => {
8367 // Set up policies directory with a file
8468 fs . mkdirSync ( policiesDir , { recursive : true } ) ;
@@ -123,33 +107,26 @@ describe('resolveWorkspacePolicyState', () => {
123107 expect ( result . policyUpdateConfirmationRequest ) . toBeUndefined ( ) ;
124108 } ) ;
125109
126- it ( 'should return confirmation request if changed in interactive mode when AUTO_ACCEPT is false' , async ( ) => {
127- const originalValue = autoAcceptWorkspacePolicies ;
128- setAutoAcceptWorkspacePolicies ( false ) ;
129-
130- try {
131- fs . mkdirSync ( policiesDir , { recursive : true } ) ;
132- fs . writeFileSync ( path . join ( policiesDir , 'policy.toml' ) , 'rules = []' ) ;
110+ it ( 'should return confirmation request if changed in interactive mode' , async ( ) => {
111+ fs . mkdirSync ( policiesDir , { recursive : true } ) ;
112+ fs . writeFileSync ( path . join ( policiesDir , 'policy.toml' ) , 'rules = []' ) ;
133113
134- const result = await resolveWorkspacePolicyState ( {
135- cwd : workspaceDir ,
136- trustedFolder : true ,
137- interactive : true ,
138- } ) ;
114+ const result = await resolveWorkspacePolicyState ( {
115+ cwd : workspaceDir ,
116+ trustedFolder : true ,
117+ interactive : true ,
118+ } ) ;
139119
140- expect ( result . workspacePoliciesDir ) . toBeUndefined ( ) ;
141- expect ( result . policyUpdateConfirmationRequest ) . toEqual ( {
142- scope : 'workspace' ,
143- identifier : workspaceDir ,
144- policyDir : policiesDir ,
145- newHash : expect . any ( String ) ,
146- } ) ;
147- } finally {
148- setAutoAcceptWorkspacePolicies ( originalValue ) ;
149- }
120+ expect ( result . workspacePoliciesDir ) . toBeUndefined ( ) ;
121+ expect ( result . policyUpdateConfirmationRequest ) . toEqual ( {
122+ scope : 'workspace' ,
123+ identifier : workspaceDir ,
124+ policyDir : policiesDir ,
125+ newHash : expect . any ( String ) ,
126+ } ) ;
150127 } ) ;
151128
152- it ( 'should warn and auto-accept if changed in non-interactive mode when AUTO_ACCEPT is true ' , async ( ) => {
129+ it ( 'should warn and auto-accept if changed in non-interactive mode' , async ( ) => {
153130 fs . mkdirSync ( policiesDir , { recursive : true } ) ;
154131 fs . writeFileSync ( path . join ( policiesDir , 'policy.toml' ) , 'rules = []' ) ;
155132
@@ -166,30 +143,6 @@ describe('resolveWorkspacePolicyState', () => {
166143 ) ;
167144 } ) ;
168145
169- it ( 'should warn and auto-accept if changed in non-interactive mode when AUTO_ACCEPT is false' , async ( ) => {
170- const originalValue = autoAcceptWorkspacePolicies ;
171- setAutoAcceptWorkspacePolicies ( false ) ;
172-
173- try {
174- fs . mkdirSync ( policiesDir , { recursive : true } ) ;
175- fs . writeFileSync ( path . join ( policiesDir , 'policy.toml' ) , 'rules = []' ) ;
176-
177- const result = await resolveWorkspacePolicyState ( {
178- cwd : workspaceDir ,
179- trustedFolder : true ,
180- interactive : false ,
181- } ) ;
182-
183- expect ( result . workspacePoliciesDir ) . toBe ( policiesDir ) ;
184- expect ( result . policyUpdateConfirmationRequest ) . toBeUndefined ( ) ;
185- expect ( writeToStderr ) . toHaveBeenCalledWith (
186- expect . stringContaining ( 'Automatically accepting and loading' ) ,
187- ) ;
188- } finally {
189- setAutoAcceptWorkspacePolicies ( originalValue ) ;
190- }
191- } ) ;
192-
193146 it ( 'should not return workspace policies if cwd is the home directory' , async ( ) => {
194147 const policiesDir = path . join ( tempDir , '.gemini' , 'policies' ) ;
195148 fs . mkdirSync ( policiesDir , { recursive : true } ) ;
@@ -206,26 +159,7 @@ describe('resolveWorkspacePolicyState', () => {
206159 expect ( result . policyUpdateConfirmationRequest ) . toBeUndefined ( ) ;
207160 } ) ;
208161
209- it ( 'should return empty state if disableWorkspacePolicies is true even if folder is trusted' , async ( ) => {
210- setDisableWorkspacePolicies ( true ) ;
211-
212- // Set up policies directory with a file
213- fs . mkdirSync ( policiesDir , { recursive : true } ) ;
214- fs . writeFileSync ( path . join ( policiesDir , 'policy.toml' ) , 'rules = []' ) ;
215-
216- const result = await resolveWorkspacePolicyState ( {
217- cwd : workspaceDir ,
218- trustedFolder : true ,
219- interactive : true ,
220- } ) ;
221-
222- expect ( result ) . toEqual ( {
223- workspacePoliciesDir : undefined ,
224- policyUpdateConfirmationRequest : undefined ,
225- } ) ;
226- } ) ;
227-
228- it ( 'should return empty state if cwd is a symlink to the home directory' , async ( ) => {
162+ it ( 'should not return workspace policies if cwd is a symlink to the home directory' , async ( ) => {
229163 const policiesDir = path . join ( tempDir , '.gemini' , 'policies' ) ;
230164 fs . mkdirSync ( policiesDir , { recursive : true } ) ;
231165 fs . writeFileSync ( path . join ( policiesDir , 'policy.toml' ) , 'rules = []' ) ;
0 commit comments