// 汇总 sweep report.json(只读),产物写 evidence 目录。 import fs from 'fs'; import path from 'path'; const EV = process.env.EV || 'docs/acceptance/2026-10-24-full-qa'; const report = JSON.parse(fs.readFileSync(path.join(EV, 'sweep/report.json'), 'utf8')); const runs = report.runs || []; const admin = report.adminRuns || []; const uniq = (xs) => [...new Set(xs)]; const isRscAbort = (x) => /[?&]_rsc=/.test(x.url || '') && x.error === 'net::ERR_ABORTED'; const isHttpError = (x) => typeof x.status === 'number' && x.status >= 400; const publicSummary = { runs: runs.length, hard: runs.filter((r) => r.hardFailure).length, opacityBelow099: runs.filter((r) => (r.opacityProduct ?? 1) < 0.99).length, overflowX: runs.filter((r) => r.overflowX).length, brokenImages: runs.filter((r) => (r.broken || []).length > 0).length, pageErrors: runs.filter((r) => (r.pageErrors || []).length > 0).length, consoleErrorRuns: runs.filter((r) => (r.consoleErrors || []).length > 0).length, // `_rsc` 预取在导航/滚动时被浏览器 abort 是 Next 的正常噪声,不算失败请求。 prefetchAbortRuns: runs.filter((r) => (r.failedRequests || []).some(isRscAbort)).length, sameOriginHttpErrorRuns: runs.filter((r) => (r.failedRequests || []).some((x) => isHttpError(x) && !(r.expected404 && /\/_not-found$/.test(x.url || '')))).length, otherNetworkFailureRuns: runs.filter((r) => (r.failedRequests || []).some((x) => !isRscAbort(x) && !isHttpError(x))).length, thirdPartyRuns: runs.filter((r) => (r.thirdParty || []).length > 0).length, routes: uniq(runs.map((r) => r.route)).length, }; const detectors = { wrappedNumberRoutes: uniq(runs.filter((r) => (r.wrappedNumbers || []).length > 0).map((r) => r.route)), gridGapRoutes: uniq(runs.filter((r) => (r.gridGaps || []).length > 0).map((r) => r.route)), orphanColSpanRoutes: uniq(runs.filter((r) => (r.orphanColSpans || []).length > 0).map((r) => r.route)), wrappedOccurrences: runs.reduce((n, r) => n + (r.wrappedNumbers || []).length, 0), gridGapOccurrences: runs.reduce((n, r) => n + (r.gridGaps || []).length, 0), orphanOccurrences: runs.reduce((n, r) => n + (r.orphanColSpans || []).length, 0), }; const redRows = runs .filter((r) => r.shots && typeof r.shots.redPixelRatio === 'number') .map((r) => ({ route: r.route, vp: r.viewport, theme: r.theme, p: r.shots.redPixelRatio })) .sort((a, b) => b.p - a.p) .slice(0, 10); const design = { redTouchMin: Math.min(...runs.map((r) => r.redTouches ?? 0)), redTouchMax: Math.max(...runs.map((r) => r.redTouches ?? 0)), redPixelRatioTop: redRows, // 这条判据只匹配 #C41E3A ±28;bg-brand-section(#8B1530) 不在范围内 —— 见 README 的仪器缺口。 redPixelRatioRuleNote: 'matches brand #C41E3A +/-28 only; bg-brand-section #8B1530 is not counted', }; const form = { contact: [] }; for (const r of runs.filter((x) => x.route === '/contact')) { if (r.form) form.contact.push({ vp: r.viewport, theme: r.theme, top: r.form.top, inViewport: r.form.inFirstViewport, fields: r.form.fields }); } const adminSummary = { runs: admin.length, hard: admin.filter((r) => r.hardFailure).length, opacityBelow099: admin.filter((r) => (r.opacityProduct ?? 1) < 0.99).length, overflowX: admin.filter((r) => r.overflowX).length, tabBarOn390: admin.filter((r) => r.viewport === '390' && r.mobileTabBar).length, tabBarRoutes: uniq(admin.filter((r) => r.viewport === '390' && r.mobileTabBar).map((r) => r.route)), pageErrors: admin.filter((r) => (r.pageErrors || []).length > 0).length, consoleErrorRuns: admin.filter((r) => (r.consoleErrors || []).length > 0).length, touchUnder44Runs: admin.filter((r) => (r.touchTargets || []).some((t) => t.w < 44 || t.h < 44)).length, }; const hardList = [...runs, ...admin] .filter((r) => r.hardFailure) .map((r) => ({ kind: r.kind, route: r.route, vp: r.viewport, theme: r.theme, error: r.error, opacity: r.opacityProduct, overflowX: r.overflowX, broken: (r.broken || []).length, pageErrors: (r.pageErrors || []).length, failedRequests: (r.failedRequests || []).length })); const out = { meta: report.meta, public: publicSummary, detectors, design, form, admin: adminSummary, hardList }; fs.writeFileSync(path.join(EV, 'sweep/summary.json'), JSON.stringify(out, null, 2)); console.log(JSON.stringify(out, null, 2));