§12.10 挂的账(113 vs 预测 104 的 +9 无从归因)根因是上一轮只留了聚合数没留名单。
本轮把「聚合数经不起追问」这一类本身修掉:
- 新增 scripts/visual-manifest.mjs:Playwright 文本输出 → {project, at, title, status} 逐名清单,
退出码 0 全通过 / 1 有 failed / 2 未能度量(解析不到任何用例行 ⇒ 不与"全绿"共用 0)。
三份读数入库:终版只读 total=125 failed=0;--radius-cta=12px total=25 failed=15;空日志 ⇒ EXIT=2。
- 差集对账:重采 113 + 未重写 12 = 125(--list 实取 Total: 125 tests in 1 file)。
未重写的 12 张具名为 input-default/focused ×4 桌面类 project、mobile 的 button-* 3 张与 header-navigation。
- 删除 5 张孤儿参照 founder-quote-section-*:该区块按 ADR-0008 决策一已退役,
spec:180 早改成 toHaveCount(0) 反向守卫 ⇒ 参照留在盘上只会骗下一轮的人。
删后每 project 恰好 25 张,与用例数逐 project 相等(manual-acceptance/ 2 张非断言参照另计)。
- 自报一次仪器错配:我第一版拿中文用例名去匹配 slug 文件名,键型不匹配 ⇒ 得出"125 张都没重写"的假结论。
44 lines
2.3 KiB
JavaScript
44 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
||
/**
|
||
* 把 Playwright 的文本输出转成**逐名清单**(name / project / status)。
|
||
*
|
||
* 为什么要它:§11.6 记的是「104 failed / 21 passed」这样一个**聚合数**,
|
||
* 没有名单 ⇒ 本轮重采实取 113 张时,那 +9 无法从证据归因,只能写「推断」。
|
||
* 聚合数经不起二次追问,逐名清单才可以。纪律同 §5.42/§5.45:
|
||
* **计数为 0 一律走「未能度量」(EXIT=2),不与"全部通过"共用 0**。
|
||
*
|
||
* 用法:node scripts/visual-manifest.mjs <log> <out.json>
|
||
* 0 = 解析成功且计数>0 · 1 = 有 failed 项 · 2 = 未能度量(解析不到任何用例行)
|
||
*/
|
||
import { readFileSync, writeFileSync } from 'node:fs';
|
||
|
||
const [, , logPath, outPath] = process.argv;
|
||
if (!logPath || !outPath) { console.error('用法:visual-manifest.mjs <playwright 日志> <输出 json>'); process.exit(2); }
|
||
|
||
const text = readFileSync(logPath, 'utf8');
|
||
// Playwright 的行形如: ✘ 25 [visual-chromium-desktop] › visual-regression.spec.ts:76:9 › 分组 › 用例名 (3.1s)
|
||
// ✓ 3 [visual-webkit-desktop] › …
|
||
const RE = /^[✘✓─\s|]*[✓✘✖×]?\s*[✓✘]?\s*\d+\s+\[([a-z0-9-]+)\]\s+›\s+(\S+:\d+:\d+)\s+›\s+(.+?)\s*(?:\((?:[\d.]+)(?:ms|s)\))?\s*$/;
|
||
const rows = [];
|
||
for (const line of text.split('\n')) {
|
||
const passed = line.includes('✓');
|
||
const failed = /[✘✖]|✗/.test(line) || line.includes('×');
|
||
if (!passed && !failed) continue;
|
||
const m = line.match(RE);
|
||
if (!m) continue;
|
||
rows.push({ project: m[1], at: m[2], title: m[3].trim(), status: passed ? 'passed' : 'failed' });
|
||
}
|
||
|
||
const uniq = new Map();
|
||
for (const r of rows) uniq.set(`${r.project}::${r.at}::${r.title}`, r);
|
||
const manifest = [...uniq.values()].sort((a, b) => `${a.project}${a.at}`.localeCompare(`${b.project}${b.at}`));
|
||
const failed = manifest.filter((m) => m.status === 'failed').length;
|
||
|
||
if (manifest.length === 0) {
|
||
console.error(`未能度量:${logPath} 里解析不到任何用例行(不是"全部通过")`);
|
||
process.exit(2);
|
||
}
|
||
writeFileSync(outPath, JSON.stringify({ source: logPath, total: manifest.length, failed, passed: manifest.length - failed, cases: manifest }, null, 2));
|
||
console.log(`逐名清单写出 ${outPath}:total=${manifest.length} passed=${manifest.length - failed} failed=${failed}`);
|
||
process.exit(failed > 0 ? 1 : 0);
|