claude-flow 3.62.0 → 3.63.1
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/.proven-config-version +1 -0
- package/.claude/helpers/.helpers-version +1 -0
- package/.claude/helpers/helpers.manifest.json +13 -0
- package/.claude/proven-config.json +42 -0
- package/.claude/settings.local.json +8 -0
- package/.claude-plugin/marketplace.json +3 -3
- package/README.md +2 -2
- package/node_modules/@claude-flow/codex/dist/cli.js +0 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.js +0 -0
- package/node_modules/@claude-flow/security/dist/input-validator.d.ts +6 -6
- package/package.json +1 -1
- package/v3/@claude-flow/cli/README.md +2 -2
- package/v3/@claude-flow/cli/catalog-manifest.json +3 -3
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentbbs-tools.js +7 -2
- package/v3/@claude-flow/cli/dist/src/mcp-tools/managed-agent-tools.d.ts +1 -20
- package/v3/@claude-flow/cli/dist/src/mcp-tools/managed-agent-tools.js +347 -108
- package/v3/@claude-flow/cli/dist/src/mcp-tools/managed-learning-tool.d.ts +4 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/managed-learning-tool.js +46 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +6 -3
- package/v3/@claude-flow/cli/dist/src/missions/schemas.d.ts +12 -12
- package/v3/@claude-flow/cli/dist/src/ruvector/diskann-backend.d.ts +78 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/diskann-backend.js +310 -0
- package/v3/@claude-flow/cli/dist/src/services/flywheel-transaction.js +5 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-learning-loop.d.ts +79 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-learning-loop.js +76 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-learning-store.d.ts +187 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-learning-store.js +238 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-learning.d.ts +108 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-learning.js +197 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-memory-client.d.ts +72 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-memory-client.js +236 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-memory-worker.d.ts +56 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-memory-worker.js +161 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-run-collector.d.ts +93 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-run-collector.js +181 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-run-store.d.ts +52 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-run-store.js +119 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-workflows.d.ts +101 -0
- package/v3/@claude-flow/cli/dist/src/services/managed-workflows.js +183 -0
- package/v3/@claude-flow/cli/package.json +1 -1
- package/v3/@claude-flow/shared/dist/events/event-store.test.d.ts +8 -0
- package/v3/@claude-flow/shared/dist/events/event-store.test.js +293 -0
- package/v3/@claude-flow/shared/dist/hooks/hooks.test.d.ts +9 -0
- package/v3/@claude-flow/shared/dist/hooks/hooks.test.js +322 -0
- package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +9 -0
- package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.js +93 -0
|
@@ -0,0 +1,322 @@
|
|
|
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
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|