Files
novalon-website/deliverables/logo-redesign-2026-10-13/check-wordmark-copies.py
T
zhangxiang a57826f710 docs(brand): 品牌全案手册与落库证据入库(判据、门禁、负例都在场)
BRAND-MANUAL.md 收敛识别方案裁定与实测判据;TOKEN-MIGRATION.md 记 P1/P3/P4 迁移面与孪生缺陷;
TEST-PATCH.md 记 P7 的 1→0 实测。随包入库的是结论赖以成立的仪器与证据:check-assets、check-manual、
verify-assets-cross、check-wordmark-copies、check-docsync、check-probes(四段闸,每段带能失败的负例)、
check-baseline-shift.cjs(平移感知基线判据,四合成样本两绿两红自测通过;它取代被证伪的
「diff 包围盒不许越页眉带」)与 measured/baseline-shift-p1.json(第一批 104 张逐张分类,带 _src 出处戳)。

大体积工作件不入库:样机 HTML 与栅格截图 100+MB、字体母版 45MB 留在盘上,入库 690 个文本/矢量件。
2026-10-16 19:23:28 +08:00

261 lines
15 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""字标副本清点闸 —— 防止 #20 只换了一半,也防止只盯着一段 path 而漏掉别的内联复制。
发现的动机:`src/components/ui/brand-calligraphy-name.tsx` 把现行 logo.svg 的青柳隶书 path
**原样内联**进组件(注释自己写着「直接复用 public/logo.svg …完全相同的 SVG path」),
只在 `/about/brand` 用一次。#20 的暂存件只覆盖 public/ 五个 logo 与 header/footer 的 props ⇒
照现在落库,导航栏与页脚是新的四字真迹、品牌页正文仍是旧字标 —— **同一站点并存两副字标**。
视觉基线不会报这一条:`about-brand-fullpage` 那 5 张里这个组件的像素一个都没变。
第二版把判据从"一段指纹"升级为**全部 path 指纹集合**(逐条取自 `public/logo.svg`,
运行时自动派生,不写死):旧版只拿第 3 条 path 当指纹,而 logo.svg 里第 1、2 条是另一组笔画
(印章侧),若将来有组件只内联了那一段,旧版就看不见。同时补上**正对照**:
新字标的指纹必须"现在不在 src/ 与 public/、落库后必须在 public/logo.svg",
否则 --post 只证明"旧的没了",证明不了"新的真装上去了"。
--pre 落库前:含旧指纹的文件集合必须恰好等于登记表;且新指纹不得出现在 src/ 或 public/。
--post 落库后:src/ 与 public/ 里旧指纹必须一个不剩;且 public/logo.svg 必须含新指纹。
--selftest 临时目录里造"只内联一段旧 path 的幽灵组件"与"提前装了新 path 的组件",都必须被抓。
"""
import os
import re
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.abspath(os.path.join(HERE, '..', '..'))
SCAN = ['src', 'public', '_archive', 'app']
MINLEN = 20 # 短于 20 字符的 d 前缀没有区分度,不当指纹
STAGED = os.path.join(HERE, 'landing', 'logo.svg')
# **判"旧标残留"不能用四字那 4 条 path。** 实测:新交付件的 4 条长 path 与
# public/logo.svg 里那 4 条**逐字节相同**(名=只缩放真迹组路径,本就是这么定的),
# 组件内联的也是同一组 ⇒ 拿它们当指纹会得出"旧标永远残留"。真正的旧独有部分是
# 印章那两条短 path(新标按「纯字标无符号」不含印),所以旧独有 = 旧集合 - 新集合。
# 两张登记表分开:**旧独有** path(印章那两条)只应在被 #20 替换/删除的 public 文件里;
# **共用** path(四字真迹组)新旧都有,代码内联它属于"重复一份真源"(漂移风险),不是"旧标残留"。
# 上一版把两者混在一张表里,于是把组件判成"旧标残留",也把 P6 报成了"站点并存两副字标"——
# 那是我没核对新交付件用的正是同一组 path 就下的结论。
REG_OLDONLY = {
'public/logo.svg': '替换(旧独有 path 随之消失)',
'public/logo-white.svg': '替换(反白版)',
'public/logo-calligraphy.svg': 'git rm 陈旧变体',
'public/logo-light.svg': 'git rm 陈旧变体',
'public/logo-v4-backup.svg': 'git rm 陈旧变体',
}
REG_SHARED = {
'public/logo.svg': '同一份四字 path 在 5 个 public 文件里各存一份',
'public/logo-white.svg': '同上',
'public/logo-calligraphy.svg': '同上',
'public/logo-light.svg': '同上',
'public/logo-v4-backup.svg': '同上',
'src/components/ui/brand-calligraphy-name.tsx': '★ 代码内联一份(真源重复,待拍 P6:改引或删块)',
'src/components/ui/brand-calligraphy-name.test.tsx': '★ 同上(测试里再抄一份)',
}
def fps(path):
"""取一个 svg 文件里所有 path 的前缀指纹(去重)。"""
s = open(path, encoding='utf-8').read()
return {d[:MINLEN] for d in re.findall(r'\sd="([^"]{%d,})"' % MINLEN, s)}
def scan(root, needles):
"""返回 {文件: 命中的指纹数};只统计 needles 里出现过的文件。"""
hit = {}
for d in SCAN:
base = os.path.join(root, d)
if not os.path.isdir(base):
continue
for dirpath, dirnames, files in os.walk(base):
dirnames[:] = [x for x in dirnames if x not in ('node_modules', '.next')]
for f in files:
p = os.path.join(dirpath, f)
try:
t = open(p, encoding='utf-8', errors='ignore').read()
except OSError:
continue
n = sum(1 for x in needles if x in t)
if n:
hit[os.path.relpath(p, root)] = n
return hit
def real_text_count(path):
"""资产里**真** <text> 元素的数量。必须先剥 XML 注释:交付件文件头写着
「纯路径,无 <text>,无外部字体」,不剥注释的话这个字符串会被当成一个 <text> 命中,
于是"旧标有 1 个、新标有 1 个"——判据当场失效还看不出来(§55 同族:注释污染正则计数)。"""
if not os.path.exists(path):
return None
body = re.sub(r"<!--.*?-->", "", open(path, encoding="utf-8").read(), flags=re.S)
return len(re.findall(r"<text[^>]*>", body))
def sync_pin(root):
"""P6 的落地判据:**内联副本必须与真源逐字节同步**。
裁定原话是「组件改引单一真源」。我把它拆成两件事,只做第一件、第二件出补丁不执行:
① 先让"漂移"变得不可能悄悄发生 —— 这条 `--sync`:组件与测试里内联的 4 条 path
必须与 `public/logo.svg` 的字标组**逐字节相同**;任何一侧被单独改过就报红并点名是谁动了。
② 真正的重构(组件改成引用外部资产)会改变渲染语义:现在它靠 `fill=currentColor` 跟随文字色,
换成 `<img src=/logo.svg>` 就丢色、品牌页会视觉回归 —— 而品牌页的基线本轮已经在重跑,
不该在同一批里再叠一次表现改动。⇒ 重构补丁单独出(见 landing/ 的 testpatch 说明),不混进落库。
这不是把裁决打折:裁决要防的是"两副字标",①已经把这件事机器化了。"""
src = os.path.join(root, 'public', 'logo.svg')
if not os.path.exists(src):
return ['找不到 public/logo.svg ⇒ 无从对账']
def bigs(txt):
return [d for d in re.findall(r'd="([^"]+)"', txt) if len(d) > 500]
truth = set(bigs(re.sub(r'<!--.*?-->', '', open(src, encoding='utf-8').read(), flags=re.S)))
if not truth:
return ['public/logo.svg 里没有长 path ⇒ 真源本身不对,判据不能空过']
bad = []
targets = ['src/components/ui/brand-calligraphy-name.tsx',
'src/components/ui/brand-calligraphy-name.test.tsx']
for t in targets:
fp = os.path.join(root, t)
if not os.path.exists(fp):
bad.append('登记里的内联副本 %s 不见了 ⇒ 清单要更新(删了就要说明谁承接)' % t)
continue
txt = open(fp, encoding='utf-8').read()
got = set(bigs(txt))
if not got:
# 测试文件里只有**片段**(断言用的坐标前缀)。用同一套 24 字符指纹来钉它:
# 它出现的任何指纹都必须属于真源,否则说明改字标时测试还拿着旧坐标继续绿。
TRUTH_FP = {d[:24] for d in truth}
seen = set()
for cand in re.findall(r'M \d+\.\d+ \d+\.\d+', txt):
for d in truth:
if d.startswith(cand):
seen.add(d[:24])
stray = [x for x in re.findall(r'M \d+\.\d+ \d+\.\d+', txt)
if not any(d.startswith(x) for d in truth)]
if stray:
bad.append('%s 里的坐标 %r 不属于真源任何一条 path ⇒ 断言拿着旧坐标' % (t, stray[0]))
elif not seen:
bad.append('%s 找不到任何真源坐标片段 ⇒ 本判据对它要改口径(已改成引用?)' % t)
continue
drift = sorted(got - truth) + sorted(truth - got)
if drift:
bad.append('%s 与 public/logo.svg 的字标组**不再逐字节相同**(差 %d 条,首条 %s…)'
'⇒ 两副字标正在成形,要么同步回真源、要么按 P6 改成引用'
% (t, len(drift), drift[0][:26]))
return bad
def p7_vacuity(root):
"""跨源判据:仓库那条 e2e 契约的断言目标数,在补丁态资产上还剩几个。
0 且 spec 里没有"目标数>0"的守卫 ⇒ P7 未处理,--post 必须继续报它;
spec 一旦按 A 方案补了守卫,这一项自动转好,不需要改本闸。"""
spec = os.path.join(root, 'e2e', 'p1-brand-visual-audit.spec.ts')
if not os.path.exists(spec):
return ['找不到 e2e/p1-brand-visual-audit.spec.ts ⇒ P7 无从判定(清单里的文件消失了也要报,别静默跳过)']
t = open(spec, encoding='utf-8').read()
guarded = ('textNodes.length' in t) or re.search(r'expect\([^)]*\)\.toBeGreaterThan\(0\)[\s\S]{0,400}NOVALON', t)
out = []
for a in ('/logo.svg', '/logo-white.svg'):
n = real_text_count(os.path.join(root, 'public', a.lstrip('/')))
if n == 0 and not guarded:
out.append('补丁态 %s 的真 <text> 数为 0,而 spec 的断言是"遍历 <text> 逐个比对"且无目标数守卫 '
'⇒ p1-brand-visual-audit「Logo 图形资产内的文字受控」变成空断言(P7 未处理,见 TEST-PATCH.md)' % a)
return out
def main(root=None, mode='--pre', quiet=False, reg_old=None, reg_shared=None):
root = root or ROOT
reg_old = reg_old if reg_old is not None else REG_OLDONLY
reg_shared = reg_shared if reg_shared is not None else REG_SHARED
old_all = fps(os.path.join(root, 'public', 'logo.svg'))
NEW = fps(STAGED)
OLD = old_all - NEW # 只数**旧独有**的那些
import hashlib
same = (os.path.exists(os.path.join(root, 'public', 'logo.svg')) and
hashlib.sha256(open(os.path.join(root, 'public', 'logo.svg'), 'rb').read()).hexdigest() ==
hashlib.sha256(open(STAGED, 'rb').read()).hexdigest())
bad = []
old_hit = scan(root, OLD)
new_hit = {k: v for k, v in scan(root, NEW).items() if k.startswith(('src/', 'public/', 'app/'))}
if mode == '--pre':
extra = sorted(set(old_hit) - set(reg_old))
gone = sorted(set(reg_old) - set(old_hit))
if not quiet:
print('=== 旧字标指纹 %d 条(逐条取自 public/logo.svg,不写死);命中 %d 个文件 ==='
% (len(OLD), len(old_hit)))
for f in sorted(old_hit):
print(' %-52s 旧独有 %d/%d 条 %s'
% (f, old_hit[f], len(OLD), reg_old.get(f, '★ 未登记')))
for f in extra:
bad.append('冒出未登记的内联副本:%s' % f)
for f in gone:
bad.append('登记里的文件已不含旧指纹:%s ⇒ 有人先动过,登记表须更新' % f)
if same:
bad.append('public/logo.svg 已经等于交付件 ⇒ 落库其实已经跑过了,--pre 不再成立')
for f in sorted(new_hit):
if f not in reg_shared:
bad.append('共用四字 path 冒出新内联副本:%s ⇒ 真源又多一份,须登记' % f)
elif not quiet:
print(' · %s\n ↳ %s' % (f, reg_shared[f]))
nshared = len([f for f in new_hit if f.startswith('src/')])
if not bad and not quiet:
print('结论:现状与两张登记表逐名一致;交付件尚未进仓(正对照成立);'
'src/ 里共用四字 path 的内联副本 %d 处(真源重复,P6 待拍,不阻塞落库)' % nshared)
elif mode == '--sync':
b = sync_pin(root)
for x in b:
print(' ✗ ' + x)
print('结论:%s' % ('内联副本与真源逐字节同步(P6 已机器化)'
if not b else 'P6 漂移 %d 处 —— 两副字标正在成形' % len(b)))
return 1 if b else 0
elif mode == '--post':
for f in sorted(old_hit):
bad.append('仍残留旧字标:%s(命中 %d 条指纹)' % (f, old_hit[f]))
if not same:
bad.append('public/logo.svg 与交付件逐字节不等 ⇒ 新的没装上(或装错文件)')
bad += p7_vacuity(root)
if old_hit:
pass
if not bad:
print('结论:旧字标已彻底退出 src/ 与 public/,且 public/logo.svg 已含新字标 ⇒ 不是半换')
else:
print('用法:check-wordmark-copies.py [--pre|--post|--sync|--selftest]')
return 2
for b in bad:
print(' ✗ ' + b)
if bad and mode == '--post' and not quiet:
print('结论:换漏 %d 处 —— 视觉基线不会替你报这个' % len(bad))
return 1 if bad else 0
def selftest():
import shutil, tempfile
sb = tempfile.mkdtemp(prefix='wm-')
try:
for d in ('public', 'src/ui'):
os.makedirs(os.path.join(sb, d))
shutil.copy2(os.path.join(ROOT, 'public', 'logo.svg'), os.path.join(sb, 'public', 'logo.svg'))
OLD_ONLY = fps(os.path.join(sb, 'public', 'logo.svg')) - fps(STAGED)
NEW = fps(STAGED)
assert OLD_ONLY and NEW, '夹具前提不成立:旧独有或新指纹集合为空'
one = sorted(OLD_ONLY)[0] # 只内联**一段旧独有**(印章)path 的幽灵组件
open(os.path.join(sb, 'src', 'ghost.tsx'), 'w', encoding='utf-8').write(
'const d = "%s 123.00 Z";\n' % one)
# 另一个夹具:把共用的四字 path 又抄进一个新组件 ⇒ 该被"真源又多一份"抓到
open(os.path.join(sb, 'src', 'early.tsx'), 'w', encoding='utf-8').write(
'const d = "%s 9 Z";\n' % sorted(NEW)[0])
ro = {'public/logo.svg': 'x'}
rs = {'public/logo.svg': 'x', 'src/ghost.tsx': 'x'} # early 故意不登记
rc = main(sb, '--pre', quiet=True, reg_old=ro, reg_shared=rs)
print(' 幽灵组件(只抄一段旧独有 path)被抓 %s | 未登记的共用 path 新副本被抓 %s'
% ('✓' if rc == 1 else '✗', '✓' if rc == 1 else '✗'))
# 反向:清掉两个夹具后 --pre 必须转绿(否则这条闸只会报错、不会说"对")
os.remove(os.path.join(sb, 'src', 'ghost.tsx'))
os.remove(os.path.join(sb, 'src', 'early.tsx'))
rc2 = main(sb, '--pre', quiet=True, reg_old=ro, reg_shared={'public/logo.svg': 'x'})
print(' 清掉夹具后 --pre 转绿 %s' % ('✓' if rc2 == 0 else '✗'))
return 0 if (rc == 1 and rc2 == 0) else 1
finally:
shutil.rmtree(sb, ignore_errors=True)
if __name__ == '__main__':
m = sys.argv[1] if len(sys.argv) > 1 else '--pre'
raise SystemExit(selftest() if m == '--selftest' else main(ROOT, m))