mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-12 06:10:42 -07:00
Add Folder Trust Support To Hooks (#15325)
This commit is contained in:
@@ -6,9 +6,9 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import * as fs from 'node:fs';
|
||||
import { HookRegistry, ConfigSource } from './hookRegistry.js';
|
||||
import { HookRegistry } from './hookRegistry.js';
|
||||
import type { Storage } from '../config/storage.js';
|
||||
import { HookEventName, HookType } from './types.js';
|
||||
import { ConfigSource, HookEventName, HookType } from './types.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import type { HookDefinition } from './types.js';
|
||||
|
||||
@@ -47,6 +47,7 @@ describe('HookRegistry', () => {
|
||||
getExtensions: vi.fn().mockReturnValue([]),
|
||||
getHooks: vi.fn().mockReturnValue({}),
|
||||
getDisabledHooks: vi.fn().mockReturnValue([]),
|
||||
isTrustedFolder: vi.fn().mockReturnValue(true),
|
||||
} as unknown as Config;
|
||||
|
||||
hookRegistry = new HookRegistry(mockConfig);
|
||||
@@ -68,6 +69,35 @@ describe('HookRegistry', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not load hooks if folder is not trusted', async () => {
|
||||
vi.mocked(mockConfig.isTrustedFolder).mockReturnValue(false);
|
||||
const mockHooksConfig = {
|
||||
BeforeTool: [
|
||||
{
|
||||
hooks: [
|
||||
{
|
||||
type: 'command',
|
||||
command: './hooks/test.sh',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
vi.mocked(mockConfig.getHooks).mockReturnValue(
|
||||
mockHooksConfig as unknown as {
|
||||
[K in HookEventName]?: HookDefinition[];
|
||||
},
|
||||
);
|
||||
|
||||
await hookRegistry.initialize();
|
||||
|
||||
expect(hookRegistry.getAllHooks()).toHaveLength(0);
|
||||
expect(mockDebugLogger.warn).toHaveBeenCalledWith(
|
||||
'Project hooks disabled because the folder is not trusted.',
|
||||
);
|
||||
});
|
||||
|
||||
it('should load hooks from project configuration', async () => {
|
||||
const mockHooksConfig = {
|
||||
BeforeTool: [
|
||||
|
||||
Reference in New Issue
Block a user