-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-proxy-integration.js
More file actions
93 lines (78 loc) · 3.29 KB
/
test-proxy-integration.js
File metadata and controls
93 lines (78 loc) · 3.29 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
// 集成测试:模拟 memov-mcp-proxy 的三个 API handler 逻辑
const causal = require('./memory/causal');
const { PointerSystem } = require('./memory/pointer');
const ps = new PointerSystem();
// === 模拟 POST /api/search ===
console.log('========================================');
console.log('模拟 POST /api/search');
console.log('========================================');
ps.store('ptr://infra/redis/err@v1', ps.createPayload({
pointer: 'ptr://infra/redis/err@v1',
topic: 'redis', content: 'Redis ECONNREFUSED error',
keywords: ['redis', 'error']
}));
const query = 'redis error';
const limit = 5;
const keywords = query.split(/\s+/).filter(Boolean);
const keywordResults = ps.searchByKeywords(keywords);
const seen = new Set();
const results = [];
for (const item of keywordResults) {
const ptr = item.pointer;
if (!seen.has(ptr)) {
seen.add(ptr);
results.push({
pointer: ptr, score: 1.0,
content: item.content || item.topic || '',
timestamp: item.updated_at || item.created_at || Date.now()
});
}
}
console.log('Response:', JSON.stringify({ results: results.slice(0, limit) }, null, 2));
// === 模拟 POST /api/causal/debug (diagnose) ===
console.log('\n========================================');
console.log('模拟 POST /api/causal/debug (diagnose)');
console.log('========================================');
const pointer = 'test-task-1';
const errorLog = 'ECONNREFUSED 127.0.0.1:6379';
const finding = causal.diagnoseFailure(pointer, errorLog);
const diagResponse = {
pointer, mode: 'diagnose', finding,
issues: finding.cause ? [{ cause: finding.cause, confidence: finding.confidence }] : [],
suggestions: finding.fix ? [finding.fix] : []
};
console.log('Response:', JSON.stringify(diagResponse, null, 2));
// === 模拟 POST /api/causal/debug (trace) ===
console.log('\n========================================');
console.log('模拟 POST /api/causal/debug (trace)');
console.log('========================================');
const chain = causal.getCausalChain(pointer);
console.log('Response:', JSON.stringify({
pointer, mode: 'trace',
chain_length: chain.length,
first_entry: chain[0] || null,
issues: [], suggestions: []
}, null, 2));
// === 模拟 POST /api/causal/debug (learn) ===
console.log('\n========================================');
console.log('模拟 POST /api/causal/debug (learn)');
console.log('========================================');
const entity = causal.learnFromSuccess(pointer, 'Restarted Redis service');
console.log('Response:', JSON.stringify({
pointer, mode: 'learn', entity, issues: [], suggestions: []
}, null, 2));
// === 验证回滚参数校验 ===
console.log('\n========================================');
console.log('验证回滚 target 校验逻辑');
console.log('========================================');
const validTargets = ['agent-01', 'worker_2', 'all', null];
const invalidTargets = ['../etc/passwd', 'foo;rm -rf /', 'agent 1'];
for (const t of validTargets) {
const ok = !t || t === 'all' || /^[a-zA-Z0-9_-]+$/.test(t);
console.log(` target="${t}" => ${ok ? 'PASS' : 'FAIL'}`);
}
for (const t of invalidTargets) {
const ok = !t || t === 'all' || /^[a-zA-Z0-9_-]+$/.test(t);
console.log(` target="${t}" => ${ok ? 'FAIL (should reject)' : 'BLOCKED (correct)'}`);
}
console.log('\n✅ 所有集成测试通过');