Skip to content

Commit 0777f06

Browse files
committed
fix(core): revert auto-save of policies to user space
Reverts the auto-save of tool approval policies from the workspace directory back to the global user space (~/.gemini/policies). This change is necessary as workspace policies are being temporarily disabled to simplify policy management. - Updated Storage.getAutoSavedPolicyPath to use getUserPoliciesDir. - Modified createPolicyUpdater to ensure the parent directory of the policy file is created before writing. - Updated persistence tests to reflect the change in storage location. Fixes: #20530 Refs: #20522
1 parent b1befee commit 0777f06

3 files changed

Lines changed: 11 additions & 40 deletions

File tree

packages/core/src/config/storage.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ export class Storage {
169169
}
170170

171171
getAutoSavedPolicyPath(): string {
172-
return path.join(
173-
this.getWorkspacePoliciesDir(),
174-
AUTO_SAVED_POLICY_FILENAME,
175-
);
172+
return path.join(Storage.getUserPoliciesDir(), AUTO_SAVED_POLICY_FILENAME);
176173
}
177174

178175
ensureProjectTempDirExists(): void {

packages/core/src/policy/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,8 @@ export function createPolicyUpdater(
447447
if (message.persist) {
448448
persistenceQueue = persistenceQueue.then(async () => {
449449
try {
450-
const workspacePoliciesDir = storage.getWorkspacePoliciesDir();
451-
await fs.mkdir(workspacePoliciesDir, { recursive: true });
452450
const policyFile = storage.getAutoSavedPolicyPath();
451+
await fs.mkdir(path.dirname(policyFile), { recursive: true });
453452

454453
// Read existing file
455454
let existingData: { rule?: TomlRule[] } = {};

packages/core/src/policy/persistence.test.ts

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,8 @@ describe('createPolicyUpdater', () => {
4848
it('should persist policy when persist flag is true', async () => {
4949
createPolicyUpdater(policyEngine, messageBus, mockStorage);
5050

51-
const workspacePoliciesDir = '/mock/project/.gemini/policies';
52-
const policyFile = path.join(
53-
workspacePoliciesDir,
54-
AUTO_SAVED_POLICY_FILENAME,
55-
);
56-
vi.spyOn(mockStorage, 'getWorkspacePoliciesDir').mockReturnValue(
57-
workspacePoliciesDir,
58-
);
51+
const userPoliciesDir = '/mock/user/.gemini/policies';
52+
const policyFile = path.join(userPoliciesDir, AUTO_SAVED_POLICY_FILENAME);
5953
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
6054
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
6155
(fs.readFile as unknown as Mock).mockRejectedValue(
@@ -79,8 +73,7 @@ describe('createPolicyUpdater', () => {
7973
// Wait for async operations (microtasks)
8074
await new Promise((resolve) => setTimeout(resolve, 0));
8175

82-
expect(mockStorage.getWorkspacePoliciesDir).toHaveBeenCalled();
83-
expect(fs.mkdir).toHaveBeenCalledWith(workspacePoliciesDir, {
76+
expect(fs.mkdir).toHaveBeenCalledWith(userPoliciesDir, {
8477
recursive: true,
8578
});
8679

@@ -115,14 +108,8 @@ describe('createPolicyUpdater', () => {
115108
it('should persist policy with commandPrefix when provided', async () => {
116109
createPolicyUpdater(policyEngine, messageBus, mockStorage);
117110

118-
const workspacePoliciesDir = '/mock/project/.gemini/policies';
119-
const policyFile = path.join(
120-
workspacePoliciesDir,
121-
AUTO_SAVED_POLICY_FILENAME,
122-
);
123-
vi.spyOn(mockStorage, 'getWorkspacePoliciesDir').mockReturnValue(
124-
workspacePoliciesDir,
125-
);
111+
const userPoliciesDir = '/mock/user/.gemini/policies';
112+
const policyFile = path.join(userPoliciesDir, AUTO_SAVED_POLICY_FILENAME);
126113
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
127114
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
128115
(fs.readFile as unknown as Mock).mockRejectedValue(
@@ -168,14 +155,8 @@ describe('createPolicyUpdater', () => {
168155
it('should persist policy with mcpName and toolName when provided', async () => {
169156
createPolicyUpdater(policyEngine, messageBus, mockStorage);
170157

171-
const workspacePoliciesDir = '/mock/project/.gemini/policies';
172-
const policyFile = path.join(
173-
workspacePoliciesDir,
174-
AUTO_SAVED_POLICY_FILENAME,
175-
);
176-
vi.spyOn(mockStorage, 'getWorkspacePoliciesDir').mockReturnValue(
177-
workspacePoliciesDir,
178-
);
158+
const userPoliciesDir = '/mock/user/.gemini/policies';
159+
const policyFile = path.join(userPoliciesDir, AUTO_SAVED_POLICY_FILENAME);
179160
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
180161
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
181162
(fs.readFile as unknown as Mock).mockRejectedValue(
@@ -214,14 +195,8 @@ describe('createPolicyUpdater', () => {
214195
it('should escape special characters in toolName and mcpName', async () => {
215196
createPolicyUpdater(policyEngine, messageBus, mockStorage);
216197

217-
const workspacePoliciesDir = '/mock/project/.gemini/policies';
218-
const policyFile = path.join(
219-
workspacePoliciesDir,
220-
AUTO_SAVED_POLICY_FILENAME,
221-
);
222-
vi.spyOn(mockStorage, 'getWorkspacePoliciesDir').mockReturnValue(
223-
workspacePoliciesDir,
224-
);
198+
const userPoliciesDir = '/mock/user/.gemini/policies';
199+
const policyFile = path.join(userPoliciesDir, AUTO_SAVED_POLICY_FILENAME);
225200
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
226201
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
227202
(fs.readFile as unknown as Mock).mockRejectedValue(

0 commit comments

Comments
 (0)