docs(architecture): enforce host persistence boundary

This commit is contained in:
jxxghp
2026-08-27 05:44:33 +08:00
parent 5df388719e
commit 3bf94ffeda
7 changed files with 124 additions and 73 deletions
+28
View File
@@ -0,0 +1,28 @@
"""架构规则文档的可执行一致性约束。"""
import re
from pathlib import Path
PROJECT_ROOT = Path(__file__).parents[1]
RULE_DOCUMENTS = tuple(sorted((PROJECT_ROOT / "docs" / "rules").glob("*.md")))
NO_SESSION_OPER = re.compile(r"\b[A-Z][A-Za-z0-9]*Oper\(\)")
COMPATIBILITY_MARKERS = ("legacy plugin abi", "compatibility", "兼容")
def test_no_session_oper_examples_are_explicitly_compatibility_only() -> None:
"""无 Session Oper 示例必须紧邻 Legacy/Compat 说明,不能冒充宿主规范。"""
violations: list[str] = []
for path in RULE_DOCUMENTS:
content = path.read_text(encoding="utf-8")
for occurrence in NO_SESSION_OPER.finditer(content):
context = content[
max(0, occurrence.start() - 500):occurrence.end() + 200
].lower()
if not any(marker in context for marker in COMPATIBILITY_MARKERS):
line = content.count("\n", 0, occurrence.start()) + 1
violations.append(f"{path.relative_to(PROJECT_ROOT)}:{line}")
assert violations == [], (
"无 Session Oper 仅允许出现在明确标注的插件 Legacy/Compat 示例中: "
+ ", ".join(violations)
)