| import app from './src/index'; |
| import * as http from 'http'; |
|
|
| const PORT = 3001; |
|
|
| async function runTests() { |
| const server = http.createServer(app); |
| |
| await new Promise<void>((resolve) => { |
| server.listen(PORT, () => { |
| console.log(`Test server running on port ${PORT}`); |
| resolve(); |
| }); |
| }); |
|
|
| const baseUrl = `http://localhost:${PORT}/api/agents`; |
|
|
| try { |
| console.log('\n--- 1. Testing API-01: peer-reg-summary ---'); |
| const payload01 = { |
| peer_updates: ["同业A更新了SDK列表", "同业B细化了权限说明"], |
| regulatory_updates: ["监管部门发布关于APP最小必要收集的通报"], |
| business_line: "retail", |
| app_name: "手机银行APP" |
| }; |
| |
| let res01 = await fetch(`${baseUrl}/peer-reg-summary`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(payload01) |
| }); |
| |
| |
| while(res01.status === 500) { |
| console.log('API-01 遇到了模拟的 5001 错误,正在重试...'); |
| res01 = await fetch(`${baseUrl}/peer-reg-summary`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(payload01) |
| }); |
| } |
|
|
| const peerRegSummary = await res01.json(); |
| console.log('✅ API-01 Success! Output:', JSON.stringify(peerRegSummary, null, 2)); |
|
|
| console.log('\n--- 2. Testing API-02: policy-rewrite ---'); |
| const case_context = { |
| case_id: "case_001", |
| materials: { |
| current_policy_text: "本隐私政策适用于手机银行APP。我们收集您的姓名和手机号用于注册。我们可能会申请您的设备权限。我们会把数据共享给第三方SDK以提供服务。", |
| prd_text: "PRD说明:包含人脸识别功能,需要获取身份证正反面,并在开户流程中使用相机进行活体检测。消息推送需接入极光SDK。", |
| permission_items: [{ name: "相机", purpose: "活体检测与身份证识别", required: true, trigger_page: "开户流程" }], |
| sdk_items: [{ name: "极光推送SDK", vendor: "极光", purpose: "消息推送", data_items: ["设备标识符", "网络状态"] }] |
| } |
| }; |
| |
| const payload02 = { |
| case_context, |
| peer_reg_summary: peerRegSummary |
| }; |
| |
| let res02 = await fetch(`${baseUrl}/policy-rewrite`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(payload02) |
| }); |
|
|
| while(res02.status === 500) { |
| console.log('API-02 遇到了模拟的 5001 错误,正在重试...'); |
| res02 = await fetch(`${baseUrl}/policy-rewrite`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(payload02) |
| }); |
| } |
|
|
| const gapAnalysis = await res02.json(); |
| console.log('✅ API-02 Success! Output:', JSON.stringify(gapAnalysis, null, 2)); |
|
|
| console.log('\n--- 3. Testing API-03: compliance-check ---'); |
| const payload03 = { |
| case_context, |
| gap_analysis: gapAnalysis |
| }; |
| |
| let res03 = await fetch(`${baseUrl}/compliance-check`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(payload03) |
| }); |
|
|
| while(res03.status === 500) { |
| console.log('API-03 遇到了模拟的 5001 错误,正在重试...'); |
| res03 = await fetch(`${baseUrl}/compliance-check`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(payload03) |
| }); |
| } |
|
|
| const complianceCheck = await res03.json(); |
| console.log('✅ API-03 Success! Output:', JSON.stringify(complianceCheck, null, 2)); |
|
|
| console.log('\n--- 4. Testing API-04: legal-pack ---'); |
| const payload04 = { |
| case_context, |
| peer_reg_summary: peerRegSummary, |
| gap_analysis: gapAnalysis, |
| compliance_check: complianceCheck |
| }; |
| |
| let res04 = await fetch(`${baseUrl}/legal-pack`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(payload04) |
| }); |
|
|
| while(res04.status === 500) { |
| console.log('API-04 遇到了模拟的 5001 错误,正在重试...'); |
| res04 = await fetch(`${baseUrl}/legal-pack`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify(payload04) |
| }); |
| } |
|
|
| const legalPack = await res04.json(); |
| console.log('✅ API-04 Success! Output:', JSON.stringify(legalPack, null, 2)); |
|
|
| console.log('\n--- 5. Testing Error Handling (Missing Materials) ---'); |
| const errRes = await fetch(`${baseUrl}/peer-reg-summary`, { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ app_name: "手机银行" }) |
| }); |
| const errData = await errRes.json(); |
| console.log('✅ Error Handling Success! Output:', JSON.stringify(errData, null, 2)); |
|
|
| } catch (error) { |
| console.error('Test failed:', error); |
| } finally { |
| server.close(() => { |
| console.log('\nTest server closed.'); |
| process.exit(0); |
| }); |
| } |
| } |
|
|
| runTests(); |
|
|