Files
gplan-2/tools/extract_capability_list.py
T
DKChan 8b09b2c952 追红(远端 run 95 两条红转绿·修复车道): 红因1=判定级——能力审计 G 道「oracle 注记函数 401·红项 1」, 红项原文「game/probe/probe_coverage_recorder.gd:201 验证函数 dump_js 缺 # oracle 注记」(dump_js 体内三处 push_error( 命中 capability_audit.py:341 VERDICT_RE → 属须注记的验证函数, :386 判红); 上一批「判据出处注记 402 函数全库铺开」的跑绿读数靠主工作区一行未提交注记撑过, 未随批 commit, 故本地 strict 绿而远端干净检出必红; 本批在该文件补同一行注记(放法照仓内既有形态——函数定义行下一行顶格, 样本 camp_scene_layout_test.gd:13/:18, 指针 design/engineering/test-conventions.md:30 与主区工作稿逐字节同, cmp 已核)。红因2=非判定级但在日志里成串报红——tools 四处五 sites 用 Path.write_text(..., newline="\n"), 该关键字 Python 3.13+ 才有(本机 3.13.14 绿), Mac runner 的 python3 更老 → TypeError("write_text() got an unexpected keyword argument 'newline'") → 六层明细回执在远端一件未落盘, run 93/95 日志同报此错(挂点按设计是观测件不翻闸判, 故它不是 run 95 的失败主因, 但等于覆盖总览面板的六层明细一直是空的); 五处改 open(str(p), "w", encoding="utf-8", newline="\n") 写法(newline 形参 builtin open 自 3.0 起有, LF 纪律不丢), 覆盖面=coverage_enum.py:148/coverage_receipts.py:160/:179/extract_capability_list.py:104/extract_checks.py:588; 注: tools/t17_fanout2_rebuild.py:140 与 t5_build_templates.py:237 本来就是 open(..., newline=) 形态, 不属坏件未动。本步凭据(全部区内实跑): ①修复前在干净检出复现红——capability_audit --strict 出「401 注记·红项 1」并打出上述红项原文; ②修复后同件 exit=0「402 注记·红项 0」; ③四件 py_compile OK 且 grep 全仓 write_text(.*newline= 零残留; ④runner 语义实证——把 Path.write_text 垫片成 3.12 行为(newline 一律 TypeError)再跑 coverage_receipts.main(), 六层与 probe_manifest 全部正常落盘、无一行「[receipts] 红」, 产物字节核对 gate_probe/gate_render/gate_smoke.js 均 CRLF=0 LF=14(行尾纪律未破); ⑤run_all_gates --docs 验收通过无新增红(基线 9e81408e)。引擎层本地未跑: 区内 --premerge 被素材齐盘预检拦在冷检出态(缺 .godot/uid_cache.bin 与字体 .import 边车, 处置需从主区拷素材再 --editor --quit 刷导入), 本批五处改动零游戏行为面, 引擎全套件由主区合回时的 pre-merge-commit 前置检查跑, 全量档归合回后远端 CI
2026-11-06 23:47:28 +08:00

