61 lines
2.9 KiB
JavaScript
61 lines
2.9 KiB
JavaScript
import http from 'http';
|
||
|
||
function req(method, path, body, token) {
|
||
return new Promise((resolve, reject) => {
|
||
const opts = { hostname: 'localhost', port: 3002, path, method, headers: { 'Content-Type': 'application/json' } };
|
||
if (token) opts.headers['Authorization'] = 'Bearer ' + token;
|
||
const r = http.request(opts, res => { let d = ''; res.on('data', c => d += c); res.on('end', () => resolve(JSON.parse(d))); });
|
||
r.on('error', reject);
|
||
if (body) r.end(JSON.stringify(body)); else r.end();
|
||
});
|
||
}
|
||
|
||
const token = (await req('POST', '/api/auth/login', { password: 'admin123' })).token;
|
||
|
||
// Get first project
|
||
const projects = await req('GET', '/api/projects', null, token);
|
||
const pid = projects[0]?.id;
|
||
if (!pid) { console.log('No project found'); process.exit(1); }
|
||
console.log('Project:', pid);
|
||
|
||
// Create a standard if none
|
||
const standards = await req('GET', `/api/projects/${pid}/standards`, null, token);
|
||
if (standards.length === 0) {
|
||
const std = await req('POST', `/api/projects/${pid}/standards`, {
|
||
name: 'L2标准', content: '## 功能完整性(25分)\n要点\n## 设计文档(15分)\n要点\n## 测试用例(10分)\n要点\n## 代码质量(10分)\n要点\n## AGENTS.md(15分)\n要点\n## 样本数据(15分)\n要点\n## 演示录屏(10分)\n要点'
|
||
}, token);
|
||
console.log('Standard created:', std.dimensions.length, 'dims');
|
||
}
|
||
|
||
// Test start review (will fail since repo doesn't exist, but tests the flow)
|
||
const entries = await req('GET', `/api/projects/${pid}/entries?limit=5`, null, token);
|
||
if (entries.items.length > 0) {
|
||
const eid = entries.items[0].id;
|
||
console.log('Entry:', entries.items[0].title, 'status:', entries.items[0].status);
|
||
|
||
const result = await req('POST', `/api/projects/${pid}/entries/${eid}/start`, null, token);
|
||
console.log('Start:', result.success ? 'OK' : 'FAIL', JSON.stringify(result));
|
||
|
||
// Wait a bit then check status
|
||
await new Promise(r => setTimeout(r, 2000));
|
||
const updated = await req('GET', `/api/projects/${pid}/entries/${eid}`, null, token);
|
||
console.log('Status after start:', updated.status);
|
||
|
||
// Test cancel
|
||
if (['queued', 'cloning', 'analyzing'].includes(updated.status)) {
|
||
await req('POST', `/api/projects/${pid}/entries/${eid}/cancel`, null, token);
|
||
const cancelled = await req('GET', `/api/projects/${pid}/entries/${eid}`, null, token);
|
||
console.log('After cancel:', cancelled.status);
|
||
}
|
||
|
||
// Test batch start
|
||
const batchResult = await req('POST', `/api/projects/${pid}/entries/batch-start`, { entryIds: [eid] }, token);
|
||
console.log('Batch start:', JSON.stringify(batchResult));
|
||
}
|
||
|
||
// verify the whole list endpoint works
|
||
const fullList = await req('GET', `/api/projects/${pid}/entries?offset=0&limit=10`, null, token);
|
||
console.log('List:', fullList.total, 'entries, offset:', fullList.offset, 'limit:', fullList.limit);
|
||
|
||
console.log('\n✅ Phase 2 core endpoints verified');
|