Files
novalon-website/deliverables/logo-redesign-2026-10-13/check-manual.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

395 lines
20 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 -*-
"""
手册数字对账(第五十六刀)—— 文档里写的数,必须能从生成器重算出来
手册是这一轮交付的**最终产物**,但它也是全套文件里唯一一处
"数字被抄第二遍"的地方:源在 brand.py / novalon.py / auxiliary.py / mockups.py 里算,
手册里是手抄的字符串。**抄下来的数不会因为源变了而变。**
`.ico` 那件事刚教过一遍:同一事实两个来源,不交叉对账就是没证。
所以这一支把凡是**能解析重算**的数字全部重算一遍,逐个回查手册正文里出现的是不是这个数。
量出来的数(浏览器实测那类:面积、缺口、保留率)不在这里重算 —— 那些的权威是页面本身,
这里只断言"手册必须写明出处页",不假装能离线复现浏览器栅格。
判据双边:正例全对;负例(把某个数改掉)必须报红 —— 不然这支脚本自己就是一条不会失败的判据。
"""
import glob
import importlib.util
import json
import os
import re
HERE = os.path.dirname(os.path.abspath(__file__))
# 文档路径可传入:敏感性自测要拿一份"被改坏的手册"来跑,
# 但**不能靠整树复制**——mark-swap.py 之类会按自己所在位置往上找仓根,
# 复制到 /tmp 外就找不到 public/logo.svg(上一轮那个 exit=1 就是这么来的假通过)。
import sys
DOC = (sys.argv[1] if len(sys.argv) > 1
else os.path.join(HERE, "BRAND-MANUAL.md"))
def load(name, fn):
sp = importlib.util.spec_from_file_location(name, os.path.join(HERE, fn))
m = importlib.util.module_from_spec(sp)
sp.loader.exec_module(m)
return m
def claims():
"""(手册里必须出现的字样, 重算表达式, 说明) —— 重算全部走生成器,不抄手册。"""
br = load("auxx", "auxiliary.py")
bm = load("brn", "brand.py")
ml = load("mln", "mockups.py")
nv = br.nv
out = []
r = lambda v, n: ("%%.%df" % n) % v
# 主锁定五件套
out.append((r(bm.CAP_R, 3), "0.535 倍", "号 cap / 名高"))
out.append((r(bm.WM_CAP, 2), "27.82", "号 cap 单位"))
out.append((r(bm.WM_TRACK, 2), "33.62", "锁定里的号字距"))
out.append((r(bm.NAME_W, 1), "223.6", "名墨宽"))
out.append((r(bm.NAME_H, 0), "52", "名 cap"))
_, I = bm.lockup_stack(px=560)
out.append((r(I["W"], 1), "255.6", "1× 主锁定墨盒宽"))
out.append((r(I["H"], 1), "119.8", "1× 主锁定墨盒高"))
# 朱砂条派生比与地板
out.append((r(100 * br.BR, 4), "1.5238%", "条厚 = 标识显示宽 × 此比 × 档位"))
out.append((r(br.T1, 3), "3.895", "基准厚 T1(锁定单位)"))
for tier in (1.0, 2.0, 4.0):
need = 1.0 / (br.BR * tier)
out.append((str(int(round(need))), "%dpx" % int(round(need)),
"%g× 档的最小载体宽(期望厚 ≥1px)" % tier))
# 最小尺寸三档(笔画 = 14 × 显示宽 ÷ 墨宽)
for w, lab in ((64, "安全"), (40, "极限"), (32, "塌")):
out.append((r(14.0 * w / I["W"], 2), "%s 档 %s" % (r(14.0 * w / I["W"], 2), lab),
"%dpx 显示宽对应的笔画" % w))
# A 用红的先验与补偿系数
ra = load("ran", "red-a.py")
out.append((r(-100 * ra.PRIOR, 1), "%.1f%%" % (-100 * ra.PRIOR), "朱砂 A 的先验缺口"))
out.append((r(ra.K_COMP, 3), "×%s" % r(ra.K_COMP, 3), "补偿笔宽系数"))
# 动效时标与存量计数
ms = sorted(br.DUR.values())
out.append(("/".join(str(v) for v in ms), "六档时标值序列", "六档时标(须与 globals.css 同值)"))
assert "/".join(str(v) for v in ms) == "100/180/280/450/700/1000", ms
out.append((str(sum(len(v) for v in br.OFFTOK.values())),
"%d 处" % sum(len(v) for v in br.OFFTOK.values()), "非 token 字面时长计数"))
out.append((br.EASE, "cubic-bezier(0.22, 1, 0.36, 1)", "唯一缓动"))
# 样机面的物理厚(印刷 0.1mm 单位 → mm)
for key, mw, tier, lab in [("MC2", 400, 4.0, "名片背面 4×"),
("MC4", 260, 4.0, "PPT 4×"),
("MC5", 900, 2.0, "年报 2×")]:
mm = mw * br.BR * tier * 0.1
out.append((r(mm, 2), "%.2fmm" % mm, lab + " 的真实物理厚"))
# 资产计数
n_assets = len([f for f in os.listdir(os.path.join(HERE, "assets-delivery"))
if f != "MANIFEST.md"])
out.append((str(n_assets), "%d 个文件" % n_assets, "assets-delivery 计数"))
n_land = len([f for f in os.listdir(os.path.join(HERE, "landing"))
if re.search(r"\.(svg|png|ico)$", f)])
out.append((str(n_land), "%d 个落库文件" % n_land, "landing 暂存计数"))
# 仪器自证的三个数:手册里"探针全绿"这句话也必须能被重算。
# 写成整句当 needle(而不是裸数字)——"5"这种一个字符的定位符在文档里必然命中,
# 等于没有断言(记忆 §66①:不具体的谓词会给真漂移开绿灯)。
cp = load("chkprobes", "check-probes.py")
nsyn = len(glob.glob(os.path.join(HERE, "*.py")))
nerr = len(cp.s1_syntax(HERE))
ngen, nmiss = cp.s2_provenance(HERE)[1], len(cp.s2_provenance(HERE)[0])
out.append(("%d 个探针脚本 %d 个语法错误" % (nsyn, nerr), "S1", "语法面"))
out.append(("%d 个页面生成器 %d 处输出缺失" % (ngen, nmiss), "S2", "出处面"))
out.append(("%d 条闸" % len(cp.GATES), "S3", "闸清单长度"))
return out
def run(doc):
cs = claims()
bad = []
for needle, shown, why in cs:
if needle not in doc:
bad.append("手册缺/错:%s | 重算值 %r | 手册里写的形如 %r" % (why, needle, shown))
return bad, cs
def measured_claims():
"""手册里引的**实测**数,与页面跑出来的 JSON 快照对账。
权威是页面;JSON 是那一跑的存档 —— 这里查的是"手册抄没抄错",
不假装能离线复现浏览器栅格。"""
M = os.path.join(HERE, "measured")
mk = json.load(open(os.path.join(M, "mockups.json"), encoding="utf-8"))
ra = json.load(open(os.path.join(M, "red-a.json"), encoding="utf-8"))
ax = json.load(open(os.path.join(M, "auxiliary.json"), encoding="utf-8"))
out = []
for k in ("MC1", "MC2", "MC3", "MC4", "MC5", "MC6", "MC7", "MC8"):
# 取手册用的同一档精度:面积表写两位、笔画列写一位。
# 精度由【引用方】决定,容差再按这个精度给 —— 否则 25.9 会被 25.88 判成漂移。
out.append((("%.2f" % mk["area"][k]), "样机 %s 朱砂面积%%" % k))
out.append((("%.1f" % mk["stroke"][k]), "样机 %s 笔画 px" % k))
for k, lab in [("S1", "朱砂 A 无补偿"), ("S2", "深红 A"), ("S3", "浅红反例"),
("S4", "补偿版"), ("D1", "深底 #E13C58"), ("D2", "深底朱砂")]:
out.append((("%.1f" % abs(ra["deficit"][k])) + "%", lab + " 的光学重量缺口"))
for k, lab in [("C1", "闭合环标定"), ("C2", "半环标定"), ("C3", "等宽环标定"),
("G55", "55° 那格"), ("X1", "上移出框"), ("X3", "左移出框"),
("X4", "右移出框")]:
out.append((str(ax["ring"][k][0]), lab + " 的视觉开口读数"))
out.append((("%.2f" % ax["ring"]["N24"][1]), "一相圆 24px 环身最厚"))
return out
def _nums(text):
return [float(x) for x in re.findall(r"(?<![\d.])-?\d+(?:\.\d+)?(?![\d.])", text)]
def _lines(doc, key):
"""返回正文里含该键的行(表格行/条目行)。定位不到就是断言没锚上。"""
return [l for l in doc.split("\n") if key in l]
def _close(nums, want, prec):
tol = 0.5 * (10 ** -prec) + 1e-9
return any(abs(n - want) <= tol for n in nums)
def stale_snapshots(here=None):
"""快照必须对得上当前页面。页面重跑过而 JSON 没更新,对账就是在拿旧真值
验新文档 —— 两边都"通过",但什么都没验。
here 可注入,是为了让负例能在临时目录里复现"页面重新生成",
而不动真树里任何交付资产。"""
import hashlib
here = here or HERE
out = []
mdir = os.path.join(here, "measured")
for j in sorted(os.listdir(mdir)):
if not j.endswith(".json"):
continue
d = json.load(open(os.path.join(mdir, j), encoding="utf-8"))
src = d.get("_src")
if not src:
out.append("%s 没有 _src 出处戳 ⇒ 无法判断快照是否过期" % j)
continue
for f, want in src.items():
pth = os.path.join(here, f)
if not os.path.exists(pth):
out.append("%s 声称来自 %s,但该文件不存在" % (j, f)); continue
got = hashlib.sha256(open(pth, "rb").read()).hexdigest()[:12]
if got != want:
out.append("%s 快照过期:%s 已重新生成(快照 %s ≠ 当前 %s)"
% (j, f, want, got))
return out
def _sec(doc, head):
"""取某个二级/三级标题下的正文。按节定位,避免"年报扉页"在 §3.1 和 §8.2 各出现一次
却只对其中一处对账 —— 上一版就是这么把五条正确数据判成漂移的。"""
i = doc.find(head)
if i < 0:
return ""
j = len(doc)
for m in re.finditer(r"^#{2,3} ", doc[i + len(head):], re.M):
j = i + len(head) + m.start()
break
return doc[i:j]
def _one(lines, key, where):
hit = [l for l in lines if key in l]
if len(hit) != 1:
return None, "%s:定位符 %r 命中 %d 行(应恰好 1 行)⇒ 无法对账" % (where, key, len(hit))
return hit[0], None
def run_measured(doc):
"""按【节 → 行 → 数值】三级定位对账。
不具体全文扫:上一版"全文任意一个数像就算命中",注入真漂移 25.9→26.4 仍 exit=0。"""
M = os.path.join(HERE, "measured")
mk = json.load(open(os.path.join(M, "mockups.json"), encoding="utf-8"))
ra = json.load(open(os.path.join(M, "red-a.json"), encoding="utf-8"))
ax = json.load(open(os.path.join(M, "auxiliary.json"), encoding="utf-8"))
bad = []
# 只取表格行:§8.2 的正文里也提到"工牌"(那次碰撞),不过滤就会命中 2 行。
rows = [l for l in _sec(doc, "### 8.2").split("\n") if l.startswith("| ")]
NAME = {"MC1": "名片·正面", "MC2": "名片·背面", "MC3": "信纸 A4", "MC4": "PPT 章节页",
"MC5": "年报扉页", "MC6": "工牌", "MC7": "社媒 OG 图", "MC8": "网页 hero"}
for k, key in NAME.items():
line, err = _one(rows, key, "§8.2")
if err:
bad.append(err); continue
nums = _nums(line)
if not _close(nums, mk["stroke"][k], 1):
bad.append("§8.2 %s 笔画对不上:页面实测 %.2f,该行 %s" % (key, mk["stroke"][k], nums))
if not _close(nums, mk["area"][k], 2):
bad.append("§8.2 %s 面积对不上:页面实测 %.3f,该行 %s" % (key, mk["area"][k], nums))
p5 = _sec(doc, "**P5").split("\n")
LAB = [("S2", "深红"), ("S4", "正朱砂"), ("S3", "#E8899A"),
("D1", "对白字实测轻"), ("D2", "纸底朱砂直接搬上来"), ("S1", "页内栅格实测")]
for k, key in LAB:
line, err = _one(p5, key, "§10 P5")
if err:
bad.append(err); continue
if not _close(_nums(line), abs(ra["deficit"][k]), 1):
bad.append("§10 P5 %s 缺口对不上:页面实测 %.1f%%,该行 %s"
% (key, abs(ra["deficit"][k]), _nums(line)))
ring = _sec(doc, "## 3.").split("\n")
RING = [("C1", "闭合环"), ("C2", "半环"), ("C3", "等宽环"),
("X1", "把正上方裁掉")]
for k, key in RING:
line, err = _one(ring, key, "§3")
if not err and not _close(_nums(line), ax["ring"][k][0], 0):
bad.append("§3 %s 视觉开口对不上:页面实测 %d°" % (key, ax["ring"][k][0]))
elif err:
bad.append(err)
lr = [l for l in ring if "左移" in l and "右移" in l]
if len(lr) != 1:
bad.append("§3:左移/右移那行定位到 %d 行 ⇒ 无法对账" % len(lr))
elif not (_close(_nums(lr[0]), ax["ring"]["X3"][0], 0)
and _close(_nums(lr[0]), ax["ring"]["X4"][0], 0)):
bad.append("§3 左移/右移读数对不上:页面实测 %d°/%d°"
% (ax["ring"]["X3"][0], ax["ring"]["X4"][0]))
return bad
def _dec(s):
s = s.rstrip("%")
return len(s.split(".")[1]) if "." in s else 0
def structure(doc):
"""手册的**结构**对账(改完一个长文档必须跑它的解析器——这里"解析器"就是这几条)。
触发原因是本轮又一次 Edit 吞掉了一个 bullet 头:锚点行被整条替换掉,正文续行还在,
markdown 渲染时那段就并到上一条去了——数字对账全绿,读者看到的却是错的段落。"""
out = []
L = doc.split("\n")
hs = [int(m.group(1)) for m in (re.match(r"^## (\d+)\.", l) for l in L) if m]
if hs != list(range(1, len(hs) + 1)):
out.append("## 章节序号不连续:%s" % hs)
for i, l in enumerate(L):
if re.match(r"^\s\s+\S", l) and i > 0: # 任意深度的缩进续行
j = i - 1
while j >= 0 and not L[j].strip():
j -= 1
# 父项可以是无序列表项、**有序列表项**(§6 的 M1–M6 就是 1./2./…),
# 也可以是另一条缩进续行。上一版只认 `- ` ⇒ 把合法的 `6.` 续行判成"bullet 头被吃掉",
# 又一次是仪器误伤文档(对不上就改解析,不放宽判据)。
if j >= 0 and not re.match(r"^\s*([-*]|\d+\.) ", L[j]) and not re.match(r"^\s\s+\S", L[j]):
out.append("第 %d 行是缩进续行,但上一个非空行不是列表项 ⇒ 疑似 bullet 头被吃掉:%s"
% (i + 1, l.strip()[:44]))
blk = []
for l in L + [""]:
if l.startswith("|"):
blk.append(l.count("|"))
else:
if len(blk) > 1 and len(set(blk)) > 1:
out.append("表格列数不齐(竖线数集合 %s)⇒ 有行的单元格数漂了" % sorted(set(blk)))
blk = []
for m in re.finditer(r"\]\((?!http|#|/)([^)#\s]+)", doc):
p = m.group(1).strip()
if p and not os.path.exists(os.path.join(HERE, p)):
out.append("死链:%s" % p)
return out
def main():
doc = open(DOC, encoding="utf-8").read()
bad, cs = run(doc)
print("=== 手册数字对账(重算 %d 条)===" % len(cs))
for needle, shown, why in cs:
print(" %-46s 重算 %-22s %s" % (why, needle, "✓" if needle in doc else "✗ 手册里没有这个值"))
st = stale_snapshots()
print("=== 快照出处(measured/*.json 的 _src 必须对得上当前页面哈希)===")
for b in st:
print(" ✗ " + b)
if not st:
print(" ✓ 3 份快照的出处哈希与当前页面一致")
mbad = run_measured(doc) + st
print("=== 实测数对账(按行/按格比较,权威=measured/*.json 页面快照)===")
print(" 样机 8 行 × (笔画, 面积) + A 用红 6 条 + 一相圆留档 6 条")
for b in mbad:
print(" ✗ " + b)
if not mbad:
print(" ✓ 全部与页面快照一致")
st_doc = structure(doc)
print("=== 结构对账(章节序号 / 缩进续行有无吃掉 bullet 头 / 表格列数 / 死链)===")
for b in st_doc:
print(" ✗ " + b)
if not st_doc:
print(" ✓ 10 节连续、无孤立缩进行、表格配平、引用文件都在")
print("=== 负例(把源里的数改掉,对账必须报红)===")
import shutil, tempfile
sb = tempfile.mkdtemp(prefix="mdoc-")
tmp_doc = os.path.join(sb, "BRAND-MANUAL.md")
try:
# 负例必须把该数的**所有**出现都换掉:手册里同一个数常出现两次(表格 + 正文),
# 只 replace 第一次的话另一处仍然命中,对账就"抓不到"——那是负例没做成,不是判据有效。
t = doc.replace("1.5238%", "1.5999%").replace("33.62", "33.60")
open(tmp_doc, "w", encoding="utf-8").write(t)
globals()["DOC"] = tmp_doc
b2, _ = run(t)
# 注入两处真漂移:改表格里的笔画值、改 A 用红的缺口值
m2 = run_measured(t.replace("| 25.9 |", "| 26.4 |").replace("7.6%", "17.6%"))
print(" 解析数改坏 2 个 → 报红 %d 条 %s" % (len(b2), "✓" if len(b2) >= 2 else "✗"))
print(" 实测数改坏 2 个 → 报红 %d 条 %s" % (len(m2), "✓" if len(m2) >= 2 else "✗"))
assert len(b2) >= 2 and len(m2) >= 2
# 出处闸自己的负例:在临时目录里模拟"页面重新生成",必须报过期。
# 前提是正例基线已绿(上面 st 为空),否则"抓到了"毫无意义。
if not st:
sb2 = tempfile.mkdtemp(prefix="mst-")
try:
shutil.copytree(os.path.join(HERE, "measured"),
os.path.join(sb2, "measured"))
refs = set()
for j in os.listdir(os.path.join(sb2, "measured")):
if j.endswith(".json"):
refs |= set(json.load(open(os.path.join(sb2, "measured", j),
encoding="utf-8")).get("_src", {}))
for f in sorted(refs):
shutil.copy2(os.path.join(HERE, f), os.path.join(sb2, f))
assert not stale_snapshots(sb2), "临时副本的正例基线就该绿"
first = sorted(refs)[0]
open(os.path.join(sb2, first), "a",
encoding="utf-8").write("\n<!-- regen -->\n")
s2 = stale_snapshots(sb2)
print(" 页面重新生成 1 个(%s) → 报红 %d 条 / 含「快照过期」%s"
% (first, len(s2),
"✓" if len(s2) >= 1 and any("快照过期" in x for x in s2) else "✗"))
assert len(s2) >= 1 and any("快照过期" in x for x in s2)
# 忘打戳同样要报,否则闸可以靠"不加出处"绕过去
p0 = os.path.join(sb2, "measured",
sorted(x for x in os.listdir(os.path.join(sb2, "measured"))
if x.endswith(".json"))[0])
d0 = json.load(open(p0, encoding="utf-8")); d0.pop("_src", None)
json.dump(d0, open(p0, "w", encoding="utf-8"))
s3 = [x for x in stale_snapshots(sb2) if "没有 _src" in x]
print(" 抹掉 1 份出处戳(%s) → 报「没有 _src」%s"
% (os.path.basename(p0), "✓" if len(s3) == 1 else "✗"))
assert len(s3) == 1
finally:
shutil.rmtree(sb2, ignore_errors=True)
else:
print(" 出处闸负例:跳过(正例基线已红,负例结论不作数)")
# 结构负例:抹掉一个 bullet 头(本轮真实踩过的 Edit 失效形态),必须报孤立缩进行
assert not st_doc, "结构正例基线就该绿,否则下面的「抓到了」不作数"
s4 = structure(doc.replace("- **对账判据自己也会失效", "**对账判据自己也会失效", 1))
got = [x for x in s4 if "bullet 头被吃掉" in x]
print(" 抹掉 1 个 bullet 头 → 报孤立缩进续行 %d 条 %s"
% (len(got), "✓" if len(got) >= 1 else "✗"))
assert len(got) >= 1
finally:
shutil.rmtree(sb, ignore_errors=True)
print("\n结论:%s" % ("手册里可重算的 %d 条解析数 + 按行对账的实测数,全部与源一致"
% len(cs) if not (bad or mbad or st_doc)
else "手册漂移 %d 处,必须改文档不是改判据" % (len(bad) + len(mbad))))
for b in bad + mbad + st_doc:
print(" · " + b)
return 1 if (bad or mbad or st_doc) else 0
if __name__ == "__main__":
raise SystemExit(main())