| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/usr/bin/env node
- /**
- * 导出接口回归校验(BUG-004)。
- *
- * 覆盖三处导出:任务管理 / 会话与消息审计 / 用量与配额。
- * 断言:空筛选条件下不再出现 `agentId=null` 之类的非法参数,接口返回 200 且响应非空。
- *
- * 用法(后端已启动):
- * node ai-server/scripts/verify-export.mjs
- * ZSJZ_BASE_URL=http://localhost:8980/js/a ZSJZ_USERNAME=admin ZSJZ_PASSWORD=admin123 node ai-server/scripts/verify-export.mjs
- *
- * 说明:脚本会以 force=true 登录(会顶掉同一账号的浏览器会话),执行后浏览器需重新登录。
- */
- const BASE = process.env.ZSJZ_BASE_URL ?? 'http://localhost:8980/js/a';
- const USERNAME = process.env.ZSJZ_USERNAME ?? 'admin';
- const PASSWORD = process.env.ZSJZ_PASSWORD ?? 'admin123';
- async function login() {
- const res = await fetch(`${BASE}/auth/login`, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ username: USERNAME, password: PASSWORD, force: true }),
- });
- const body = await res.json();
- if (body?.code !== 200 || !body?.data?.token) {
- throw new Error(`登录失败:HTTP ${res.status} / ${body?.message ?? body?.code ?? 'unknown'}`);
- }
- return body.data.token;
- }
- async function expectExport(token, path, name) {
- const res = await fetch(`${BASE}${path}`, {
- method: 'POST',
- headers: {
- 'x-token': token,
- 'Content-Type': 'application/x-www-form-urlencoded',
- },
- body: '',
- });
- const bytes = Buffer.from(await res.arrayBuffer());
- const contentType = res.headers.get('content-type') ?? '';
- const ok = res.status === 200 && bytes.length > 0;
- console.log(
- `${ok ? 'PASS' : 'FAIL'} ${name} HTTP=${res.status} bytes=${bytes.length} content-type=${contentType}`,
- );
- if (!ok) {
- const text = bytes.subarray(0, 300).toString('utf8');
- console.log(` 响应片段:${text}`);
- }
- return ok;
- }
- const token = await login();
- const results = await Promise.all([
- expectExport(token, '/ai/session/export', '任务管理导出'),
- expectExport(token, '/ai/audit/message/export', '会话与消息审计导出'),
- expectExport(token, '/ai/usage/export', '用量与配额导出'),
- ]);
- if (results.some((ok) => !ok)) {
- process.exitCode = 1;
- }
|