@sparkleideas/testing 3.0.0-alpha.7
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/README.md +547 -0
- package/__tests__/framework.test.ts +21 -0
- package/package.json +61 -0
- package/src/fixtures/agent-fixtures.ts +793 -0
- package/src/fixtures/agents.ts +212 -0
- package/src/fixtures/configurations.ts +491 -0
- package/src/fixtures/index.ts +21 -0
- package/src/fixtures/mcp-fixtures.ts +1030 -0
- package/src/fixtures/memory-entries.ts +328 -0
- package/src/fixtures/memory-fixtures.ts +750 -0
- package/src/fixtures/swarm-fixtures.ts +837 -0
- package/src/fixtures/tasks.ts +309 -0
- package/src/helpers/assertion-helpers.ts +616 -0
- package/src/helpers/assertions.ts +286 -0
- package/src/helpers/create-mock.ts +200 -0
- package/src/helpers/index.ts +182 -0
- package/src/helpers/mock-factory.ts +711 -0
- package/src/helpers/setup-teardown.ts +678 -0
- package/src/helpers/swarm-instance.ts +326 -0
- package/src/helpers/test-application.ts +310 -0
- package/src/helpers/test-utils.ts +670 -0
- package/src/index.ts +232 -0
- package/src/mocks/index.ts +29 -0
- package/src/mocks/mock-mcp-client.ts +723 -0
- package/src/mocks/mock-services.ts +793 -0
- package/src/regression/api-contract.ts +473 -0
- package/src/regression/index.ts +46 -0
- package/src/regression/integration-regression.ts +416 -0
- package/src/regression/performance-baseline.ts +356 -0
- package/src/regression/regression-runner.ts +339 -0
- package/src/regression/security-regression.ts +331 -0
- package/src/setup.ts +127 -0
- package/src/v2-compat/api-compat.test.ts +590 -0
- package/src/v2-compat/cli-compat.test.ts +484 -0
- package/src/v2-compat/compatibility-validator.ts +1072 -0
- package/src/v2-compat/hooks-compat.test.ts +602 -0
- package/src/v2-compat/index.ts +58 -0
- package/src/v2-compat/mcp-compat.test.ts +557 -0
- package/src/v2-compat/report-generator.ts +441 -0
- package/tmp.json +0 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +12 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Claude-Flow Memory Entry Fixtures
|
|
3
|
+
*
|
|
4
|
+
* Test data for memory and AgentDB testing
|
|
5
|
+
* Following London School principle of explicit test data
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Memory entry interface
|
|
10
|
+
*/
|
|
11
|
+
export interface MemoryEntry {
|
|
12
|
+
key: string;
|
|
13
|
+
value: unknown;
|
|
14
|
+
metadata: MemoryMetadata;
|
|
15
|
+
embedding?: number[];
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
expiresAt?: Date;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Memory metadata interface
|
|
23
|
+
*/
|
|
24
|
+
export interface MemoryMetadata {
|
|
25
|
+
type: 'short-term' | 'long-term' | 'semantic' | 'episodic';
|
|
26
|
+
tags: string[];
|
|
27
|
+
source?: string;
|
|
28
|
+
confidence?: number;
|
|
29
|
+
ttl?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Vector search query interface
|
|
34
|
+
*/
|
|
35
|
+
export interface VectorQuery {
|
|
36
|
+
embedding: number[];
|
|
37
|
+
topK: number;
|
|
38
|
+
threshold?: number;
|
|
39
|
+
filters?: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Search result interface
|
|
44
|
+
*/
|
|
45
|
+
export interface SearchResult {
|
|
46
|
+
key: string;
|
|
47
|
+
value: unknown;
|
|
48
|
+
score: number;
|
|
49
|
+
metadata: MemoryMetadata;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Pre-defined memory entries for testing
|
|
54
|
+
*/
|
|
55
|
+
export const memoryEntries: Record<string, MemoryEntry> = {
|
|
56
|
+
agentPattern: {
|
|
57
|
+
key: 'pattern:agent:queen-coordinator',
|
|
58
|
+
value: {
|
|
59
|
+
pattern: 'orchestration',
|
|
60
|
+
successRate: 0.95,
|
|
61
|
+
avgDuration: 150,
|
|
62
|
+
},
|
|
63
|
+
metadata: {
|
|
64
|
+
type: 'semantic',
|
|
65
|
+
tags: ['agent', 'pattern', 'queen'],
|
|
66
|
+
source: 'learning-module',
|
|
67
|
+
confidence: 0.92,
|
|
68
|
+
},
|
|
69
|
+
embedding: generateMockEmbedding(384, 'orchestration'),
|
|
70
|
+
createdAt: new Date('2024-01-01T00:00:00Z'),
|
|
71
|
+
updatedAt: new Date('2024-01-15T12:00:00Z'),
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
securityRule: {
|
|
75
|
+
key: 'rule:security:path-traversal',
|
|
76
|
+
value: {
|
|
77
|
+
rule: 'block-path-traversal',
|
|
78
|
+
patterns: ['../', '~/', '/etc/'],
|
|
79
|
+
severity: 'critical',
|
|
80
|
+
},
|
|
81
|
+
metadata: {
|
|
82
|
+
type: 'long-term',
|
|
83
|
+
tags: ['security', 'rule', 'validation'],
|
|
84
|
+
source: 'security-module',
|
|
85
|
+
confidence: 1.0,
|
|
86
|
+
},
|
|
87
|
+
embedding: generateMockEmbedding(384, 'security'),
|
|
88
|
+
createdAt: new Date('2024-01-01T00:00:00Z'),
|
|
89
|
+
updatedAt: new Date('2024-01-01T00:00:00Z'),
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
taskMemory: {
|
|
93
|
+
key: 'task:memory:impl-001',
|
|
94
|
+
value: {
|
|
95
|
+
taskId: 'impl-001',
|
|
96
|
+
context: 'implementing security module',
|
|
97
|
+
decisions: ['use argon2 for hashing', 'implement path validation'],
|
|
98
|
+
},
|
|
99
|
+
metadata: {
|
|
100
|
+
type: 'episodic',
|
|
101
|
+
tags: ['task', 'implementation', 'security'],
|
|
102
|
+
ttl: 86400000, // 24 hours
|
|
103
|
+
},
|
|
104
|
+
embedding: generateMockEmbedding(384, 'implementation'),
|
|
105
|
+
createdAt: new Date('2024-01-15T10:00:00Z'),
|
|
106
|
+
updatedAt: new Date('2024-01-15T10:00:00Z'),
|
|
107
|
+
expiresAt: new Date('2024-01-16T10:00:00Z'),
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
sessionContext: {
|
|
111
|
+
key: 'session:context:session-001',
|
|
112
|
+
value: {
|
|
113
|
+
sessionId: 'session-001',
|
|
114
|
+
user: 'developer',
|
|
115
|
+
activeAgents: ['queen-coordinator', 'coder'],
|
|
116
|
+
currentTask: 'security-implementation',
|
|
117
|
+
},
|
|
118
|
+
metadata: {
|
|
119
|
+
type: 'short-term',
|
|
120
|
+
tags: ['session', 'context'],
|
|
121
|
+
ttl: 3600000, // 1 hour
|
|
122
|
+
},
|
|
123
|
+
createdAt: new Date('2024-01-15T14:00:00Z'),
|
|
124
|
+
updatedAt: new Date('2024-01-15T14:30:00Z'),
|
|
125
|
+
expiresAt: new Date('2024-01-15T15:30:00Z'),
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
learningTrajectory: {
|
|
129
|
+
key: 'learning:trajectory:traj-001',
|
|
130
|
+
value: {
|
|
131
|
+
trajectoryId: 'traj-001',
|
|
132
|
+
steps: [
|
|
133
|
+
{ action: 'analyze', result: 'success', reward: 0.8 },
|
|
134
|
+
{ action: 'implement', result: 'success', reward: 0.9 },
|
|
135
|
+
{ action: 'test', result: 'success', reward: 1.0 },
|
|
136
|
+
],
|
|
137
|
+
totalReward: 2.7,
|
|
138
|
+
},
|
|
139
|
+
metadata: {
|
|
140
|
+
type: 'long-term',
|
|
141
|
+
tags: ['learning', 'trajectory', 'reinforcement'],
|
|
142
|
+
source: 'reasoningbank',
|
|
143
|
+
confidence: 0.88,
|
|
144
|
+
},
|
|
145
|
+
embedding: generateMockEmbedding(384, 'learning'),
|
|
146
|
+
createdAt: new Date('2024-01-10T00:00:00Z'),
|
|
147
|
+
updatedAt: new Date('2024-01-15T00:00:00Z'),
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Pre-defined search results for testing
|
|
153
|
+
*/
|
|
154
|
+
export const searchResults: Record<string, SearchResult[]> = {
|
|
155
|
+
securityPatterns: [
|
|
156
|
+
{
|
|
157
|
+
key: 'pattern:security:input-validation',
|
|
158
|
+
value: { pattern: 'validate all inputs', effectiveness: 0.99 },
|
|
159
|
+
score: 0.95,
|
|
160
|
+
metadata: { type: 'semantic', tags: ['security', 'pattern'] },
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
key: 'pattern:security:output-encoding',
|
|
164
|
+
value: { pattern: 'encode all outputs', effectiveness: 0.97 },
|
|
165
|
+
score: 0.88,
|
|
166
|
+
metadata: { type: 'semantic', tags: ['security', 'pattern'] },
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
key: 'pattern:security:least-privilege',
|
|
170
|
+
value: { pattern: 'minimal permissions', effectiveness: 0.95 },
|
|
171
|
+
score: 0.82,
|
|
172
|
+
metadata: { type: 'semantic', tags: ['security', 'pattern'] },
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
|
|
176
|
+
agentPatterns: [
|
|
177
|
+
{
|
|
178
|
+
key: 'pattern:agent:coordination',
|
|
179
|
+
value: { pattern: 'hierarchical coordination', successRate: 0.92 },
|
|
180
|
+
score: 0.91,
|
|
181
|
+
metadata: { type: 'semantic', tags: ['agent', 'pattern'] },
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
key: 'pattern:agent:communication',
|
|
185
|
+
value: { pattern: 'async messaging', successRate: 0.89 },
|
|
186
|
+
score: 0.85,
|
|
187
|
+
metadata: { type: 'semantic', tags: ['agent', 'pattern'] },
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
|
|
191
|
+
emptyResults: [],
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Generate mock embedding vector
|
|
196
|
+
* Creates deterministic embeddings based on seed string
|
|
197
|
+
*/
|
|
198
|
+
export function generateMockEmbedding(dimensions: number, seed: string): number[] {
|
|
199
|
+
const seedHash = hashString(seed);
|
|
200
|
+
return Array.from({ length: dimensions }, (_, i) => {
|
|
201
|
+
const value = Math.sin(seedHash + i * 0.1) * 0.5 + 0.5;
|
|
202
|
+
return Math.round(value * 10000) / 10000; // 4 decimal places
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Simple string hash function for deterministic embeddings
|
|
208
|
+
*/
|
|
209
|
+
function hashString(str: string): number {
|
|
210
|
+
let hash = 0;
|
|
211
|
+
for (let i = 0; i < str.length; i++) {
|
|
212
|
+
hash = ((hash << 5) - hash + str.charCodeAt(i)) | 0;
|
|
213
|
+
}
|
|
214
|
+
return hash;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Factory function to create memory entry with overrides
|
|
219
|
+
*/
|
|
220
|
+
export function createMemoryEntry(
|
|
221
|
+
base: keyof typeof memoryEntries,
|
|
222
|
+
overrides?: Partial<MemoryEntry>
|
|
223
|
+
): MemoryEntry {
|
|
224
|
+
return {
|
|
225
|
+
...memoryEntries[base],
|
|
226
|
+
...overrides,
|
|
227
|
+
key: overrides?.key ?? memoryEntries[base].key,
|
|
228
|
+
createdAt: overrides?.createdAt ?? new Date(),
|
|
229
|
+
updatedAt: overrides?.updatedAt ?? new Date(),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Factory function to create vector query
|
|
235
|
+
*/
|
|
236
|
+
export function createVectorQuery(overrides?: Partial<VectorQuery>): VectorQuery {
|
|
237
|
+
return {
|
|
238
|
+
embedding: overrides?.embedding ?? generateMockEmbedding(384, 'query'),
|
|
239
|
+
topK: overrides?.topK ?? 10,
|
|
240
|
+
threshold: overrides?.threshold ?? 0.7,
|
|
241
|
+
filters: overrides?.filters,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Create batch of memory entries for performance testing
|
|
247
|
+
*/
|
|
248
|
+
export function createMemoryBatch(count: number, type: MemoryMetadata['type'] = 'semantic'): MemoryEntry[] {
|
|
249
|
+
return Array.from({ length: count }, (_, i) => ({
|
|
250
|
+
key: `batch:entry:${i}`,
|
|
251
|
+
value: { index: i, data: `test data ${i}` },
|
|
252
|
+
metadata: {
|
|
253
|
+
type,
|
|
254
|
+
tags: [`batch`, `entry-${i}`],
|
|
255
|
+
},
|
|
256
|
+
embedding: generateMockEmbedding(384, `batch-${i}`),
|
|
257
|
+
createdAt: new Date(),
|
|
258
|
+
updatedAt: new Date(),
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Invalid memory entries for error testing
|
|
264
|
+
*/
|
|
265
|
+
export const invalidMemoryEntries = {
|
|
266
|
+
emptyKey: {
|
|
267
|
+
key: '',
|
|
268
|
+
value: { data: 'test' },
|
|
269
|
+
metadata: { type: 'short-term' as const, tags: [] },
|
|
270
|
+
createdAt: new Date(),
|
|
271
|
+
updatedAt: new Date(),
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
nullValue: {
|
|
275
|
+
key: 'valid-key',
|
|
276
|
+
value: null,
|
|
277
|
+
metadata: { type: 'short-term' as const, tags: [] },
|
|
278
|
+
createdAt: new Date(),
|
|
279
|
+
updatedAt: new Date(),
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
invalidEmbeddingDimension: {
|
|
283
|
+
key: 'valid-key',
|
|
284
|
+
value: { data: 'test' },
|
|
285
|
+
metadata: { type: 'semantic' as const, tags: [] },
|
|
286
|
+
embedding: [0.1, 0.2], // Wrong dimension
|
|
287
|
+
createdAt: new Date(),
|
|
288
|
+
updatedAt: new Date(),
|
|
289
|
+
},
|
|
290
|
+
|
|
291
|
+
expiredEntry: {
|
|
292
|
+
key: 'expired-key',
|
|
293
|
+
value: { data: 'expired' },
|
|
294
|
+
metadata: { type: 'short-term' as const, tags: [], ttl: -1000 },
|
|
295
|
+
createdAt: new Date('2024-01-01T00:00:00Z'),
|
|
296
|
+
updatedAt: new Date('2024-01-01T00:00:00Z'),
|
|
297
|
+
expiresAt: new Date('2024-01-01T00:01:00Z'),
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* AgentDB specific test data
|
|
303
|
+
*/
|
|
304
|
+
export const agentDBTestData = {
|
|
305
|
+
// HNSW index configuration
|
|
306
|
+
hnswConfig: {
|
|
307
|
+
M: 16,
|
|
308
|
+
efConstruction: 200,
|
|
309
|
+
efSearch: 50,
|
|
310
|
+
dimensions: 384,
|
|
311
|
+
},
|
|
312
|
+
|
|
313
|
+
// Expected performance metrics
|
|
314
|
+
performanceTargets: {
|
|
315
|
+
searchSpeedupMin: 150,
|
|
316
|
+
searchSpeedupMax: 12500,
|
|
317
|
+
memoryReduction: 0.50,
|
|
318
|
+
insertionTime: 1, // ms
|
|
319
|
+
searchTime: 0.1, // ms for 1M vectors
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
// Quantization configurations
|
|
323
|
+
quantizationConfigs: {
|
|
324
|
+
scalar4bit: { bits: 4, compressionRatio: 8 },
|
|
325
|
+
scalar8bit: { bits: 8, compressionRatio: 4 },
|
|
326
|
+
product: { subvectors: 8, bits: 8, compressionRatio: 32 },
|
|
327
|
+
},
|
|
328
|
+
};
|