♻️ refactor(tsl-api): tighten docs and retire stale tests

This commit is contained in:
csh
2026-08-21 10:11:48 +08:00
parent 2e8c46e152
commit 5484fc7519
24 changed files with 505 additions and 2700 deletions
-29
View File
@@ -8,7 +8,6 @@ delegate rather than re-derive rules from that document.
import ast
import json
import os
import re
import subprocess
import sys
import tempfile
@@ -18,11 +17,7 @@ from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SKILL_ROOT = ROOT / "skills" / "commit-message"
VALIDATOR = SKILL_ROOT / "scripts" / "validate_commit_message.py"
POLICY = SKILL_ROOT / "references" / "commit_policy.json"
CI_ENTRY = ROOT / ".gitea" / "ci" / "commit_message_lint.py"
SPEC = ROOT / "docs" / "common" / "commit_message.md"
TABLE_ROW_RE = re.compile(r"^\|(?P<type>[^|]*)\|(?P<emoji>[^|]*)\|")
def run(script, *args, env=None):
@@ -37,31 +32,7 @@ def run(script, *args, env=None):
)
def spec_type_emoji_mapping():
mapping = {}
for line in SPEC.read_text(encoding="utf-8").splitlines():
match = TABLE_ROW_RE.match(line.strip())
if not match:
continue
type_cell = re.search(r"`([a-z][a-z0-9-]*)`", match.group("type"))
emoji_cell = re.search(r"`(:[a-z0-9_+-]+:)`", match.group("emoji"))
if type_cell and emoji_cell:
mapping[type_cell.group(1)] = emoji_cell.group(1)
return mapping
class CommitPolicySingleOwnerTests(unittest.TestCase):
def test_policy_and_spec_table_agree(self):
policy_types = json.loads(POLICY.read_text(encoding="utf-8"))["types"]
spec_types = spec_type_emoji_mapping()
self.assertTrue(spec_types, f"no type/emoji table parsed from {SPEC}")
self.assertEqual(
policy_types,
spec_types,
"commit_policy.json and docs/common/commit_message.md disagree; "
"update both when adding or renaming a type",
)
def test_ci_entry_point_does_not_reimplement_rules(self):
source = CI_ENTRY.read_text(encoding="utf-8")
self.assertIn("validate_commit_message.py", source)