按 code-conventions §1.4.1 第三轮定稿执行:core 22+schemas 18+presentation 根 14+views 28,全部头注 #→##、删日期/变更叙事/GDD 与架构反向链接/字段与域清单/机制描述,保留职责摘要+真实使用约束(防事故禁令/单一入口/信号契约每信号一行)。main.gd 31→5 行、save_manager 45→5 行、adventure_runner 37→5 行为最大单件。子代理分模块执行(波一 core+schemas、波二 presentation+views,并发≤2)。验收=tools/verify_comment_only_change.py 逐字节校验(82 文件头注区外逐行一致=零行为变更)+audit_file_headers 全绿;纯注释批免冒烟(先例 5843270)
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""verify_comment_only_change.py — 纯注释批次零行为变更机器证明。
|
||
|
||
对 git 工作区相对 HEAD 的每个改动 .gd(game/core、game/data、game/presentation):
|
||
剥离文件头注释区(首个非注释代码行前的全部空行/注释行)后,新旧剩余内容必须逐行一致——
|
||
证明改动只发生在文件头注释区,代码行为零变更。头注清偿/载体换代一类纯注释批的交付验收
|
||
配套(code-conventions §1.4.1)。
|
||
退出码:0=全部通过,1=存在头注区外的改动。用法:python tools/verify_comment_only_change.py
|
||
"""
|
||
import subprocess
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parent.parent
|
||
|
||
|
||
def strip_header(lines):
|
||
"""剥掉头注区(首个非注释非空行前的全部空行/注释行),返回剩余行列表。"""
|
||
i = 0
|
||
while i < len(lines):
|
||
s = lines[i].strip()
|
||
if s == "" or s.startswith("#"):
|
||
i += 1
|
||
else:
|
||
break
|
||
return lines[i:]
|
||
|
||
|
||
def main():
|
||
out = subprocess.run(
|
||
["git", "diff", "--name-only", "HEAD", "--", "game/core", "game/data", "game/presentation"],
|
||
cwd=ROOT, capture_output=True, text=True, check=True).stdout.split()
|
||
if not out:
|
||
print("[verify_comment_only] 无改动文件")
|
||
return 0
|
||
bad = []
|
||
for rel in out:
|
||
rel = rel.replace("\\", "/")
|
||
old = subprocess.run(["git", "show", "HEAD:" + rel],
|
||
cwd=ROOT, capture_output=True, text=True, check=True).stdout
|
||
new = (ROOT / rel).read_text(encoding="utf-8")
|
||
if strip_header(old.splitlines()) != strip_header(new.splitlines()):
|
||
bad.append(rel)
|
||
if bad:
|
||
for rel in bad:
|
||
print("[verify_comment_only] FAIL 头注区外内容被改动: " + rel)
|
||
return 1
|
||
print("[verify_comment_only] ok: %d 个改动文件头注区外逐行一致(零行为变更)" % len(out))
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|