feat(tools): fidelity 加分区域阈值(抓全屏百分比淹没的局部错位)

针对「顶栏右组错位全屏 diff 3.5% 没报红」的盲区:
- screens.mjs shell 加 zones(顶栏/侧栏/状态栏逻辑坐标 + 各自紧阈,顶栏收到 4%)
- fidelity.mjs:有 zones 时全屏仅参考,逐 zone 判定(按 dpr crop)
- skill diff.mjs 加 --crop 仅比矩形区域(全局工具,不在本 repo)
- 验证:错位版 golden 顶栏带 9.48% > 4% 报红;修正版 3.16% 通过

仍存盲区:弹出态(用户菜单/dropdown/dialog)不进静态 golden,需单独补浮层 golden。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TSKEiHsvauyxYUW2itzUXX
This commit is contained in:
wangjia
2026-06-25 18:21:15 +08:00
parent f9668848b6
commit 15d825125d
2 changed files with 43 additions and 11 deletions
+33 -9
View File
@@ -97,16 +97,40 @@ for (const name of targets) {
failed++; continue;
}
// ③ diff,超「该屏校准阈值」即红
ran++;
try {
execFileSync('node', [diff, proto, golden, out,
'--threshold', String(s.threshold), '--tolerance', values.tolerance],
{ stdio: 'inherit' });
console.log(`[fidelity] ✅ ${name}·${theme} ≤ 阈值 ${(s.threshold * 100).toFixed(1)}%`);
} catch {
console.error(`[fidelity] ❌ ${name}·${theme} 超阈 ${(s.threshold * 100).toFixed(1)}% — 看 ${out}`);
failed++;
if (s.zones && s.zones.length) {
// 分区域判定:全屏 diff 仅参考(不判定,避免内容区差异淹没局部错位),
// 真正判定逐 zone(顶栏/侧栏/状态栏各自紧阈),抓全屏百分比看不到的局部偏移。
try {
execFileSync('node', [diff, proto, golden, out,
'--threshold', '1', '--tolerance', values.tolerance], { stdio: 'pipe' });
} catch { /* 全屏仅参考 */ }
let zoneFail = 0;
for (const z of s.zones) {
const zout = join(diffDir, `${s.prefix}_${theme}_${z.name}_diff.png`);
const crop = [z.x * s.dpr, z.y * s.dpr, z.w * s.dpr, z.h * s.dpr].join(',');
try {
execFileSync('node', [diff, proto, golden, zout,
'--threshold', String(z.threshold), '--tolerance', values.tolerance,
'--crop', crop], { stdio: 'inherit' });
console.log(`[fidelity] ✅ ${name}·${theme}·${z.name}${(z.threshold * 100).toFixed(1)}%`);
} catch {
console.error(`[fidelity] ❌ ${name}·${theme}·${z.name} 超阈 ${(z.threshold * 100).toFixed(1)}% — 看 ${zout}`);
zoneFail++;
}
}
if (zoneFail) failed++;
} else {
// ③ 整屏 diff,超「该屏校准阈值」即红
try {
execFileSync('node', [diff, proto, golden, out,
'--threshold', String(s.threshold), '--tolerance', values.tolerance],
{ stdio: 'inherit' });
console.log(`[fidelity] ✅ ${name}·${theme} ≤ 阈值 ${(s.threshold * 100).toFixed(1)}%`);
} catch {
console.error(`[fidelity] ❌ ${name}·${theme} 超阈 ${(s.threshold * 100).toFixed(1)}% — 看 ${out}`);
failed++;
}
}
}
}