verify-visual-v13.mjs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. #!/usr/bin/env node
  2. /**
  3. * scripts/verify-visual-v13.mjs —— v13 收尾三项验收(每项打印实测原值,不看「通过」两个字)。
  4. *
  5. * node scripts/verify-visual-v13.mjs --tag before 只打印、不判分(改前基线)
  6. * node scripts/verify-visual-v13.mjs 判分:任一项不达标 exit 1
  7. * --json out.json 结果落盘(docs 里的数字从这里抄)
  8. *
  9. * 量什么:
  10. * 一、排序段(/pool .seg,桌面;手机上打开 .pbar-more 里的 .pbar-sorts)
  11. * - 选中项 computed background 与文字色、aria-pressed 计数
  12. * - 选中 / 未选中 font-size、line-height、按钮框高
  13. * - 外层:border-radius / border-width;按钮:每项各自 borderRadius = 0、相邻之间 1px 分隔线
  14. * 二、机会卡描述(/pool 每张 kf-opportunity-card)
  15. * - .one 是否有文字、一行字高(line-height)、卡内布局方式
  16. * - 无描述卡是否「没有描述区」而不是空 div;指标区上提了多少
  17. * - 有描述卡 / 无描述卡「内容总高」差;每张卡最大连续空白(叶子文字的竖直间隙)
  18. * 三、/pool 页脚类名命中:拿 cardFooter() 的每个类名,在 /pool 页脚里查规则命中(CSSOM 遍历 shadow root 的 adoptedStyleSheets),
  19. * 再与 /reports 同名元素逐项比对 computed padding / border / borderRadius / 字号 / 颜色。
  20. *
  21. * 坑(见 memory kf-verify-browser-quirks):视图异步挂载;跨 shadow 走 host;hover 要真实指针;滚动位置先归零。
  22. */
  23. import { mkdirSync, writeFileSync, existsSync } from 'node:fs';
  24. import { join, dirname } from 'node:path';
  25. import { fileURLToPath } from 'node:url';
  26. const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
  27. const argv = process.argv.slice(2);
  28. const arg = (k, d) => (argv.includes(k) ? argv[argv.indexOf(k) + 1] : d);
  29. const TAG = arg('--tag', 'after');
  30. const JUDGE = TAG !== 'before';
  31. const JSON_OUT = arg('--json', '');
  32. if (!process.env.CHROME_PATH) {
  33. const pinned = '/opt/hermes/.playwright/chromium_headless_shell-1243/chrome-headless-shell-linux64/chrome-headless-shell';
  34. if (existsSync(pinned)) process.env.CHROME_PATH = pinned;
  35. }
  36. const { startServer, launch, DEEP } = await import('./v11b-lib.mjs');
  37. const srv = await startServer(Number(process.env.VERIFY_PORT || 4194));
  38. const browser = await launch();
  39. const errors = [];
  40. const newPage = async (width = 1440, height = 900) => {
  41. const ctx = await browser.newContext({ viewport: { width, height }, deviceScaleFactor: 1 });
  42. const page = await ctx.newPage();
  43. page.on('pageerror', (e) => errors.push(e.message));
  44. page.on('console', (m) => { if (m.type() === 'error' && !/favicon/.test(m.text())) errors.push(m.text()); });
  45. return page;
  46. };
  47. const page = await newPage();
  48. const gotoView = async (p, name) => {
  49. await page.goto(new URL(p, srv.base).href, { waitUntil: 'networkidle' });
  50. await page.waitForFunction((n) => {
  51. const v = document.querySelector('kf-app')?.shadowRoot?.querySelector(n);
  52. return !!v && v.shadowRoot && v.shadowRoot.childElementCount > 0 && ('db' in v ? v.db != null : true);
  53. }, name, { timeout: 20000 });
  54. await page.waitForTimeout(700);
  55. };
  56. const rgb = (s) => (s.match(/\d+(\.\d+)?/g) || []).map(Number);
  57. const hex = (rgba, under = [255, 255, 255]) => {
  58. /* rgba → 叠在不透明底上的实际颜色(选中态是半透明底,亮度要算合成后的) */
  59. const [r, g, b, a = 1] = rgba;
  60. return [0, 1, 2].map((i) => Math.round(rgba[i] * a + under[i] * (1 - a)));
  61. };
  62. const lum = ([r, g, b]) => 0.2126 * r + 0.7152 * g + 0.0722 * b;
  63. const out = { tag: TAG, at: new Date().toISOString(), one: null, two: null, three: null };
  64. /* ======================= 一、排序段 ======================= */
  65. {
  66. await gotoView('/pool', 'view-pool');
  67. out.one = await page.evaluate(`(async () => {
  68. ${DEEP}
  69. const v = appR().querySelector('view-pool').shadowRoot;
  70. const seg = v.querySelector('.filters .seg');
  71. if (!seg) return { missing: true };
  72. const btns = [...seg.querySelectorAll('button')];
  73. const read = (b) => { const s = getComputedStyle(b); const r = b.getBoundingClientRect();
  74. return { text: b.textContent.trim(), pressed: b.getAttribute('aria-pressed'), bg: s.backgroundColor, color: s.color, fontSize: s.fontSize, lineHeight: s.lineHeight,
  75. h: Math.round(r.height * 10) / 10, radius: s.borderTopLeftRadius + ' ' + s.borderTopRightRadius, borderLeft: s.borderLeftWidth }; };
  76. const ss = getComputedStyle(seg);
  77. /* 分隔线:相邻按钮「左 1px」+ 第一个「无左边框」 */
  78. const seps = btns.map((b, i) => ({ i, left: getComputedStyle(b).borderLeftWidth, leftStyle: getComputedStyle(b).borderLeftStyle, leftColor: getComputedStyle(b).borderLeftColor }));
  79. /* 实际命中规则里的 background(不是 computed 的 rgba(0,0,0,0) 兜底) */
  80. const sel = btns.find((b) => b.getAttribute('aria-pressed') === 'true');
  81. const selRule = sel ? getComputedStyle(sel) : null;
  82. const wrap = seg.parentElement.getBoundingClientRect();
  83. const r = seg.getBoundingClientRect();
  84. return { btns: btns.map(read), seps, outer: { radius: ss.borderTopLeftRadius, border: ss.borderTopWidth + ' ' + ss.borderTopStyle + ' ' + ss.borderTopColor, h: Math.round(r.height * 10) / 10, bg: ss.backgroundColor },
  85. selected: sel ? read(sel) : null, unselected: btns.filter((b) => b.getAttribute('aria-pressed') !== 'true').map(read),
  86. selColorRule: selRule ? selRule.color : null, wrapTop: wrap.top };
  87. })()`);
  88. /* 手机档:把排序抽屉打开,量里面的段选 */
  89. const mpage = await newPage(393, 852);
  90. await mpage.goto(new URL('/pool', srv.base).href, { waitUntil: 'networkidle' });
  91. await mpage.waitForFunction(() => {
  92. const v = document.querySelector('kf-app')?.shadowRoot?.querySelector('view-pool');
  93. return !!v && v.shadowRoot && v.shadowRoot.childElementCount > 0 && v.db != null;
  94. }, null, { timeout: 20000 });
  95. await mpage.waitForTimeout(600);
  96. await mpage.evaluate(() => {
  97. const v = document.querySelector('kf-app').shadowRoot.querySelector('view-pool');
  98. v.shadowRoot.querySelector('.pbar-more').setAttribute('open', '');
  99. });
  100. await mpage.waitForTimeout(200);
  101. out.one.mobile = await mpage.evaluate(() => {
  102. const v = document.querySelector('kf-app').shadowRoot.querySelector('view-pool').shadowRoot;
  103. const btns = [...v.querySelectorAll('.pbar-sorts button')];
  104. const sel = btns.find((b) => b.getAttribute('aria-pressed') === 'true');
  105. const s = sel ? getComputedStyle(sel) : null;
  106. return sel ? { text: sel.textContent.trim(), bg: s.backgroundColor, color: s.color, fontSize: s.fontSize, lineHeight: s.lineHeight } : { missing: true };
  107. });
  108. await mpage.context().close();
  109. }
  110. /* ======================= 二、报告卡描述(reportCard 的 .lead) =======================
  111. 量 /reports 与 /stages 的每一张 .rc:
  112. - 有无描述(.lead 元素存在且有文字)
  113. - 标题 → 指标区(.m)之间的缝:有描述的卡把这条缝摊给四张卡(flex 平均分),
  114. 无描述的卡应把同一条缝均分到卡内各条缝 —— 不再是 66px 一条空缝
  115. - 内容总高 = .rc 内第一个可见子块顶 → 最后一个子块底
  116. - 最大连续空白 = .rc 内叶子文字矩形按 top 排,相邻两块之间竖直间隙的最大值 */
  117. {
  118. out.two = { pages: [] };
  119. for (const [p, name] of [['/reports', 'view-reports'], ['/stages', 'view-stages']]) {
  120. await gotoView(p, name);
  121. const r = await page.evaluate(`(async () => {
  122. ${DEEP}
  123. const root = appR().querySelector('${name}').shadowRoot;
  124. const cards = [...root.querySelectorAll(".rc")].filter((c) => c.getBoundingClientRect().height > 0 && c.getBoundingClientRect().width > 0);
  125. const cardsInfo = cards.map((c) => {
  126. const lead = c.querySelector('.lead');
  127. const tk = c.querySelector('h3').getBoundingClientRect();
  128. const m = c.querySelector('.m').getBoundingClientRect();
  129. const kids = [...c.children].filter((e) => e.getBoundingClientRect().height > 0);
  130. const first = kids[0].getBoundingClientRect(), last = kids[kids.length - 1].getBoundingClientRect();
  131. /* 叶子文字块:先取最内层的文字元素(祖先容器不重复计,否则父盒扣掉 padding 后会造出假空白)。
  132. display:contents(.src 在手机档里的 .l1/.l2)没有盒,跳过。 */
  133. const textAll = [...c.querySelectorAll('*')].filter((e) => [...e.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim()));
  134. const inner = textAll.filter((e) => !textAll.some((o) => o !== e && e.contains(o)));
  135. const leaves = inner.map((e) => e.getBoundingClientRect()).filter((r) => r.width > 0 && r.height > 0).sort((a, b) => a.top - b.top || a.left - b.left);
  136. let maxGap = 0, gapAt = '';
  137. for (let i = 1; i < leaves.length; i++) {
  138. if (leaves[i].top < leaves[i - 1].bottom - 1) continue;
  139. /* 水平不相交(并排的列)不算卡内纵向空白 */
  140. if (leaves[i].left >= leaves[i - 1].right - 1 || leaves[i - 1].left >= leaves[i].right - 1) continue;
  141. const g = Math.round(leaves[i].top - leaves[i - 1].bottom);
  142. if (g > maxGap) { maxGap = g; gapAt = Math.round(leaves[i - 1].bottom) + '→' + Math.round(leaves[i].top); }
  143. }
  144. /* 卡内每条缝(相邻子块之间),以及每块子块的 stretch 情况 */
  145. const gaps = [];
  146. for (let i = 1; i < kids.length; i++) gaps.push(Math.round(kids[i].getBoundingClientRect().top - kids[i - 1].getBoundingClientRect().bottom));
  147. return { title: (c.querySelector('h3').textContent || '').trim().slice(0, 14),
  148. lead: lead ? lead.textContent.trim().slice(0, 12) : null, leadTxt: lead ? lead.textContent.trim() : '',
  149. gapTitleToM: Math.round(m.top - tk.bottom), contentH: Math.round(last.bottom - first.top),
  150. cardH: Math.round(c.closest('kf-glass-card').getBoundingClientRect().height),
  151. maxGap, gapAt, rowIdx: Math.round(c.getBoundingClientRect().top) };
  152. });
  153. return { n: cardsInfo.length, cards: cardsInfo };
  154. })()`);
  155. /* 同排(top 相同)卡片的等高由 v12 脚本管;这里只记 */
  156. out.two.pages.push({ page: p, ...r });
  157. }
  158. }
  159. /* ======================= 三、页脚类名命中 ======================= */
  160. const FOOT_PROBE = `(async () => {
  161. ${DEEP}
  162. const host = appR().querySelector(location.pathname.includes('reports') ? 'view-reports' : 'view-pool');
  163. const sr = host.shadowRoot;
  164. const foot = sr.querySelector('.cfoot[data-foot]');
  165. if (!foot) return { missing: true, host: host.localName };
  166. /* 1. 页脚里出现的每个类名,逐项查:在宿主 shadow root 的 adoptedStyleSheets 里,是否有规则的选择器能命中它 */
  167. const sheets = [...sr.adoptedStyleSheets, ...[...sr.querySelectorAll('style')].map((s) => s.sheet)];
  168. const rules = [];
  169. const walkRules = (list, media) => { for (const r of list || []) {
  170. if (r.cssRules && !r.selectorText) { walkRules(r.cssRules, r.conditionText || media); continue; }
  171. if (r.selectorText) rules.push({ sel: r.selectorText, media: media || '', css: r.style.cssText.slice(0, 90) });
  172. } };
  173. for (const s of sheets) if (s) { try { walkRules(s.cssRules, ''); } catch { /* 跨源 */ } }
  174. const classes = new Set();
  175. for (const el of [foot, ...foot.querySelectorAll('*')]) {
  176. const cn = typeof el.className === 'string' ? el.className : ''; /* svg 的 className 是 SVGAnimatedString */
  177. for (const c of cn.split(/\\s+/).filter(Boolean)) classes.add((el.localName === 'footer' || !/^(svg|path|circle|line|polyline|rect|g)$/.test(el.localName) ? '' : 'svg:') + c);
  178. }
  179. const hits = [];
  180. for (const c of classes) {
  181. const name = c;
  182. const matching = rules.filter((r) => {
  183. /* 规则选择器里是否以 .name 作为「完整类名」出现(避免 .cfl 命中 .cfleft) */
  184. return new RegExp('\\\\.' + name.replace(/[-]/g, '\\\\-') + '(?![\\\\w-])').test(r.sel);
  185. });
  186. /* 选择器是否真的能作用到页脚里的某个元素 */
  187. const el = [foot, ...foot.querySelectorAll('*')].find((e) => {
  188. const cn = typeof e.className === 'string' ? e.className : '';
  189. return cn.split(/\\s+/).includes(name);
  190. });
  191. const applies = matching.filter((r) => {
  192. if (!el) return false;
  193. try { return el.matches(r.sel.replace(/::?[a-z-]+(\\([^)]*\\))?/g, '')); } catch { return false; }
  194. });
  195. hits.push({ cls: name, tag: el ? elLabel(el).slice(0, 30) : '', rules: matching.length, applies: applies.length, el: el ? elLabel(el).slice(0, 30) : '' });
  196. }
  197. /* 2. 逐元素 computed 快照:footer 本身 + 里面每个元素,按「结构路径」记 */
  198. const snap = (f) => {
  199. const one = (el) => { const s = getComputedStyle(el);
  200. return { padding: [s.paddingTop, s.paddingRight, s.paddingBottom, s.paddingLeft].join(' '),
  201. border: [s.borderTopWidth, s.borderRightWidth, s.borderBottomWidth, s.borderLeftWidth].join(' ') + ' / ' + s.borderTopStyle + ' / ' + s.borderTopColor,
  202. radius: [s.borderTopLeftRadius, s.borderTopRightRadius, s.borderBottomRightRadius, s.borderBottomLeftRadius].join(' '),
  203. font: s.fontSize + '/' + s.lineHeight + ' ' + s.fontWeight, color: s.color, bg: s.backgroundColor,
  204. display: s.display, gap: s.gap, justify: s.justifyContent, marginTop: s.marginTop };
  205. };
  206. const list = [[f, f.parentElement && f.parentElement.classList.contains('cfoot') ? '' : '']];
  207. const path = (el) => { const p = []; for (let q = el; q && q !== f; q = q.parentElement) p.unshift(q.localName + (typeof q.className === 'string' && q.className ? '.' + q.className.trim().split(/\\s+/).join('.') : '')); return p.join('>'); };
  208. const res = { 'cfoot': one(f) };
  209. for (const el of f.querySelectorAll('*')) {
  210. if (['svg', 'path', 'circle', 'line', 'polyline', 'rect', 'g'].includes(el.localName)) continue;
  211. res[path(el)] = one(el);
  212. }
  213. return res;
  214. };
  215. /* 两页页脚根节点不同(/reports 是 <footer>,/pool 是 <span>):键用 cfoot,跨页可比 */
  216. return { host: host.localName, footTag: foot.localName, classes: [...classes], hits, snap: snap(foot), mediaHits: rules.filter((r) => /cfoot|kf-btn/.test(r.sel)).map((r) => ({ sel: r.sel.slice(0, 70), media: r.media, css: r.css.slice(0, 70) })).slice(0, 14) };
  217. })()`;
  218. {
  219. await gotoView('/pool', 'view-pool');
  220. const poolFoot = await page.evaluate(FOOT_PROBE);
  221. await gotoView('/reports', 'view-reports');
  222. const repFoot = await page.evaluate(FOOT_PROBE);
  223. /* 同路径元素逐项比对 */
  224. const paths = Object.keys(poolFoot.snap || {}).filter((k) => k in (repFoot.snap || {}));
  225. const diff = [];
  226. for (const k of paths) {
  227. for (const prop of ['padding', 'border', 'radius', 'font', 'color', 'bg', 'display', 'gap', 'justify', 'marginTop']) {
  228. const a = poolFoot.snap[k][prop], b = repFoot.snap[k][prop];
  229. if (a !== b) diff.push({ path: k, prop, pool: a, reports: b });
  230. }
  231. }
  232. out.three = { pool: poolFoot, reports: repFoot, compared: paths, diff };
  233. }
  234. /* ======================= 汇总判分 ======================= */
  235. const checks = [];
  236. const check = (name, ok, detail) => { checks.push({ name, ok, detail }); console.log(`\n${JUDGE ? (ok ? '✓' : '✗') : '·'} ${name}\n ${detail}`); };
  237. console.log(`\n===== v13 三项验收 · tag=${TAG} =====`);
  238. /* 一 */
  239. {
  240. const o = out.one;
  241. const sel = o.selected, un = o.unselected?.[0];
  242. const composed = sel ? hex(rgb(sel.bg)) : [0, 0, 0];
  243. const selLum = lum(composed), oldLum = lum([24, 24, 27]);
  244. const brighter = composed.some((v) => v > 24);
  245. const fontSame = un && sel.fontSize === un.fontSize && sel.lineHeight === un.lineHeight && sel.h === un.h;
  246. const white = sel && rgb(sel.color).slice(0, 3).every((v) => v === 255);
  247. const radiiZero = o.btns?.every((b) => b.radius === '0px 0px');
  248. const seps1 = o.seps?.slice(1).every((s) => s.left === '1px' && s.leftStyle === 'solid') && o.seps?.[0].left === '0px';
  249. const outerOk = o.outer?.radius === '8px' && o.outer?.border.startsWith('1px solid');
  250. const h28 = o.outer?.h === 28 && o.btns?.every((b) => b.h === 28);
  251. const m = o.mobile || {};
  252. const mComposed = rgb(m.bg || 'rgb(0,0,0)');
  253. const mOk = m.bg && mComposed.slice(0, 3).some((v) => v > 24) && !(rgb(m.color || '').slice(0, 3).every((v) => v === 255));
  254. check('一 排序段:选中浅底不白字 / 字级一致 / 一整块 1px 分隔 / 高 28', brighter && !white && fontSame && radiiZero && seps1 && outerOk && h28 && mOk,
  255. `选中「${sel?.text}」bg=${sel?.bg} → 叠白底后 ${composed}(亮度 ${selLum.toFixed(1)},旧 rgb(24,24,27) 亮度 ${oldLum.toFixed(1)}),字色 ${sel?.color}` +
  256. `;未选中 ${un?.bg} / ${un?.color};font-size 选中 ${sel?.fontSize} vs 未选中 ${un?.fontSize},line-height ${sel?.lineHeight} vs ${un?.lineHeight},框高 ${sel?.h} vs ${un?.h}` +
  257. `;按钮圆角 [${o.btns?.map((b) => b.radius).join(' | ')}],分隔线 [${o.seps?.map((s) => s.left).join(',')}]` +
  258. `;外层 radius ${o.outer?.radius} border ${o.outer?.border} 高 ${o.outer?.h}` +
  259. `;手机选中 bg=${m.bg} 字色 ${m.color} 字号 ${m.fontSize}`);
  260. }
  261. /* 二 */
  262. function avg(arr, k) { return arr.reduce((n, x) => n + x[k], 0) / arr.length; }
  263. {
  264. const parts = out.two.pages.map((pg) => {
  265. const withD = pg.cards.filter((c) => c.lead), without = pg.cards.filter((c) => !c.lead);
  266. const dh = withD.length && without.length ? Math.abs(avg(withD, 'contentH') - avg(without, 'contentH')) : null;
  267. const maxGap = Math.max(...pg.cards.map((c) => c.maxGap));
  268. const gapW = withD.length ? avg(withD, 'gapTitleToM') : 0;
  269. const gapN = without.length ? avg(without, 'gapTitleToM') : 0;
  270. const sameRow = new Set(pg.cards.filter((c) => !c.lead).map((c) => c.cardH));
  271. return { pg, withD, without, dh, maxGap, gapW, gapN, sameRow,
  272. ok: !without.length || (dh !== null && dh <= 40 && maxGap <= 24 && gapN < gapW * 0.8 && sameRow.size === 1) };
  273. });
  274. check('二 空描述卡:不渲染描述区 + 卡内重新均分 + 内容高差 ≤ 40px + 卡内空白 ≤ 24px',
  275. parts.every((x) => x.ok),
  276. parts.map(({ pg, withD, without, dh, maxGap, gapW, gapN, sameRow }) =>
  277. `${pg.page}:共 ${pg.n} 张,无描述 ${without.length} 张(${without.map((c) => c.title).join('、') || '—'})` +
  278. `;有描述卡 gap(标题→指标) 均值 ${gapW.toFixed(1)}px / 无描述卡 ${gapN.toFixed(1)}px` +
  279. `;内容高 有描述 [${withD.map((c) => c.contentH).join(',')}] 无描述 [${without.map((c) => c.contentH).join(',')}] 差 ${dh == null ? '—' : dh.toFixed(1) + 'px'}` +
  280. `;无描述卡高去重 [${[...sameRow].join(',')}];最大连续空白 ${maxGap}px`).join('\n '));
  281. }
  282. /* 三 */
  283. {
  284. const t = out.three;
  285. const poolMiss = (t.pool?.hits || []).filter((h) => h.applies === 0);
  286. const comp = t.compared || [];
  287. const same = comp.filter((p) => !t.diff.some((d) => d.path === p));
  288. check('三 /pool 页脚类名逐项命中(每个类名 ≥1 条生效规则)+ 与 /reports 同名元素 computed 逐项相等',
  289. !t.pool?.missing && poolMiss.length === 0 && comp.length >= 3 && (t.pool.classes || []).every((c) => (t.pool.hits || []).some((h) => h.cls === c && h.applies > 0)) && t.diff.length === 0,
  290. `类名 ${t.pool?.classes?.length} 个:${(t.pool?.hits || []).map((h) => `${h.cls}(${h.applies} 条生效/${h.rules} 条含)${h.applies ? '' : '✗'}`).join('、')}` +
  291. `;与 /reports 比对 ${comp.length} 个元素 × ${['padding', 'border', 'radius', 'font', 'color', 'bg', 'display', 'gap', 'justify', 'marginTop'].length} 项,一致 ${same.length},不一致 ${t.diff.length}` +
  292. (t.diff.length ? '\n ' + t.diff.slice(0, 8).map((d) => `${d.path}.${d.prop}: pool=${d.pool} reports=${d.reports}`).join('\n ') : ''));
  293. }
  294. /* ======================= v12 回归:同原脚本判分(不能退步) ======================= */
  295. console.log('\n----- v12 回归(子进程跑 verify-visual-v12.mjs) -----');
  296. const { spawnSync } = await import('node:child_process');
  297. const reg = spawnSync(process.execPath, [join(ROOT, 'scripts/verify-visual-v12.mjs'), '--json', 'tmp/v13-v12-after.json'], { encoding: 'utf8', env: { ...process.env, VERIFY_PORT: '4195' } });
  298. const regLines = (reg.stdout || '').split('\n');
  299. console.log(regLines.filter((l) => /^(✓|✗) |判分:/.test(l) || /^ /.test(l) && false).join('\n'));
  300. const regLine = regLines.find((l) => /^判分:/.test(l)) || '(v12 脚本无输出)';
  301. const [, pass, total] = regLine.match(/(\d+)\/(\d+)/) || [];
  302. out.v12 = { pass: Number(pass), total: Number(total), line: regLine, fails: regLines.filter((l) => l.startsWith('✗')).map((l) => l.slice(2)) };
  303. check('v12 回归不退步', out.v12.pass >= 11, `${regLine};未达标:${out.v12.fails.join('、') || '无'}`);
  304. if (errors.length) console.log(`\n页面错误 ${errors.length}:\n ${[...new Set(errors)].slice(0, 10).join('\n ')}`);
  305. const fail = checks.filter((c) => !c.ok);
  306. console.log(`\n${JUDGE ? '判分' : '基线(不判分)'}:${checks.length - fail.length}/${checks.length} 达标${errors.length ? `,页面错误 ${errors.length}` : ''}`);
  307. if (JSON_OUT) {
  308. mkdirSync(dirname(join(ROOT, JSON_OUT)), { recursive: true });
  309. writeFileSync(join(ROOT, JSON_OUT), JSON.stringify({ ...out, checks, errors }, null, 2));
  310. }
  311. await browser.close();
  312. srv.kill();
  313. process.exit(JUDGE && (fail.length || errors.length) ? 1 : 0);