mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-11 22:51:00 -07:00
fix(core): revert auto-save of policies to user space (#20531)
This commit is contained in:
@@ -169,10 +169,7 @@ export class Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAutoSavedPolicyPath(): string {
|
getAutoSavedPolicyPath(): string {
|
||||||
return path.join(
|
return path.join(Storage.getUserPoliciesDir(), AUTO_SAVED_POLICY_FILENAME);
|
||||||
this.getWorkspacePoliciesDir(),
|
|
||||||
AUTO_SAVED_POLICY_FILENAME,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureProjectTempDirExists(): void {
|
ensureProjectTempDirExists(): void {
|
||||||
|
|||||||
@@ -516,9 +516,8 @@ export function createPolicyUpdater(
|
|||||||
if (message.persist) {
|
if (message.persist) {
|
||||||
persistenceQueue = persistenceQueue.then(async () => {
|
persistenceQueue = persistenceQueue.then(async () => {
|
||||||
try {
|
try {
|
||||||
const workspacePoliciesDir = storage.getWorkspacePoliciesDir();
|
|
||||||
await fs.mkdir(workspacePoliciesDir, { recursive: true });
|
|
||||||
const policyFile = storage.getAutoSavedPolicyPath();
|
const policyFile = storage.getAutoSavedPolicyPath();
|
||||||
|
await fs.mkdir(path.dirname(policyFile), { recursive: true });
|
||||||
|
|
||||||
// Read existing file
|
// Read existing file
|
||||||
let existingData: { rule?: TomlRule[] } = {};
|
let existingData: { rule?: TomlRule[] } = {};
|
||||||
|
|||||||
@@ -48,14 +48,8 @@ describe('createPolicyUpdater', () => {
|
|||||||
it('should persist policy when persist flag is true', async () => {
|
it('should persist policy when persist flag is true', async () => {
|
||||||
createPolicyUpdater(policyEngine, messageBus, mockStorage);
|
createPolicyUpdater(policyEngine, messageBus, mockStorage);
|
||||||
|
|
||||||
const workspacePoliciesDir = '/mock/project/.gemini/policies';
|
const userPoliciesDir = '/mock/user/.gemini/policies';
|
||||||
const policyFile = path.join(
|
const policyFile = path.join(userPoliciesDir, AUTO_SAVED_POLICY_FILENAME);
|
||||||
workspacePoliciesDir,
|
|
||||||
AUTO_SAVED_POLICY_FILENAME,
|
|
||||||
);
|
|
||||||
vi.spyOn(mockStorage, 'getWorkspacePoliciesDir').mockReturnValue(
|
|
||||||
workspacePoliciesDir,
|
|
||||||
);
|
|
||||||
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
|
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
|
||||||
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
|
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
|
||||||
(fs.readFile as unknown as Mock).mockRejectedValue(
|
(fs.readFile as unknown as Mock).mockRejectedValue(
|
||||||
@@ -79,8 +73,7 @@ describe('createPolicyUpdater', () => {
|
|||||||
// Wait for async operations (microtasks)
|
// Wait for async operations (microtasks)
|
||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
|
||||||
expect(mockStorage.getWorkspacePoliciesDir).toHaveBeenCalled();
|
expect(fs.mkdir).toHaveBeenCalledWith(userPoliciesDir, {
|
||||||
expect(fs.mkdir).toHaveBeenCalledWith(workspacePoliciesDir, {
|
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,14 +108,8 @@ describe('createPolicyUpdater', () => {
|
|||||||
it('should persist policy with commandPrefix when provided', async () => {
|
it('should persist policy with commandPrefix when provided', async () => {
|
||||||
createPolicyUpdater(policyEngine, messageBus, mockStorage);
|
createPolicyUpdater(policyEngine, messageBus, mockStorage);
|
||||||
|
|
||||||
const workspacePoliciesDir = '/mock/project/.gemini/policies';
|
const userPoliciesDir = '/mock/user/.gemini/policies';
|
||||||
const policyFile = path.join(
|
const policyFile = path.join(userPoliciesDir, AUTO_SAVED_POLICY_FILENAME);
|
||||||
workspacePoliciesDir,
|
|
||||||
AUTO_SAVED_POLICY_FILENAME,
|
|
||||||
);
|
|
||||||
vi.spyOn(mockStorage, 'getWorkspacePoliciesDir').mockReturnValue(
|
|
||||||
workspacePoliciesDir,
|
|
||||||
);
|
|
||||||
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
|
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
|
||||||
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
|
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
|
||||||
(fs.readFile as unknown as Mock).mockRejectedValue(
|
(fs.readFile as unknown as Mock).mockRejectedValue(
|
||||||
@@ -168,14 +155,8 @@ describe('createPolicyUpdater', () => {
|
|||||||
it('should persist policy with mcpName and toolName when provided', async () => {
|
it('should persist policy with mcpName and toolName when provided', async () => {
|
||||||
createPolicyUpdater(policyEngine, messageBus, mockStorage);
|
createPolicyUpdater(policyEngine, messageBus, mockStorage);
|
||||||
|
|
||||||
const workspacePoliciesDir = '/mock/project/.gemini/policies';
|
const userPoliciesDir = '/mock/user/.gemini/policies';
|
||||||
const policyFile = path.join(
|
const policyFile = path.join(userPoliciesDir, AUTO_SAVED_POLICY_FILENAME);
|
||||||
workspacePoliciesDir,
|
|
||||||
AUTO_SAVED_POLICY_FILENAME,
|
|
||||||
);
|
|
||||||
vi.spyOn(mockStorage, 'getWorkspacePoliciesDir').mockReturnValue(
|
|
||||||
workspacePoliciesDir,
|
|
||||||
);
|
|
||||||
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
|
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
|
||||||
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
|
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
|
||||||
(fs.readFile as unknown as Mock).mockRejectedValue(
|
(fs.readFile as unknown as Mock).mockRejectedValue(
|
||||||
@@ -214,14 +195,8 @@ describe('createPolicyUpdater', () => {
|
|||||||
it('should escape special characters in toolName and mcpName', async () => {
|
it('should escape special characters in toolName and mcpName', async () => {
|
||||||
createPolicyUpdater(policyEngine, messageBus, mockStorage);
|
createPolicyUpdater(policyEngine, messageBus, mockStorage);
|
||||||
|
|
||||||
const workspacePoliciesDir = '/mock/project/.gemini/policies';
|
const userPoliciesDir = '/mock/user/.gemini/policies';
|
||||||
const policyFile = path.join(
|
const policyFile = path.join(userPoliciesDir, AUTO_SAVED_POLICY_FILENAME);
|
||||||
workspacePoliciesDir,
|
|
||||||
AUTO_SAVED_POLICY_FILENAME,
|
|
||||||
);
|
|
||||||
vi.spyOn(mockStorage, 'getWorkspacePoliciesDir').mockReturnValue(
|
|
||||||
workspacePoliciesDir,
|
|
||||||
);
|
|
||||||
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
|
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
|
||||||
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
|
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
|
||||||
(fs.readFile as unknown as Mock).mockRejectedValue(
|
(fs.readFile as unknown as Mock).mockRejectedValue(
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ describe('createPolicyUpdater', () => {
|
|||||||
|
|
||||||
messageBus = new MessageBus(policyEngine);
|
messageBus = new MessageBus(policyEngine);
|
||||||
mockStorage = new Storage('/mock/project');
|
mockStorage = new Storage('/mock/project');
|
||||||
vi.spyOn(mockStorage, 'getWorkspacePoliciesDir').mockReturnValue(
|
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(
|
||||||
'/mock/project/.gemini/policies',
|
'/mock/user/.gemini/policies/auto-saved.toml',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user