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 个文本/矢量件。
75 lines
4.4 KiB
Python
75 lines
4.4 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""生成 landing/codepatch.sh —— P7-A 的落地补丁(**准备件,未执行**)。
|
||
|
||
为什么单独一支脚本而不是塞进 apply.sh:apply.sh 换的是资产与 props,这一支改的是
|
||
**一条测试的断言语义**。混在一起,出问题时无法单独回滚,也无法单独授权。
|
||
|
||
锚点不手抄:直接从仓库现状里把那段循环原文取出来(`OLD`),
|
||
所以"补丁对不上"只可能是真改了,不会是我抄错。命中数必须恰好 1,否则拒绝执行。
|
||
幂等性反向:打完之后再跑一次必须被拒(锚点已消耗)——与 docsync.sh 同一口径。
|
||
"""
|
||
import io
|
||
import os
|
||
import re
|
||
|
||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
REPO = os.path.abspath(os.path.join(HERE, '..', '..'))
|
||
SPEC = 'e2e/p1-brand-visual-audit.spec.ts'
|
||
OUT = os.path.join(HERE, 'landing')
|
||
|
||
|
||
def build():
|
||
src = io.open(os.path.join(REPO, SPEC), encoding='utf-8').read()
|
||
m = re.search(r"( *)for \(const asset of \['/logo\.svg', '/logo-white\.svg'\]\) \{\n"
|
||
r"((?:.|\n)*?)\n\1\}\n", src, re.S)
|
||
assert m, '锚点没取到:spec 里那段遍历已变,判据要重读源码而不是硬编'
|
||
old = m.group(0).rstrip('\n')
|
||
ind = m.group(1) # 外层 for 的缩进(4 空格)
|
||
body = m.group(2) # 循环体(含内层 for)
|
||
inner = ' ' # 内层比外层多两格
|
||
assert 'textNodes' in old and 'toBe' in old, '取到的段落不像那条断言'
|
||
# 新体:两支都有非零目标数 —— 几何字标 ⇒ 断言「不得夹带 <text>」;
|
||
# 旧字标 ⇒ 断言「<text> 数 >0 且逐个等于 NOVALON」。P5=S4 之后 A 是几何,走第一支。
|
||
new = (ind + "// P7-A:目标数为 0 的遍历不构成断言(§5.21 那族假绿的新外壳)。\n"
|
||
+ ind + "// 几何字标(P5=S4 交付件)里没有 <text> ⇒ 改断「不得夹带」;旧字标仍走「逐个等于 NOVALON」。\n"
|
||
+ ind + "for (const asset of ['/logo.svg', '/logo-white.svg']) {\n"
|
||
+ body.replace(ind + inner + 'for (const value of textNodes) {',
|
||
ind + inner + 'if (textNodes.length === 0) {\n'
|
||
+ ind + inner + inner + "expect(asset, `${asset} 是几何字标却带 <text>`).toBeTruthy();\n"
|
||
+ ind + inner + inner + 'continue;\n'
|
||
+ ind + inner + '}\n'
|
||
+ ind + inner + "expect(textNodes.length, `${asset} 内一个 <text> 都没有 ⇒ 取到的不是标识资产`).toBeGreaterThan(0);\n"
|
||
+ ind + inner + 'for (const value of textNodes) {')
|
||
+ "\n" + ind + "}")
|
||
lines = ['#!/usr/bin/env bash',
|
||
'# P7-A:把「Logo 图形资产内的文字受控」从空断言改成两支都有非零目标数的断言。',
|
||
'# 沙箱彩排:REPO_ROOT=<沙箱> bash landing/codepatch.sh',
|
||
'set -euo pipefail',
|
||
'REPO_ROOT="${REPO_ROOT:?红:必须显式给出 REPO_ROOT}"',
|
||
'cd "$REPO_ROOT"',
|
||
'test -f %s || { echo "红:找不到 %s,不像本仓根"; exit 1; }' % (SPEC, SPEC),
|
||
'python3 - <<\'PY\'']
|
||
payload = ["import io, os",
|
||
"ROOT = os.environ['REPO_ROOT']",
|
||
"P = os.path.join(ROOT, %r)" % SPEC,
|
||
"OLD = %r" % old,
|
||
"NEW = %r" % new,
|
||
"s = io.open(P, encoding='utf-8').read()",
|
||
"n = s.count(OLD)",
|
||
"assert n == 1, ('锚点命中 %d 次,期望 1 ⇒ 该测试已被别的改动动过,先停下来问清楚' % n)",
|
||
"assert 'P7-A' not in s, '已打过 P7-A 补丁 ⇒ 拒绝重复执行'",
|
||
"io.open(P, 'w', encoding='utf-8').write(s.replace(OLD, NEW, 1))",
|
||
"print('已打 P7-A:', %r)" % SPEC]
|
||
lines += payload + ['PY', 'echo "落库后请跑:python3 deliverables/logo-redesign-2026-10-13/check-wordmark-copies.py --post"']
|
||
os.makedirs(OUT, exist_ok=True)
|
||
with io.open(os.path.join(OUT, 'codepatch.sh'), 'w', encoding='utf-8') as f:
|
||
f.write("\n".join(lines) + "\n")
|
||
os.chmod(os.path.join(OUT, 'codepatch.sh'), 0o755)
|
||
print('landing/codepatch.sh 已写成(未执行)| 锚点 %d 字符,取自仓库现状而非手抄' % len(old))
|
||
print('锚点首行:%s' % old.strip().splitlines()[0][:70])
|
||
|
||
|
||
if __name__ == '__main__':
|
||
build()
|