Skip to content

Commit 72033d0

Browse files
committed
Revert "feat(cli): add temporary flag to disable workspace policies (#20523)"
This reverts commit f13a306.
1 parent f13a306 commit 72033d0

4 files changed

Lines changed: 20 additions & 140 deletions

File tree

package-lock.json

Lines changed: 1 addition & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 18 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
88
import * as fs from 'node:fs';
99
import * as path from 'node:path';
1010
import * 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';
1812
import { 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 = []');

packages/cli/src/config/policy.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,6 @@ import {
2020
} from '@google/gemini-cli-core';
2121
import { type Settings } from './settings.js';
2222

23-
/**
24-
* Temporary flag to automatically accept workspace policies to reduce friction.
25-
* Exported as 'let' to allow monkey patching in tests via the setter.
26-
*/
27-
export let autoAcceptWorkspacePolicies = true;
28-
29-
/**
30-
* Sets the autoAcceptWorkspacePolicies flag.
31-
* Used primarily for testing purposes.
32-
*/
33-
export function setAutoAcceptWorkspacePolicies(value: boolean) {
34-
autoAcceptWorkspacePolicies = value;
35-
}
36-
37-
/**
38-
* Temporary flag to disable workspace level policies altogether.
39-
* Exported as 'let' to allow monkey patching in tests via the setter.
40-
*/
41-
export let disableWorkspacePolicies = true;
42-
43-
/**
44-
* Sets the disableWorkspacePolicies flag.
45-
* Used primarily for testing purposes.
46-
*/
47-
export function setDisableWorkspacePolicies(value: boolean) {
48-
disableWorkspacePolicies = value;
49-
}
50-
5123
export async function createPolicyEngineConfig(
5224
settings: Settings,
5325
approvalMode: ApprovalMode,
@@ -94,7 +66,7 @@ export async function resolveWorkspacePolicyState(options: {
9466
| PolicyUpdateConfirmationRequest
9567
| undefined;
9668

97-
if (trustedFolder && !disableWorkspacePolicies) {
69+
if (trustedFolder) {
9870
const storage = new Storage(cwd);
9971

10072
// If we are in the home directory (or rather, our target Gemini dir is the global one),

0 commit comments

Comments
 (0)