import fs from 'fs'; import path from 'path'; import app from './src/index'; const PORT = 3002; const BASE_URL = `http://localhost:${PORT}`; const tc = { case_id: 'TC-05', sample_type: '缺 PRD', materials: { current_policy_text: '基本条款...', prd_text: '', // 故意置空触发 4001 permission_items: [], sdk_items: [] }, peer_updates: [], regulatory_updates: [] }; async function post(url: string, data: any) { const start = Date.now(); const res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); const latency = Date.now() - start; const json = await res.json(); if (!res.ok) { throw { status: res.status, latency, error: json }; } return { data: json, latency }; } const server = app.listen(PORT, async () => { console.log(`Server started on ${PORT}`); try { const baseContext = { case_id: tc.case_id, customer_id: 'CUST-TEST', customer_name: '测试银行', app_name: '测试银行APP', business_line: 'retail', language: 'zh-CN', materials: tc.materials, external_context: { peer_updates: tc.peer_updates, regulatory_updates: tc.regulatory_updates }, metadata: { submitted_at: new Date().toISOString(), source: 'regression-test' } }; const a1Res = await post(`${BASE_URL}/api/agents/peer-reg-summary`, { peer_updates: tc.peer_updates, regulatory_updates: tc.regulatory_updates, business_line: 'retail', app_name: '测试银行APP' }); console.log('a1 done'); const a2Res = await post(`${BASE_URL}/api/agents/policy-rewrite`, { case_context: baseContext, peer_reg_summary: a1Res.data }); console.log('a2 done'); } catch(err: any) { let rec = 'ERROR'; if (err.error && (err.error.error_code === 'need_more_material' || (err.error.error && err.error.error.code === 4001))) { rec = 'need_more_material (4001)'; } console.log('caught:', rec); } server.close(); process.exit(0); });