feat(hooks): add support for friendly names and descriptions (#15174)

This commit is contained in:
Abhi
2025-12-18 11:09:24 -05:00
committed by GitHub
parent b919bb14cd
commit 464beedce2
14 changed files with 300 additions and 17 deletions
@@ -282,6 +282,71 @@ describe('HookPlanner', () => {
);
});
it('should deduplicate based on both name and command', () => {
const mockEntries: HookRegistryEntry[] = [
{
config: {
name: 'hook1',
type: HookType.Command,
command: './same.sh',
},
source: ConfigSource.Project,
eventName: HookEventName.BeforeTool,
enabled: true,
},
{
config: {
name: 'hook1',
type: HookType.Command,
command: './same.sh',
},
source: ConfigSource.User,
eventName: HookEventName.BeforeTool,
enabled: true,
}, // Same name, same command -> deduplicate
{
config: {
name: 'hook2',
type: HookType.Command,
command: './same.sh',
},
source: ConfigSource.Project,
eventName: HookEventName.BeforeTool,
enabled: true,
}, // Different name, same command -> distinct
{
config: {
name: 'hook1',
type: HookType.Command,
command: './different.sh',
},
source: ConfigSource.Project,
eventName: HookEventName.BeforeTool,
enabled: true,
}, // Same name, different command -> distinct
{
config: { type: HookType.Command, command: './no-name.sh' },
source: ConfigSource.Project,
eventName: HookEventName.BeforeTool,
enabled: true,
},
{
config: { type: HookType.Command, command: './no-name.sh' },
source: ConfigSource.User,
eventName: HookEventName.BeforeTool,
enabled: true,
}, // No name, same command -> deduplicate
];
vi.mocked(mockHookRegistry.getHooksForEvent).mockReturnValue(mockEntries);
const plan = hookPlanner.createExecutionPlan(HookEventName.BeforeTool);
expect(plan).not.toBeNull();
// hook1:same.sh (deduped), hook2:same.sh, hook1:different.sh, :no-name.sh (deduped)
expect(plan!.hookConfigs).toHaveLength(4);
});
it('should match trigger for session events', () => {
const mockEntries: HookRegistryEntry[] = [
{