Files
novalon-website/docs/acceptance/2026-10-24-full-qa/tools/baseline-review.mjs
T
zhangxiang 763e159ac4 docs(acceptance): 两轮全站验收读数 + 复现脚本 + 企微资产包入库(OPEN-12)
按「这条结论怎么来的必须入库,排查当时的截图只服务当时」的既有口径,
把此前一直悬在 git status 里、归属未定的产物逐组落定:

入库(7.2MB):
- docs/acceptance/2026-10-21-full-qa/、2026-10-24-full-qa/ 的文字与结构化读数
  (README / defects*.json / sweep/summary.json / axe evidence / lighthouse /
  report.json 逐 run 原始读数 / tools 复现脚本)
- docs/acceptance/2026-11-26-axe/ 本轮 axe 复跑证据(35 路由 × 4 组合 140 rows 全 0)
- scripts/acceptance/{sweep-routes,contact-sheet}.mjs —— 两轮 README 里被引用的
  复现脚本,不提交则结论不可复算
- deliverables/.../wecom-pack.cjs + check-wecom.py + WECOM-MANIFEST.md +
  assets-wecom/pack-report.json(生成器/校验器/清单;18 张 PNG 可由脚本从已入库
  SVG 重新栅格化,故仍按既有规则忽略)

忽略(不提交,已写进 .gitignore 并注明归属):
- 两轮验收的逐页截图(172MB):只在排查当时有用
- infra/cicd/gitea{,-custom}/ + 2026-10-22-gitea-branding/(340KB):
  归 feature/gitea-branding,逐文件 sha256 与该分支 50/50 完全一致,
  在本分支提交会造成同一批文件的两份历史

判据:提交后 git status -uall 只剩被忽略项;每条 ?? 都能回答「归谁、为什么在这里」。
2026-11-26 20:03:46 +08:00

128 lines
5.3 KiB
JavaScript

