2026-12-04 08:37:28 -08:00
|
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
// 粗略统计黄金对照覆盖的服务器路由:把记录里的请求归一为“方法 + 路由模板”,与 server.js 中的路由清单对照。
|
|
|
|
|
|
// 用法:node e2e/coverage.js(读取 e2e/baseline/golden/transcript.json)
|
2026-12-04 08:58:53 -08:00
|
|
|
|
const fs = require('node:fs'),
|
|
|
|
|
|
path = require('node:path');
|
|
|
|
|
|
const transcript = JSON.parse(fs.readFileSync(path.join(__dirname, 'baseline', 'golden', 'transcript.json'), 'utf8'));
|
|
|
|
|
|
const template = p =>
|
|
|
|
|
|
p
|
|
|
|
|
|
.split('?')[0]
|
|
|
|
|
|
.replace(/<id\d+>/g, ':id')
|
|
|
|
|
|
.replace(/\d{4}-\d{2}-\d{2}/g, ':date')
|
|
|
|
|
|
.replace(/pocket_:id/g, ':pocket')
|
|
|
|
|
|
.replace(/<backup-file>/g, ':file')
|
|
|
|
|
|
.replace(/\/staff_:id\//, '/:member/')
|
|
|
|
|
|
.replace(/\/(assistant2?|owner)\/password$/, '/:member/password')
|
|
|
|
|
|
.replace(/^\/print\/(?!recoveries).+/, '/print/:id');
|
|
|
|
|
|
const ROUTES =
|
|
|
|
|
|
`GET /api/session|POST /api/setup|POST /api/login|POST /api/demo-login|POST /api/logout|GET /api/state|GET /api/print-status/order/:id|POST /api/print-status/order/:id|GET /api/print-status/recovery/:id|POST /api/print-status/recovery/:id|GET /api/shop-settings|POST /api/shop-settings|POST /api/printing|GET /api/employees|POST /api/employees|POST /api/employees/:member/update|POST /api/employees/:member/deactivate|POST /api/employees/:member/reactivate|POST /api/employees/:member/delete|GET /api/team-members|POST /api/team-members/:member/password|GET /api/pockets|POST /api/pockets|POST /api/pockets/:pocket/update|GET /api/team-funds|POST /api/team-funds/transfers|POST /api/team-funds/transfer|GET /api/private-operations|GET /api/private-operations/people|POST /api/private-operations/people|GET /api/private-operations/people-history|GET /api/team-profits|GET /api/material-pools|GET /api/material-pools/rolling-preview|POST /api/material-pools/rolling-enable|POST /api/material-pools/quote|GET /api/material-pools/:date|POST /api/material-pools/:date/settlement|GET /api/material-purchase-changes|GET /api/material-purchase-changes/:id|POST /api/material-purchase-changes/:id/approve|POST /api/material-purchase-changes/:id/reject|POST /api/material-purchases|GET /api/material-purchases/:id|POST /api/material-purchases/:id/edit|POST /api/material-purchases/:id/delete|POST /api/material-purchases/:id/change|GET /api/after-sales/changes|GET /api/after-sales/changes/:id|POST /api/after-sales/changes/:id/approve|POST /api/after-sales/changes/:id/reject|POST /api/after-sales|GET /api/after-sales/:id|POST /api/after-sales/:id/update|GET /api/customer-materials|POST /api/customer-materials|GET /api/recoveries|POST /api/recoveries|POST /api/recoveries/quote|GET /api/recoveries/:id|GET /api/recoveries/:id/edit|POST /api/recoveries/:id/update|POST /api/recoveries/:id/cancel|POST /api/recoveries/:id/quote|GET /api/recovery-changes|GET /api/recovery-changes/:id|POST /api/recovery-changes/:id/approve|POST /api/recovery-changes/:id/reject|GET /api/price-locks|POST /api/price-locks|GET /api/price-locks/:id|GET /api/price-locks/:id/edit-context|POST /api/price-locks/:id/deliver|POST /api/price-locks/:id/edit|POST /api/price-locks/:id/cancel|POST /api/price-locks/:id/change-requests|GET /api/price-lock-changes|GET /api/price-lock-changes/:id|POST /api/price-lock-changes/:id/approve|POST /api/price-lock-changes/:id/reject|GET /api/order-note-tags|GET /api/order-changes|GET /api/order-changes/:id|POST /api/order-changes/:id/approve|POST /api/order-changes/:id/reject|GET /api/order-ownership-changes|GET /api/order-ownership-changes/:id|POST /api/order-ownership-changes/:id/approve|POST /api/order-ownership-changes/:id/reject|GET /api/order-cancellations|GET /api/order-cancellations/:id|POST /api/order-cancellations/:id/approve|POST /api/order-cancellations/:id/reject|GET /api/inventory|GET /api/inventory/movements/export.xlsx|GET /api/inventory/movements|GET /api/inventory/movements/:id|POST /api/inventory/movements/:id/update|POST /api/inventory/movements/:id/delete|GET /api/inventory/changes|GET /api/inventory/changes/:id|POST /api/inventory/changes/:id/approve|POST /api/inventory/changes/:id/reject|GET /api/inventory/snapshots|POST /api/inventory/review|GET /api/order-book|GET /api/order-templates|POST /api/order-templates|GET /api/order-templates/:id|POST /api/order-templates/:id/update|POST /api/order-templates/:id/delete|GET /api/people-count|POST /api/people-count|GET /api/people-count-history|GET /api/daily-funds|POST /api/daily-funds/confirm|GET /api/reimbursement-funding-options|GET /api/reimbursements|POST /api/reimbursements|POST /api/reimbursements/:id/update|POST /api/reimbursements/:id/approve|POST /api/reimbursements/:id/reject|GET /api/returned-stock-lots|GET /api/paper-number|GET /api/orders/:id/after-sale|POST /api/orders/:id/after-sale-preview|GET /api/orders/:id|GET /api/orders/:id/public|GET /api/orders/:id/edit|GET /api/orders/:id/change|GET /api/orders/:id/ownership|GET /api/orders/:id/cancellation|POST /api/orders/issue|
|
|
|
|
|
|
'|',
|
|
|
|
|
|
);
|
|
|
|
|
|
const hits = new Map();
|
|
|
|
|
|
for (const e of transcript.filter(e => e.method)) {
|
|
|
|
|
|
let key = e.method + ' ' + template(e.path);
|
|
|
|
|
|
if (e.method === 'GET' && /^\/[\w.-]*$/.test(e.path) && !e.path.startsWith('/api')) key = 'GET /(static assets)';
|
|
|
|
|
|
const ok = e.status < 400;
|
|
|
|
|
|
const h = hits.get(key) || { ok: 0, err: 0 };
|
|
|
|
|
|
h[ok ? 'ok' : 'err']++;
|
|
|
|
|
|
hits.set(key, h);
|
|
|
|
|
|
}
|
|
|
|
|
|
const covered = ROUTES.filter(r => hits.has(r)),
|
|
|
|
|
|
success = ROUTES.filter(r => hits.get(r)?.ok);
|
|
|
|
|
|
console.log(
|
|
|
|
|
|
`路由清单 ${ROUTES.length} 条;被请求 ${covered.length} 条(${Math.round((covered.length / ROUTES.length) * 100)}%),其中有成功响应 ${success.length} 条(${Math.round((success.length / ROUTES.length) * 100)}%)。`,
|
|
|
|
|
|
);
|
|
|
|
|
|
console.log('\n未请求:\n ' + ROUTES.filter(r => !hits.has(r)).join('\n '));
|
|
|
|
|
|
console.log('\n只有错误响应(拒绝路径):\n ' + ROUTES.filter(r => hits.has(r) && !hits.get(r).ok).join('\n '));
|
|
|
|
|
|
const extra = [...hits.keys()].filter(k => !ROUTES.includes(k));
|
|
|
|
|
|
if (extra.length) console.log('\n清单外(多为故意的未知地址):\n ' + extra.join('\n '));
|