mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 13:53:02 -07:00
feat(policy): support auto-add to policy by default and scoped persistence
This commit is contained in:
@@ -536,15 +536,6 @@ export function createPolicyUpdater(
|
||||
: storage.getAutoSavedPolicyPath();
|
||||
await fs.mkdir(path.dirname(policyFile), { recursive: true });
|
||||
|
||||
// Backup existing file if it exists
|
||||
try {
|
||||
await fs.copyFile(policyFile, `${policyFile}.bak`);
|
||||
} catch (error) {
|
||||
if (!isNodeError(error) || error.code !== 'ENOENT') {
|
||||
debugLogger.warn(`Failed to backup ${policyFile}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Read existing file
|
||||
let existingData: { rule?: TomlRule[] } = {};
|
||||
try {
|
||||
|
||||
@@ -284,33 +284,4 @@ describe('createPolicyUpdater', () => {
|
||||
policyFile,
|
||||
);
|
||||
});
|
||||
|
||||
it('should backup existing policy file before writing', async () => {
|
||||
createPolicyUpdater(policyEngine, messageBus, mockStorage);
|
||||
|
||||
const policyFile = '/mock/user/.gemini/policies/auto-saved.toml';
|
||||
vi.spyOn(mockStorage, 'getAutoSavedPolicyPath').mockReturnValue(policyFile);
|
||||
(fs.mkdir as unknown as Mock).mockResolvedValue(undefined);
|
||||
(fs.readFile as unknown as Mock).mockResolvedValue(
|
||||
'[[rule]]\ntoolName = "existing"',
|
||||
);
|
||||
(fs.copyFile as unknown as Mock).mockResolvedValue(undefined);
|
||||
|
||||
const mockFileHandle = {
|
||||
writeFile: vi.fn().mockResolvedValue(undefined),
|
||||
close: vi.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
(fs.open as unknown as Mock).mockResolvedValue(mockFileHandle);
|
||||
(fs.rename as unknown as Mock).mockResolvedValue(undefined);
|
||||
|
||||
await messageBus.publish({
|
||||
type: MessageBusType.UPDATE_POLICY,
|
||||
toolName: 'new_tool',
|
||||
persist: true,
|
||||
});
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
expect(fs.copyFile).toHaveBeenCalledWith(policyFile, `${policyFile}.bak`);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user