Repository navigation
Expand file tree
/
Copy pathtest_embedding_e2e.js
More file actions
261 lines (222 loc) · 7.96 KB
/
Copy pathtest_embedding_e2e.js
File metadata and controls
261 lines (222 loc) · 7.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/env node
/**
* Test E2E per sistema embedding DevStream
* Verifica: memoria storage → embedding generation → vector search
*/
const http = require('http');
const BASE_URL = 'http://localhost:9094';
async function testMemoryStorage() {
console.log(`🧪 Test 1: Memory Storage con Embedding...`);
const testData = {
content: "Questo è un test di verifica del sistema embedding per DevStream. Include concetti come database worker pool, sqlite-vec extension, e hybrid search functionality.",
content_type: "test",
keywords: ["embedding", "worker pool", "sqlite-vec", "hybrid search"],
metadata: {
test_id: "e2e_test_001",
timestamp: new Date().toISOString(),
component: "mcp_server"
}
};
return new Promise((resolve, reject) => {
const postData = JSON.stringify(testData);
const options = {
hostname: 'localhost',
port: 9094,
path: '/memory/store',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
const result = JSON.parse(data);
console.log(` ✅ Memory storage: ${result.success ? 'SUCCESS' : 'FAILED'}`);
if (result.success) {
console.log(` 📝 Record ID: ${result.record_id}`);
console.log(` 🧠 Embedding generato: ${result.embedding_generated ? 'SÌ' : 'NO'}`);
}
resolve(result);
} catch (e) {
console.log(` ❌ Memory storage: ERROR (${e.message})`);
resolve({ success: false, error: e.message });
}
});
});
req.on('error', (err) => {
console.log(` ❌ Memory storage: CONNECTION ERROR (${err.message})`);
resolve({ success: false, error: err.message });
});
req.write(postData);
req.end();
});
}
async function testHybridSearch() {
console.log(``);
console.log(`🔍 Test 2: Hybrid Search...`);
const searchQuery = "worker pool sqlite-vec embedding";
return new Promise((resolve, reject) => {
const postData = JSON.stringify({
query: searchQuery,
limit: 5,
content_type: null
});
const options = {
hostname: 'localhost',
port: 9094,
path: '/memory/search',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
const result = JSON.parse(data);
console.log(` ✅ Hybrid search: ${result.success ? 'SUCCESS' : 'FAILED'}`);
if (result.success) {
console.log(` 📊 Risultati trovati: ${result.results.length}`);
console.log(` 🎯 Top score: ${result.results[0]?.score?.toFixed(4) || 'N/A'}`);
console.log(` ⏱️ Query time: ${result.query_time_ms || 'N/A'}ms`);
// Verifica che il nostro test sia nei risultati
const testResult = result.results.find(r => r.content?.includes('e2e_test_001'));
if (testResult) {
console.log(` 🎯 Test record trovato (rank: ${result.results.indexOf(testResult) + 1})`);
}
}
resolve(result);
} catch (e) {
console.log(` ❌ Hybrid search: ERROR (${e.message})`);
resolve({ success: false, error: e.message });
}
});
});
req.on('error', (err) => {
console.log(` ❌ Hybrid search: CONNECTION ERROR (${err.message})`);
resolve({ success: false, error: err.message });
});
req.write(postData);
req.end();
});
}
async function testVectorSearch() {
console.log(``);
console.log(`🎯 Test 3: Vector Search Puro...`);
const searchQuery = "database performance optimization threading";
return new Promise((resolve, reject) => {
const postData = JSON.stringify({
query: searchQuery,
limit: 3,
search_type: "vector_only"
});
const options = {
hostname: 'localhost',
port: 9094,
path: '/memory/search',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
const result = JSON.parse(data);
console.log(` ✅ Vector search: ${result.success ? 'SUCCESS' : 'FAILED'}`);
if (result.success) {
console.log(` 📊 Risultati: ${result.results.length}`);
console.log(` 🎯 Top similarity: ${result.results[0]?.similarity?.toFixed(4) || 'N/A'}`);
}
resolve(result);
} catch (e) {
console.log(` ❌ Vector search: ERROR (${e.message})`);
resolve({ success: false, error: e.message });
}
});
});
req.on('error', (err) => {
console.log(` ❌ Vector search: CONNECTION ERROR (${err.message})`);
resolve({ success: false, error: err.message });
});
req.write(postData);
req.end();
});
}
async function testSystemMetrics() {
console.log(``);
console.log(`📊 Test 4: System Metrics...`);
return new Promise((resolve, reject) => {
const req = http.get(`${BASE_URL}/metrics`, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
// Estrai metriche rilevanti
const queryCount = (data.match(/devstream_queries_total[^}]+} (\d+)/) || [])[1] || '0';
const vectorIndex = (data.match(/devstream_vector_index_size (\d+)/) || [])[1] || '0';
const ftsIndex = (data.match(/devstream_fts5_index_size (\d+)/) || [])[1] || '0';
console.log(` ✅ Metrics: SUCCESS`);
console.log(` 📊 Query totali: ${queryCount}`);
console.log(` 🎯 Vector index size: ${vectorIndex}`);
console.log(` 📝 FTS5 index size: ${ftsIndex}`);
resolve({
success: true,
queryCount: parseInt(queryCount),
vectorIndex: parseInt(vectorIndex),
ftsIndex: parseInt(ftsIndex)
});
});
});
req.on('error', (err) => {
console.log(` ❌ Metrics: CONNECTION ERROR (${err.message})`);
resolve({ success: false, error: err.message });
});
});
}
async function runE2ETest() {
console.log(`🚀 DevStream MCP E2E Test Suite`);
console.log(`====================================`);
console.log(`Target: ${BASE_URL}`);
console.log(``);
const results = {
memoryStorage: await testMemoryStorage(),
hybridSearch: await testHybridSearch(),
vectorSearch: await testVectorSearch(),
systemMetrics: await testSystemMetrics()
};
console.log(``);
console.log(`📋 RIEPILOGO RISULTATI:`);
console.log(``);
const passed = Object.values(results).filter(r => r.success).length;
const total = Object.keys(results).length;
Object.entries(results).forEach(([test, result]) => {
const status = result.success ? '✅ PASS' : '❌ FAIL';
console.log(` ${test.padEnd(15)}: ${status}`);
});
console.log(``);
console.log(`🎯 VERDETTO FINALE: ${passed}/${total} test passati`);
if (passed === total) {
console.log(``);
console.log(`🎉 SISTEMA FULLY OPERATIVO!`);
console.log(` ✅ Memory storage con embedding automatico`);
console.log(` ✅ Hybrid search (vector + FTS5)`);
console.log(` ✅ Vector search puro`);
console.log(` ✅ System metrics`);
console.log(` ✅ Worker pool (test precedente: 426 QPS)`);
} else {
console.log(``);
console.log(`⚠️ PROBLEMI RILEVATI - Sistema non completamente operativo`);
}
process.exit(passed === total ? 0 : 1);
}
runE2ETest().catch(console.error);