Files
gplan-2/tools/verify_comment_only_change.py
T
DKChan 9a72394652 chore(代码卫生): 头注存量清偿批——82 文件按两类白名单改写为 ## 文档注释载体
按 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)
2026-10-16 23:28:07 +08:00

55 lines
2.0 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 -*-
"""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())