claude-flow 3.56.6 → 3.56.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/helpers/auto-memory-hook.mjs +109 -10
- package/.claude/helpers/intelligence.cjs +57 -4
- package/README.md +9 -3
- package/node_modules/@claude-flow/codex/README.md +20 -3
- package/node_modules/@claude-flow/codex/dist/cli.js +7 -0
- package/node_modules/@claude-flow/codex/dist/cli.js.map +1 -1
- package/node_modules/@claude-flow/codex/dist/index.d.ts +3 -3
- package/node_modules/@claude-flow/codex/dist/index.js +1 -1
- package/node_modules/@claude-flow/codex/dist/initializer.d.ts +8 -3
- package/node_modules/@claude-flow/codex/dist/initializer.d.ts.map +1 -1
- package/node_modules/@claude-flow/codex/dist/initializer.js +75 -13
- package/node_modules/@claude-flow/codex/dist/initializer.js.map +1 -1
- package/node_modules/@claude-flow/codex/dist/types.d.ts +8 -0
- package/node_modules/@claude-flow/codex/dist/types.d.ts.map +1 -1
- package/node_modules/@claude-flow/codex/package.json +1 -1
- package/package.json +6 -3
- package/v3/@claude-flow/cli/bin/cli.js +11 -1
- package/v3/@claude-flow/cli/bin/mcp-server.js +11 -1
- package/v3/@claude-flow/cli/dist/src/commands/coverage-reader.d.ts +29 -0
- package/v3/@claude-flow/cli/dist/src/commands/coverage-reader.js +247 -0
- package/v3/@claude-flow/cli/dist/src/commands/doctor-native-addon.d.ts +23 -0
- package/v3/@claude-flow/cli/dist/src/commands/doctor-native-addon.js +135 -0
- package/v3/@claude-flow/cli/dist/src/commands/doctor.js +3 -0
- package/v3/@claude-flow/cli/dist/src/commands/hooks.js +17 -181
- package/v3/@claude-flow/cli/dist/src/commands/index.js +2 -0
- package/v3/@claude-flow/cli/dist/src/commands/init.d.ts +2 -0
- package/v3/@claude-flow/cli/dist/src/commands/init.js +37 -5
- package/v3/@claude-flow/cli/dist/src/commands/mods.d.ts +3 -0
- package/v3/@claude-flow/cli/dist/src/commands/mods.js +19 -5
- package/v3/@claude-flow/cli/dist/src/commands/tui.d.ts +12 -0
- package/v3/@claude-flow/cli/dist/src/commands/tui.js +98 -0
- package/v3/@claude-flow/cli/dist/src/fs-secure.d.ts +25 -0
- package/v3/@claude-flow/cli/dist/src/fs-secure.js +51 -2
- package/v3/@claude-flow/cli/dist/src/init/executor.js +11 -14
- package/v3/@claude-flow/cli/dist/src/init/helper-commands.d.ts +2 -0
- package/v3/@claude-flow/cli/dist/src/init/helper-commands.js +2 -0
- package/v3/@claude-flow/cli/dist/src/init/helpers-generator.js +4 -1
- package/v3/@claude-flow/cli/dist/src/init/settings-generator.js +3 -3
- package/v3/@claude-flow/cli/dist/src/mcp-server.js +10 -2
- package/v3/@claude-flow/cli/dist/src/mcp-tools/capability-brain.d.ts +1 -1
- package/v3/@claude-flow/cli/dist/src/mcp-tools/capability-brain.js +1 -1
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +26 -4
- package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +2 -1
- package/v3/@claude-flow/cli/dist/src/memory/live-memory-row.d.ts +3 -1
- package/v3/@claude-flow/cli/dist/src/memory/live-memory-row.js +3 -1
- package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.d.ts +4 -0
- package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +3 -2
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.d.ts +4 -0
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +12 -11
- package/v3/@claude-flow/cli/dist/src/mods/claude-installs.js +7 -3
- package/v3/@claude-flow/cli/dist/src/mods/install.js +32 -12
- package/v3/@claude-flow/cli/dist/src/mods/plugin-resolve.js +3 -1
- package/v3/@claude-flow/cli/dist/src/mods/probe.js +92 -4
- package/v3/@claude-flow/cli/dist/src/services/command-recording.d.ts +17 -0
- package/v3/@claude-flow/cli/dist/src/services/command-recording.js +91 -0
- package/v3/@claude-flow/cli/dist/src/services/policy-ledger-anchor.js +20 -2
- package/v3/@claude-flow/cli/package.json +3 -3
- package/v3/@claude-flow/shared/dist/events/rvf-event-log.d.ts +9 -0
- package/v3/@claude-flow/shared/dist/events/rvf-event-log.js +44 -3
- package/v3/@claude-flow/shared/dist/mcp/transport/http.js +11 -1
- package/v3/@claude-flow/shared/package.json +12 -9
- package/v3/@claude-flow/shared/dist/events/event-store-pagination.test.d.ts +0 -2
- package/v3/@claude-flow/shared/dist/events/event-store-pagination.test.js +0 -32
- package/v3/@claude-flow/shared/dist/events/event-store.test.d.ts +0 -8
- package/v3/@claude-flow/shared/dist/events/event-store.test.js +0 -313
- package/v3/@claude-flow/shared/dist/hooks/hooks.test.d.ts +0 -9
- package/v3/@claude-flow/shared/dist/hooks/hooks.test.js +0 -322
- package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +0 -9
- package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.js +0 -93
- package/v3/@claude-flow/shared/dist/resilience/bulkhead-sync-throw.test.d.ts +0 -2
- package/v3/@claude-flow/shared/dist/resilience/bulkhead-sync-throw.test.js +0 -33
- package/v3/@claude-flow/shared/dist/resilience/retry-timeout-cleanup.test.d.ts +0 -2
- package/v3/@claude-flow/shared/dist/resilience/retry-timeout-cleanup.test.js +0 -38
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* V3 Hooks System - Tests
|
|
3
|
-
*
|
|
4
|
-
* Comprehensive tests for hook registry and executor.
|
|
5
|
-
*
|
|
6
|
-
* @module v3/shared/hooks/hooks.test
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
9
|
-
import { createHookRegistry } from './registry.js';
|
|
10
|
-
import { createHookExecutor } from './executor.js';
|
|
11
|
-
import { HookEvent, HookPriority } from './types.js';
|
|
12
|
-
import { createEventBus } from '../core/event-bus.js';
|
|
13
|
-
describe('HookRegistry', () => {
|
|
14
|
-
let registry;
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
registry = createHookRegistry();
|
|
17
|
-
});
|
|
18
|
-
it('should register a hook', () => {
|
|
19
|
-
const handler = vi.fn();
|
|
20
|
-
const id = registry.register(HookEvent.PreToolUse, handler);
|
|
21
|
-
expect(id).toBeDefined();
|
|
22
|
-
expect(registry.has(id)).toBe(true);
|
|
23
|
-
expect(registry.count()).toBe(1);
|
|
24
|
-
});
|
|
25
|
-
it('should unregister a hook', () => {
|
|
26
|
-
const handler = vi.fn();
|
|
27
|
-
const id = registry.register(HookEvent.PreToolUse, handler);
|
|
28
|
-
const result = registry.unregister(id);
|
|
29
|
-
expect(result).toBe(true);
|
|
30
|
-
expect(registry.has(id)).toBe(false);
|
|
31
|
-
expect(registry.count()).toBe(0);
|
|
32
|
-
});
|
|
33
|
-
it('should return false when unregistering non-existent hook', () => {
|
|
34
|
-
const result = registry.unregister('non-existent');
|
|
35
|
-
expect(result).toBe(false);
|
|
36
|
-
});
|
|
37
|
-
it('should get handlers sorted by priority', () => {
|
|
38
|
-
const handler1 = vi.fn();
|
|
39
|
-
const handler2 = vi.fn();
|
|
40
|
-
const handler3 = vi.fn();
|
|
41
|
-
registry.register(HookEvent.PreToolUse, handler1, HookPriority.Normal);
|
|
42
|
-
registry.register(HookEvent.PreToolUse, handler2, HookPriority.High);
|
|
43
|
-
registry.register(HookEvent.PreToolUse, handler3, HookPriority.Low);
|
|
44
|
-
const handlers = registry.getHandlers(HookEvent.PreToolUse);
|
|
45
|
-
expect(handlers).toHaveLength(3);
|
|
46
|
-
expect(handlers[0].handler).toBe(handler2); // High priority first
|
|
47
|
-
expect(handlers[1].handler).toBe(handler1); // Normal priority second
|
|
48
|
-
expect(handlers[2].handler).toBe(handler3); // Low priority last
|
|
49
|
-
});
|
|
50
|
-
it('should filter disabled hooks', () => {
|
|
51
|
-
const handler = vi.fn();
|
|
52
|
-
const id = registry.register(HookEvent.PreToolUse, handler, HookPriority.Normal, {
|
|
53
|
-
enabled: false,
|
|
54
|
-
});
|
|
55
|
-
const handlers = registry.getHandlers(HookEvent.PreToolUse);
|
|
56
|
-
const allHandlers = registry.getHandlers(HookEvent.PreToolUse, true);
|
|
57
|
-
expect(handlers).toHaveLength(0);
|
|
58
|
-
expect(allHandlers).toHaveLength(1);
|
|
59
|
-
});
|
|
60
|
-
it('should enable and disable hooks', () => {
|
|
61
|
-
const handler = vi.fn();
|
|
62
|
-
const id = registry.register(HookEvent.PreToolUse, handler);
|
|
63
|
-
registry.disable(id);
|
|
64
|
-
expect(registry.getHandlers(HookEvent.PreToolUse)).toHaveLength(0);
|
|
65
|
-
registry.enable(id);
|
|
66
|
-
expect(registry.getHandlers(HookEvent.PreToolUse)).toHaveLength(1);
|
|
67
|
-
});
|
|
68
|
-
it('should list hooks with filters', () => {
|
|
69
|
-
registry.register(HookEvent.PreToolUse, vi.fn(), HookPriority.High);
|
|
70
|
-
registry.register(HookEvent.PostToolUse, vi.fn(), HookPriority.Normal);
|
|
71
|
-
registry.register(HookEvent.PreEdit, vi.fn(), HookPriority.Low);
|
|
72
|
-
const allHooks = registry.listHooks();
|
|
73
|
-
expect(allHooks).toHaveLength(3);
|
|
74
|
-
const preToolHooks = registry.listHooks({ event: HookEvent.PreToolUse });
|
|
75
|
-
expect(preToolHooks).toHaveLength(1);
|
|
76
|
-
const highPriorityHooks = registry.listHooks({ minPriority: HookPriority.Normal });
|
|
77
|
-
expect(highPriorityHooks).toHaveLength(2);
|
|
78
|
-
});
|
|
79
|
-
it('should get event types', () => {
|
|
80
|
-
registry.register(HookEvent.PreToolUse, vi.fn());
|
|
81
|
-
registry.register(HookEvent.PostToolUse, vi.fn());
|
|
82
|
-
registry.register(HookEvent.PreEdit, vi.fn());
|
|
83
|
-
const eventTypes = registry.getEventTypes();
|
|
84
|
-
expect(eventTypes).toContain(HookEvent.PreToolUse);
|
|
85
|
-
expect(eventTypes).toContain(HookEvent.PostToolUse);
|
|
86
|
-
expect(eventTypes).toContain(HookEvent.PreEdit);
|
|
87
|
-
});
|
|
88
|
-
it('should track statistics', () => {
|
|
89
|
-
registry.register(HookEvent.PreToolUse, vi.fn());
|
|
90
|
-
registry.register(HookEvent.PostToolUse, vi.fn());
|
|
91
|
-
registry.recordExecution(true, 10);
|
|
92
|
-
registry.recordExecution(true, 20);
|
|
93
|
-
registry.recordExecution(false, 5);
|
|
94
|
-
const stats = registry.getStats();
|
|
95
|
-
expect(stats.totalHooks).toBe(2);
|
|
96
|
-
expect(stats.totalExecutions).toBe(3);
|
|
97
|
-
expect(stats.totalFailures).toBe(1);
|
|
98
|
-
expect(stats.avgExecutionTime).toBe((10 + 20 + 5) / 3);
|
|
99
|
-
});
|
|
100
|
-
it('should reset statistics', () => {
|
|
101
|
-
registry.recordExecution(true, 10);
|
|
102
|
-
registry.resetStats();
|
|
103
|
-
const stats = registry.getStats();
|
|
104
|
-
expect(stats.totalExecutions).toBe(0);
|
|
105
|
-
expect(stats.totalFailures).toBe(0);
|
|
106
|
-
});
|
|
107
|
-
it('should clear all hooks', () => {
|
|
108
|
-
registry.register(HookEvent.PreToolUse, vi.fn());
|
|
109
|
-
registry.register(HookEvent.PostToolUse, vi.fn());
|
|
110
|
-
registry.clear();
|
|
111
|
-
expect(registry.count()).toBe(0);
|
|
112
|
-
expect(registry.getEventTypes()).toHaveLength(0);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe('HookExecutor', () => {
|
|
116
|
-
let registry;
|
|
117
|
-
let executor;
|
|
118
|
-
let eventBus;
|
|
119
|
-
beforeEach(() => {
|
|
120
|
-
registry = createHookRegistry();
|
|
121
|
-
eventBus = createEventBus();
|
|
122
|
-
executor = createHookExecutor(registry, eventBus);
|
|
123
|
-
});
|
|
124
|
-
it('should execute single hook successfully', async () => {
|
|
125
|
-
const handler = vi.fn(async () => ({ success: true }));
|
|
126
|
-
registry.register(HookEvent.PreToolUse, handler);
|
|
127
|
-
const context = {
|
|
128
|
-
event: HookEvent.PreToolUse,
|
|
129
|
-
timestamp: new Date(),
|
|
130
|
-
tool: { name: 'Read', parameters: { path: 'file.ts' } },
|
|
131
|
-
};
|
|
132
|
-
const result = await executor.execute(HookEvent.PreToolUse, context);
|
|
133
|
-
expect(result.success).toBe(true);
|
|
134
|
-
expect(result.hooksExecuted).toBe(1);
|
|
135
|
-
expect(result.hooksFailed).toBe(0);
|
|
136
|
-
expect(handler).toHaveBeenCalledWith(context);
|
|
137
|
-
});
|
|
138
|
-
it('should execute multiple hooks in priority order', async () => {
|
|
139
|
-
const executionOrder = [];
|
|
140
|
-
const handler1 = vi.fn(async () => {
|
|
141
|
-
executionOrder.push(1);
|
|
142
|
-
return { success: true };
|
|
143
|
-
});
|
|
144
|
-
const handler2 = vi.fn(async () => {
|
|
145
|
-
executionOrder.push(2);
|
|
146
|
-
return { success: true };
|
|
147
|
-
});
|
|
148
|
-
const handler3 = vi.fn(async () => {
|
|
149
|
-
executionOrder.push(3);
|
|
150
|
-
return { success: true };
|
|
151
|
-
});
|
|
152
|
-
registry.register(HookEvent.PreToolUse, handler1, HookPriority.Normal);
|
|
153
|
-
registry.register(HookEvent.PreToolUse, handler2, HookPriority.High);
|
|
154
|
-
registry.register(HookEvent.PreToolUse, handler3, HookPriority.Low);
|
|
155
|
-
const context = {
|
|
156
|
-
event: HookEvent.PreToolUse,
|
|
157
|
-
timestamp: new Date(),
|
|
158
|
-
};
|
|
159
|
-
await executor.execute(HookEvent.PreToolUse, context);
|
|
160
|
-
expect(executionOrder).toEqual([2, 1, 3]); // High, Normal, Low
|
|
161
|
-
});
|
|
162
|
-
it('should handle hook errors gracefully', async () => {
|
|
163
|
-
const handler1 = vi.fn(async () => ({ success: true }));
|
|
164
|
-
const handler2 = vi.fn(async () => {
|
|
165
|
-
throw new Error('Hook failed');
|
|
166
|
-
});
|
|
167
|
-
const handler3 = vi.fn(async () => ({ success: true }));
|
|
168
|
-
registry.register(HookEvent.PreToolUse, handler1, HookPriority.High);
|
|
169
|
-
registry.register(HookEvent.PreToolUse, handler2, HookPriority.Normal);
|
|
170
|
-
registry.register(HookEvent.PreToolUse, handler3, HookPriority.Low);
|
|
171
|
-
const context = {
|
|
172
|
-
event: HookEvent.PreToolUse,
|
|
173
|
-
timestamp: new Date(),
|
|
174
|
-
};
|
|
175
|
-
const result = await executor.execute(HookEvent.PreToolUse, context, {
|
|
176
|
-
continueOnError: true,
|
|
177
|
-
});
|
|
178
|
-
expect(result.hooksExecuted).toBe(3);
|
|
179
|
-
expect(result.hooksFailed).toBe(1);
|
|
180
|
-
expect(handler3).toHaveBeenCalled(); // Should continue despite error
|
|
181
|
-
});
|
|
182
|
-
it('should abort on error when continueOnError is false', async () => {
|
|
183
|
-
const handler1 = vi.fn(async () => ({ success: true }));
|
|
184
|
-
const handler2 = vi.fn(async () => {
|
|
185
|
-
throw new Error('Hook failed');
|
|
186
|
-
});
|
|
187
|
-
const handler3 = vi.fn(async () => ({ success: true }));
|
|
188
|
-
registry.register(HookEvent.PreToolUse, handler1, HookPriority.High);
|
|
189
|
-
registry.register(HookEvent.PreToolUse, handler2, HookPriority.Normal);
|
|
190
|
-
registry.register(HookEvent.PreToolUse, handler3, HookPriority.Low);
|
|
191
|
-
const context = {
|
|
192
|
-
event: HookEvent.PreToolUse,
|
|
193
|
-
timestamp: new Date(),
|
|
194
|
-
};
|
|
195
|
-
const result = await executor.execute(HookEvent.PreToolUse, context);
|
|
196
|
-
expect(result.aborted).toBe(true);
|
|
197
|
-
expect(result.hooksExecuted).toBe(2);
|
|
198
|
-
expect(handler3).not.toHaveBeenCalled(); // Should not execute after error
|
|
199
|
-
});
|
|
200
|
-
it('should abort when hook returns abort flag', async () => {
|
|
201
|
-
const handler1 = vi.fn(async () => ({ success: true }));
|
|
202
|
-
const handler2 = vi.fn(async () => ({ success: true, abort: true }));
|
|
203
|
-
const handler3 = vi.fn(async () => ({ success: true }));
|
|
204
|
-
registry.register(HookEvent.PreToolUse, handler1, HookPriority.High);
|
|
205
|
-
registry.register(HookEvent.PreToolUse, handler2, HookPriority.Normal);
|
|
206
|
-
registry.register(HookEvent.PreToolUse, handler3, HookPriority.Low);
|
|
207
|
-
const context = {
|
|
208
|
-
event: HookEvent.PreToolUse,
|
|
209
|
-
timestamp: new Date(),
|
|
210
|
-
};
|
|
211
|
-
const result = await executor.execute(HookEvent.PreToolUse, context);
|
|
212
|
-
expect(result.aborted).toBe(true);
|
|
213
|
-
expect(result.hooksExecuted).toBe(2);
|
|
214
|
-
expect(handler3).not.toHaveBeenCalled();
|
|
215
|
-
});
|
|
216
|
-
it('should merge context modifications', async () => {
|
|
217
|
-
const handler1 = vi.fn(async () => ({
|
|
218
|
-
success: true,
|
|
219
|
-
data: { metadata: { modified: true } },
|
|
220
|
-
}));
|
|
221
|
-
const handler2 = vi.fn(async (context) => {
|
|
222
|
-
expect(context.metadata?.modified).toBe(true);
|
|
223
|
-
return { success: true };
|
|
224
|
-
});
|
|
225
|
-
registry.register(HookEvent.PreToolUse, handler1, HookPriority.High);
|
|
226
|
-
registry.register(HookEvent.PreToolUse, handler2, HookPriority.Normal);
|
|
227
|
-
const context = {
|
|
228
|
-
event: HookEvent.PreToolUse,
|
|
229
|
-
timestamp: new Date(),
|
|
230
|
-
};
|
|
231
|
-
const result = await executor.execute(HookEvent.PreToolUse, context);
|
|
232
|
-
expect(result.finalContext?.metadata).toEqual({ modified: true });
|
|
233
|
-
});
|
|
234
|
-
it('should handle timeout', async () => {
|
|
235
|
-
const handler = vi.fn(async () => {
|
|
236
|
-
await new Promise(resolve => setTimeout(resolve, 200));
|
|
237
|
-
return { success: true };
|
|
238
|
-
});
|
|
239
|
-
registry.register(HookEvent.PreToolUse, handler);
|
|
240
|
-
const context = {
|
|
241
|
-
event: HookEvent.PreToolUse,
|
|
242
|
-
timestamp: new Date(),
|
|
243
|
-
};
|
|
244
|
-
const result = await executor.executeWithTimeout(HookEvent.PreToolUse, context, 100);
|
|
245
|
-
expect(result.success).toBe(false);
|
|
246
|
-
expect(result.hooksFailed).toBe(1);
|
|
247
|
-
});
|
|
248
|
-
it('should execute hooks in parallel', async () => {
|
|
249
|
-
const handler1 = vi.fn(async () => ({ success: true }));
|
|
250
|
-
const handler2 = vi.fn(async () => ({ success: true }));
|
|
251
|
-
registry.register(HookEvent.PreToolUse, handler1);
|
|
252
|
-
registry.register(HookEvent.PostToolUse, handler2);
|
|
253
|
-
const contexts = [
|
|
254
|
-
{ event: HookEvent.PreToolUse, timestamp: new Date() },
|
|
255
|
-
{ event: HookEvent.PostToolUse, timestamp: new Date() },
|
|
256
|
-
];
|
|
257
|
-
const results = await executor.executeParallel([HookEvent.PreToolUse, HookEvent.PostToolUse], contexts);
|
|
258
|
-
expect(results).toHaveLength(2);
|
|
259
|
-
expect(results[0].success).toBe(true);
|
|
260
|
-
expect(results[1].success).toBe(true);
|
|
261
|
-
});
|
|
262
|
-
it('should execute hooks sequentially with context chaining', async () => {
|
|
263
|
-
const handler1 = vi.fn(async () => ({
|
|
264
|
-
success: true,
|
|
265
|
-
data: { metadata: { step: 1 } },
|
|
266
|
-
}));
|
|
267
|
-
const handler2 = vi.fn(async () => ({
|
|
268
|
-
success: true,
|
|
269
|
-
data: { metadata: { step: 2 } },
|
|
270
|
-
}));
|
|
271
|
-
registry.register(HookEvent.PreToolUse, handler1);
|
|
272
|
-
registry.register(HookEvent.PostToolUse, handler2);
|
|
273
|
-
const initialContext = {
|
|
274
|
-
event: HookEvent.PreToolUse,
|
|
275
|
-
timestamp: new Date(),
|
|
276
|
-
};
|
|
277
|
-
const result = await executor.executeSequential([HookEvent.PreToolUse, HookEvent.PostToolUse], initialContext);
|
|
278
|
-
expect(result.success).toBe(true);
|
|
279
|
-
expect(result.hooksExecuted).toBe(2);
|
|
280
|
-
});
|
|
281
|
-
it('should emit events to event bus', async () => {
|
|
282
|
-
const preExecuteHandler = vi.fn();
|
|
283
|
-
const postExecuteHandler = vi.fn();
|
|
284
|
-
eventBus.on('hooks:pre-execute', preExecuteHandler);
|
|
285
|
-
eventBus.on('hooks:post-execute', postExecuteHandler);
|
|
286
|
-
const handler = vi.fn(async () => ({ success: true }));
|
|
287
|
-
registry.register(HookEvent.PreToolUse, handler);
|
|
288
|
-
const context = {
|
|
289
|
-
event: HookEvent.PreToolUse,
|
|
290
|
-
timestamp: new Date(),
|
|
291
|
-
};
|
|
292
|
-
await executor.execute(HookEvent.PreToolUse, context);
|
|
293
|
-
expect(preExecuteHandler).toHaveBeenCalled();
|
|
294
|
-
expect(postExecuteHandler).toHaveBeenCalled();
|
|
295
|
-
});
|
|
296
|
-
it('should skip disabled hooks', async () => {
|
|
297
|
-
const handler = vi.fn(async () => ({ success: true }));
|
|
298
|
-
const id = registry.register(HookEvent.PreToolUse, handler, HookPriority.Normal, {
|
|
299
|
-
enabled: false,
|
|
300
|
-
});
|
|
301
|
-
const context = {
|
|
302
|
-
event: HookEvent.PreToolUse,
|
|
303
|
-
timestamp: new Date(),
|
|
304
|
-
};
|
|
305
|
-
const result = await executor.execute(HookEvent.PreToolUse, context);
|
|
306
|
-
expect(result.hooksExecuted).toBe(0);
|
|
307
|
-
expect(handler).not.toHaveBeenCalled();
|
|
308
|
-
});
|
|
309
|
-
it('should record execution statistics', async () => {
|
|
310
|
-
const handler = vi.fn(async () => ({ success: true }));
|
|
311
|
-
registry.register(HookEvent.PreToolUse, handler);
|
|
312
|
-
const context = {
|
|
313
|
-
event: HookEvent.PreToolUse,
|
|
314
|
-
timestamp: new Date(),
|
|
315
|
-
};
|
|
316
|
-
await executor.execute(HookEvent.PreToolUse, context);
|
|
317
|
-
const stats = registry.getStats();
|
|
318
|
-
expect(stats.totalExecutions).toBe(1);
|
|
319
|
-
expect(stats.totalFailures).toBe(0);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
//# sourceMappingURL=hooks.test.js.map
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* V3 Hooks System - Export Verification
|
|
3
|
-
*
|
|
4
|
-
* Verifies that all exports are accessible through the public API.
|
|
5
|
-
*
|
|
6
|
-
* @module v3/shared/hooks/verify-exports.test
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect } from 'vitest';
|
|
9
|
-
describe('Hooks Module Exports', () => {
|
|
10
|
-
it('should export all types from main module', async () => {
|
|
11
|
-
const module = await import('./index.js');
|
|
12
|
-
// Enums
|
|
13
|
-
expect(module.HookEvent).toBeDefined();
|
|
14
|
-
expect(module.HookPriority).toBeDefined();
|
|
15
|
-
// Classes
|
|
16
|
-
expect(module.HookRegistry).toBeDefined();
|
|
17
|
-
expect(module.HookExecutor).toBeDefined();
|
|
18
|
-
// Factory functions
|
|
19
|
-
expect(module.createHookRegistry).toBeDefined();
|
|
20
|
-
expect(module.createHookExecutor).toBeDefined();
|
|
21
|
-
});
|
|
22
|
-
it('should export types (type-only imports)', () => {
|
|
23
|
-
expect(true).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
it('should create instances from exported factories', async () => {
|
|
26
|
-
const { createHookRegistry, createHookExecutor } = await import('./index.js');
|
|
27
|
-
const registry = createHookRegistry();
|
|
28
|
-
expect(registry).toBeDefined();
|
|
29
|
-
expect(typeof registry.register).toBe('function');
|
|
30
|
-
expect(typeof registry.unregister).toBe('function');
|
|
31
|
-
const executor = createHookExecutor(registry);
|
|
32
|
-
expect(executor).toBeDefined();
|
|
33
|
-
expect(typeof executor.execute).toBe('function');
|
|
34
|
-
});
|
|
35
|
-
it('should have all 26 hook events defined', async () => {
|
|
36
|
-
const { HookEvent } = await import('./index.js');
|
|
37
|
-
const expectedEvents = [
|
|
38
|
-
'PreToolUse',
|
|
39
|
-
'PostToolUse',
|
|
40
|
-
'PreEdit',
|
|
41
|
-
'PostEdit',
|
|
42
|
-
'PreRead',
|
|
43
|
-
'PostRead',
|
|
44
|
-
'PreWrite',
|
|
45
|
-
'PostWrite',
|
|
46
|
-
'PreCommand',
|
|
47
|
-
'PostCommand',
|
|
48
|
-
'SessionStart',
|
|
49
|
-
'SessionEnd',
|
|
50
|
-
'SessionPause',
|
|
51
|
-
'SessionResume',
|
|
52
|
-
'PreAgentSpawn',
|
|
53
|
-
'PostAgentSpawn',
|
|
54
|
-
'PreAgentTerminate',
|
|
55
|
-
'PostAgentTerminate',
|
|
56
|
-
'PreTaskExecute',
|
|
57
|
-
'PostTaskExecute',
|
|
58
|
-
'PreTaskComplete',
|
|
59
|
-
'PostTaskComplete',
|
|
60
|
-
'PreMemoryStore',
|
|
61
|
-
'PostMemoryStore',
|
|
62
|
-
'PreMemoryRetrieve',
|
|
63
|
-
'PostMemoryRetrieve',
|
|
64
|
-
'OnError',
|
|
65
|
-
'OnWarning',
|
|
66
|
-
];
|
|
67
|
-
for (const event of expectedEvents) {
|
|
68
|
-
expect(HookEvent[event]).toBeDefined();
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
it('should have all 5 priority levels defined', async () => {
|
|
72
|
-
const { HookPriority } = await import('./index.js');
|
|
73
|
-
expect(HookPriority.Critical).toBe(1000);
|
|
74
|
-
expect(HookPriority.High).toBe(500);
|
|
75
|
-
expect(HookPriority.Normal).toBe(0);
|
|
76
|
-
expect(HookPriority.Low).toBe(-500);
|
|
77
|
-
expect(HookPriority.Lowest).toBe(-1000);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe('Hooks Integration with Shared Module', () => {
|
|
81
|
-
it('should be importable from @claude-flow/shared', async () => {
|
|
82
|
-
// This would be the actual import path in production
|
|
83
|
-
const module = await import('../index.js');
|
|
84
|
-
// Verify hooks are exported from main shared module
|
|
85
|
-
expect(module.HookEvent).toBeDefined();
|
|
86
|
-
expect(module.HookPriority).toBeDefined();
|
|
87
|
-
expect(module.HookRegistry).toBeDefined();
|
|
88
|
-
expect(module.HookExecutor).toBeDefined();
|
|
89
|
-
expect(module.createHookRegistry).toBeDefined();
|
|
90
|
-
expect(module.createHookExecutor).toBeDefined();
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
//# sourceMappingURL=verify-exports.test.js.map
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { Bulkhead } from './bulkhead.js';
|
|
3
|
-
describe('queued bulkhead failures', () => {
|
|
4
|
-
it('rejects the throwing task and preserves the previous result and remaining capacity', async () => {
|
|
5
|
-
const bulkhead = new Bulkhead({
|
|
6
|
-
name: 'test',
|
|
7
|
-
maxConcurrent: 1,
|
|
8
|
-
maxQueue: 2,
|
|
9
|
-
queueTimeout: 100,
|
|
10
|
-
});
|
|
11
|
-
let release;
|
|
12
|
-
const first = bulkhead.execute(() => new Promise((resolve) => {
|
|
13
|
-
release = resolve;
|
|
14
|
-
}));
|
|
15
|
-
const failure = new Error('synchronous callback failure');
|
|
16
|
-
const second = bulkhead.execute(() => {
|
|
17
|
-
throw failure;
|
|
18
|
-
});
|
|
19
|
-
const secondResult = second.catch((error) => error);
|
|
20
|
-
const third = bulkhead.execute(async () => 'third');
|
|
21
|
-
release('first');
|
|
22
|
-
await expect(first).resolves.toBe('first');
|
|
23
|
-
expect(await secondResult).toBe(failure);
|
|
24
|
-
await expect(third).resolves.toBe('third');
|
|
25
|
-
await Promise.resolve();
|
|
26
|
-
expect(bulkhead.getStats()).toMatchObject({
|
|
27
|
-
active: 0,
|
|
28
|
-
queued: 0,
|
|
29
|
-
completed: 2,
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
//# sourceMappingURL=bulkhead-sync-throw.test.js.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { retry } from './retry.js';
|
|
3
|
-
afterEach(() => vi.useRealTimers());
|
|
4
|
-
describe('retry timeout lifetime', () => {
|
|
5
|
-
it('does not keep a success timer alive after an attempt settles', async () => {
|
|
6
|
-
vi.useFakeTimers();
|
|
7
|
-
const result = await retry(async () => 42, {
|
|
8
|
-
maxAttempts: 1,
|
|
9
|
-
timeout: 30000,
|
|
10
|
-
});
|
|
11
|
-
expect(result.success).toBe(true);
|
|
12
|
-
expect(result.result).toBe(42);
|
|
13
|
-
expect(vi.getTimerCount()).toBe(0);
|
|
14
|
-
});
|
|
15
|
-
it('releases timers for rejected attempts without suppressing their errors', async () => {
|
|
16
|
-
vi.useFakeTimers();
|
|
17
|
-
const err = new Error('no');
|
|
18
|
-
const result = await retry(async () => {
|
|
19
|
-
throw err;
|
|
20
|
-
}, { maxAttempts: 1 });
|
|
21
|
-
expect(result.success).toBe(false);
|
|
22
|
-
expect(result.errors).toEqual([err]);
|
|
23
|
-
expect(vi.getTimerCount()).toBe(0);
|
|
24
|
-
});
|
|
25
|
-
it('still bounds a pending operation and reports the timeout', async () => {
|
|
26
|
-
vi.useFakeTimers();
|
|
27
|
-
const promise = retry(() => new Promise(() => { }), {
|
|
28
|
-
maxAttempts: 1,
|
|
29
|
-
timeout: 10,
|
|
30
|
-
});
|
|
31
|
-
await vi.advanceTimersByTimeAsync(10);
|
|
32
|
-
const result = await promise;
|
|
33
|
-
expect(result.success).toBe(false);
|
|
34
|
-
expect(result.errors[0].message).toContain('timed out');
|
|
35
|
-
expect(vi.getTimerCount()).toBe(0);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
//# sourceMappingURL=retry-timeout-cleanup.test.js.map
|