131 lines
5.2 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 -*-
r"""extract_capability_list.py — 能力清单义务层提取器(B 覆盖总览面板·义务层)
把 game/tests/README.md「能力清单」的四列表(能力|系统|真实入口|代表用例)按旅程段
解析成机器可读 JSONP .js,供 tools/coverage_report.html 经 <script src> 直载
(file:// 下 fetch 本地 json 被 CORS 拦——JSONP 是 B 面板全数据源的统一形态)。
用法:
python tools/extract_capability_list.py [--readme <路径>] [--out <路径>]
判据口径:
- 只认表头恰为「能力|系统|真实入口|代表用例」的四列表(覆盖域表等五列表不取);
- 旅程段标题形态=「**旅程段N:名称**」,段名进每行的 segment 字段;
- 代表用例列按「;」切分成用例指针数组(`文件:函数` 形态逐字保真);
- 本工具是义务层的静态投影,产出随 README 变更重跑即得——面板只读本产物,禁在面板里改义务。
产出(JSONP):
window.__QA_COVERAGE__.capability_list = {
"meta": {"generated_at", "source", "rows_total", "segments_total"},
"segments": [{"segment": 名称, "rows": [{"ability", "system", "entry", "cases": []}]}],
}
"""
from __future__ import annotations
import argparse
import datetime
import json
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
DEFAULT_README = ROOT / "game" / "tests" / "README.md"
DEFAULT_OUT = ROOT / "game" / "tests" / ".gates" / "coverage" / "capability_list.js"
SEGMENT_RE = re.compile(r"^\*\*旅程段[一二三四五六七八九十]+[::](.+?)\*\*\s*$")
def split_row(line: str) -> list[str]:
body = line.strip()
if body.startswith("|"):
body = body[1:]
if body.endswith("|"):
body = body[:-1]
return [c.strip() for c in body.split("|")]
def parse(readme: Path) -> dict:
lines = readme.read_text(encoding="utf-8").splitlines()
segments: list[dict] = []
cur_seg: str | None = None
cur_rows: list[dict] | None = None
in_capability_table = False
for line in lines:
seg = SEGMENT_RE.match(line.strip())
if seg:
if cur_seg is not None:
segments.append({"segment": cur_seg, "rows": cur_rows or []})
cur_seg = seg.group(1).strip()
cur_rows = []
in_capability_table = False
continue
if cur_seg is None:
continue
if not line.strip().startswith("|"):
in_capability_table = False
continue
cells = split_row(line)
if all(not set(c) - {"-", " ", ":"} for c in cells) and cells:
continue # 表头分隔行 |---|---|
if (len(cells) == 4 and cells[0] == "能力" and cells[1] == "系统"
and cells[2] == "真实入口" and cells[3].startswith("代表用例")):
in_capability_table = True
continue
if in_capability_table and len(cells) == 4:
ability, system, entry, cases = cells
cur_rows.append({
"ability": ability.strip("`"),
"system": system,
"entry": entry,
"cases": [c.strip().strip("`") for c in cases.split(";") if c.strip()],
})
if cur_seg is not None:
segments.append({"segment": cur_seg, "rows": cur_rows or []})
rows_total = sum(len(s["rows"]) for s in segments)
return {
"meta": {
"generated_at": datetime.datetime.now().isoformat(timespec="seconds"),
"source": str(readme),
"rows_total": rows_total,
"segments_total": len(segments),
},
"segments": segments,
}
def dump_js(payload: dict, out: Path) -> None:
out.parent.mkdir(parents=True, exist_ok=True)
js = "/* 能力清单义务层投影——由 extract_capability_list.py 生成,随 README 变更重跑;人工修订无效(义务源=README 能力清单)。 */\n"
js += "window.__QA_COVERAGE__ = window.__QA_COVERAGE__ || {};\n"
js += "window.__QA_COVERAGE__.capability_list = %s;\n" % json.dumps(payload, ensure_ascii=False, indent=2)
with open(str(out), "w", encoding="utf-8", newline="\n") as fh:
fh.write(js)
def main() -> int:
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ap = argparse.ArgumentParser(description="能力清单义务层提取(B 面板·义务层)")
ap.add_argument("--readme", default=str(DEFAULT_README))
ap.add_argument("--out", default=str(DEFAULT_OUT))
args = ap.parse_args()
readme = Path(args.readme)
if not readme.is_file():
print("[capability] README 不存在:%s" % readme)
return 1
payload = parse(readme)
dump_js(payload, Path(args.out))
print("[capability] 义务层投影已落盘 %s(旅程段 %d / 能力行 %d)" % (
args.out, payload["meta"]["segments_total"], payload["meta"]["rows_total"]))
if payload["meta"]["rows_total"] == 0:
print("[capability] 红:能力行数为 0——表头或旅程段标题形态不匹配,禁当空义务面用")
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())