// 2026-10-24 新增视觉基线的清单 + 拼版工具(只读 e2e/visual-snapshots,只在证据目录写产物)
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
import sharp from 'sharp';
const ROOT = '/Users/zhangxiang/Codes/Novalon/novalon-website';
const EV = path.join(ROOT, 'docs/acceptance/2026-10-24-full-qa');
const SNAP = path.join(ROOT, 'e2e/visual-snapshots');
const OUT = path.join(EV, 'contact-sheets/baselines');
fs.mkdirSync(OUT, { recursive: true });
const PROJECTS = [
'visual-chromium-desktop',
'visual-chromium-tablet',
'visual-chromium-mobile',
'visual-firefox-desktop',
'visual-webkit-desktop',
];
const ROUTES = [
['not-found', '/_not-found'],
['cases', '/cases'],
['insights', '/insights'],
['news-digital-transformation', '/news/digital-transformation-solution'],
['privacy', '/privacy'],
['terms', '/terms'],
['product-bi', '/products/bi'],
['product-cms', '/products/cms'],
['product-crm', '/products/crm'],
['product-oa', '/products/oa'],
['product-sds', '/products/sds'],
['product-erp-upgrade-v3', '/products/erp-upgrade-v3'],
['service-consulting', '/services/consulting'],
['service-data', '/services/data'],
['service-solutions', '/services/solutions'],
['solution-education', '/solutions/education'],
['solution-finance', '/solutions/finance'],
['solution-healthcare', '/solutions/healthcare'],
['solution-logistics', '/solutions/logistics'],
['solution-retail', '/solutions/retail'],
];
const sha256 = (buf) => crypto.createHash('sha256').update(buf).digest('hex');
const esc = (s) => s.replace(/[<>&'"]/g, (c) => ({ '<': '&lt;', '>': '&gt;', '&': '&amp;', "'": '&apos;', '"': '&quot;' }[c]));
const manifest = [];
for (const project of PROJECTS) {
for (const [name, route] of ROUTES) {
const file = path.join(SNAP, project, 'visual-regression.spec.ts', `${name}-fullpage-${project}.png`);
if (!fs.existsSync(file)) {
manifest.push({ project, name, route, file, exists: false });
continue;
}
const buf = fs.readFileSync(file);
const meta = await sharp(buf).metadata();
const stats = await sharp(buf).stats();
const channels = stats.channels.slice(0, 3);
const stdev = Math.max(...channels.map((c) => c.stdev));
const entropy = Math.max(...channels.map((c) => c.entropy));
manifest.push({
project,
name,
route,
file: path.relative(ROOT, file),
exists: true,
width: meta.width,
height: meta.height,
bytes: buf.length,
sha256: sha256(buf),
maxChannelStdev: +stdev.toFixed(2),
maxChannelEntropy: +entropy.toFixed(3),
blankSuspicion: stdev < 6 || entropy < 1.2,
});
}
}
fs.writeFileSync(path.join(EV, 'baseline-manifest.json'), JSON.stringify(manifest, null, 2));
console.log(`manifest=${manifest.length} missing=${manifest.filter((m) => !m.exists).length} blankSuspicion=${manifest.filter((m) => m.blankSuspicion).length}`);
async function labeledTile(file, width, cropTop) {
let src = await sharp(file).resize({ width, withoutEnlargement: true }).jpeg({ quality: 80 }).toBuffer();
let m = await sharp(src).metadata();
if (cropTop && m.height > cropTop) {
src = await sharp(src).extract({ left: 0, top: 0, width: m.width, height: cropTop }).jpeg({ quality: 80 }).toBuffer();
m = await sharp(src).metadata();
}
const label = Buffer.from(
`<svg width="${m.width}" height="24" xmlns="http://www.w3.org/2000/svg">`
+ `<rect width="${m.width}" height="24" fill="#fff"/>`
+ `<text x="4" y="16" font-family="Helvetica,Arial,sans-serif" font-size="11" fill="#111">${esc(path.basename(file).replace('-fullpage-' + path.basename(path.dirname(path.dirname(file))) + '.png', ''))}</text></svg>`,
);
return {
buf: await sharp({ create: { width: m.width, height: m.height + 24, channels: 3, background: '#fff' } })
.composite([{ input: src, top: 0, left: 0 }, { input: label, top: m.height, left: 0 }])
.jpeg({ quality: 82 }).toBuffer(),
height: m.height + 24,
};
}
async function sheet(files, out, width, cols, cropTop) {
const tiles = [];
for (const f of files) tiles.push(await labeledTile(f, width, cropTop));
const rows = [];
for (let i = 0; i < tiles.length; i += cols) rows.push(tiles.slice(i, i + cols));
const gap = 8;
const heights = rows.map((r) => Math.max(...r.map((t) => t.height)));
const w = cols * width + (cols - 1) * gap;
const h = heights.reduce((a, b) => a + b, 0) + (rows.length - 1) * gap;
const comps = [];
let y = 0;
rows.forEach((r, ri) => {
let x = 0;
r.forEach((t) => { comps.push({ input: t.buf, top: y, left: x }); x += width + gap; });
y += heights[ri] + gap;
});
await sharp({ create: { width: w, height: h, channels: 3, background: '#fff' } })
.composite(comps).jpeg({ quality: 80 }).toFile(out);
console.log(`sheet ${path.basename(out)} ${files.length} tiles ${w}x${h}`);
}
for (const project of PROJECTS) {
const files = ROUTES.map(([name]) => path.join(SNAP, project, 'visual-regression.spec.ts', `${name}-fullpage-${project}.png`)).filter(fs.existsSync);
await sheet(files, path.join(OUT, `${project}__top.jpg`), 300, 5, 900);
for (let i = 0; i < files.length; i += 5) {
await sheet(files.slice(i, i + 5), path.join(OUT, `${project}__full-${String(i / 5 + 1).padStart(2, '0')}.jpg`), 300, 5, 0);
}
}