feat: add python compatibility review gate

This commit is contained in:
yaojingang
2026-06-14 01:35:36 +08:00
parent 4737358f3c
commit ae0f72cccb
30 changed files with 624 additions and 149 deletions
+11
View File
@@ -440,6 +440,17 @@ ACTION_GUIDANCE: dict[str, dict[str, str]] = {
],
"verification": "python3 scripts/trust_check.py .",
},
"python-compat": {
"summary": "修复 Python 3.11 语法兼容问题,尤其是 f-string 表达式内的反斜杠转义。",
"why": "目标运行环境可能仍停留在 Python 3.11,语法漂移会让 CLI、报告生成和 CI 在发布后直接失败。",
"source_fix": "reports/python_compatibility.md + scripts/*.py + tests/*.py",
"source_paths": [
{"path": "reports/python_compatibility.md", "label": "Python compatibility", "kind": "report", "patterns": ["# Python"]},
{"path": "scripts/python_compat_check.py", "label": "compatibility checker", "kind": "source", "patterns": ["SCRIPT_INTERFACE"]},
{"path": ".github/workflows/test.yml", "label": "CI test workflow", "kind": "ci", "patterns": ["python"]},
],
"verification": "python3 scripts/yao.py python-compat .",
},
"permission-gates": {
"summary": "补齐高权限能力的 reviewer、scope、reason、expires_at 和目标端 enforcement 说明。",
"why": "权限契约只有在批准人、有效期和目标端处置方式明确时,才能支撑 governed release。",
+33
View File
@@ -259,6 +259,38 @@ def build_gates(skill_dir: Path, output_html: Path, data: dict[str, dict[str, An
)
)
python_compat = data["python_compatibility"]
python_compat_summary = python_compat.get("summary", {})
if not python_compat:
python_compat_status = "warn"
python_compat_detail = "Python compatibility report is missing"
else:
issue_count = int(python_compat_summary.get("issue_count", 0) or 0)
syntax_error_count = int(python_compat_summary.get("syntax_error_count", 0) or 0)
fstring_violation_count = int(python_compat_summary.get("fstring_311_violation_count", 0) or 0)
python_compat_status = (
"block"
if not python_compat.get("ok", True) or issue_count or syntax_error_count or fstring_violation_count
else "pass"
)
python_compat_detail = (
f"Python {python_compat_summary.get('target_python', '3.11')}; "
f"{python_compat_summary.get('file_count', 0)} files; "
f"{issue_count} compatibility issues; "
f"{syntax_error_count} syntax; "
f"{fstring_violation_count} f-string 3.11 hazards"
)
gates.append(
gate(
"python-compat",
"Python 兼容",
python_compat_status,
python_compat_detail,
"reports/python_compatibility.json",
_report_link(output_html, skill_dir, "reports/python_compatibility.md"),
)
)
permission_governance = trust.get("permission_governance", {}) if isinstance(trust.get("permission_governance", {}), dict) else {}
if trust and not permission_governance:
permission_governance = fallback_permission_governance(skill_dir)
@@ -533,6 +565,7 @@ def weighted_score(gates: list[dict[str, str]]) -> int:
"context-budget": 10,
"runtime-matrix": 10,
"trust-report": 10,
"python-compat": 10,
"permission-gates": 10,
"permission-runtime": 10,
"skill-atlas": 10,