📝 docs(tsl-syntax): enforce two-stage fact ownership workflow

This commit is contained in:
csh
2026-07-13 09:17:00 +08:00
parent 4076682895
commit 455661c936
8 changed files with 129 additions and 53 deletions
+43
View File
@@ -1,3 +1,4 @@
import importlib.util
import re
import unittest
from pathlib import Path, PurePosixPath
@@ -9,6 +10,13 @@ SKILL_FILE = SKILL_DIR / "SKILL.md"
REFERENCES_DIR = SKILL_DIR / "references"
COMPATIBILITY_INDEX = ROOT / "docs" / "tsl" / "syntax" / "index.md"
RULESET_FILE = ROOT / "rulesets" / "tsl" / "index.md"
LOOKUP_SCRIPT = SKILL_DIR / "scripts" / "lookup.py"
lookup_spec = importlib.util.spec_from_file_location(
"tsl_syntax_reference_structure_lookup", LOOKUP_SCRIPT
)
lookup = importlib.util.module_from_spec(lookup_spec)
lookup_spec.loader.exec_module(lookup)
TOPIC_REFERENCES = {
"01_quickstart.md",
@@ -73,6 +81,41 @@ def local_link_targets(text: str) -> list[str]:
class TslSyntaxReferenceSkillStructureTest(unittest.TestCase):
def test_skill_discovery_covers_natural_tinysoft_terms(self) -> None:
description = frontmatter(SKILL_FILE)["description"]
for term in ("TSL", "TSF", "TS-SQL", "Tinysoft", "天软", "脚本"):
self.assertIn(term, description)
def test_skill_requires_safe_two_stage_lookup(self) -> None:
text = read_text(SKILL_FILE)
self.assertRegex(text, r"--query[^\n]*(候选|Section ID)")
self.assertRegex(text, r"--section[^\n]*(正文|事实|章节)")
self.assertRegex(text, r"shell|命令注入|安全传参|原样拼接")
self.assertRegex(text, r"询问[^\n]*运行|如何运行")
self.assertIn("AGENTS.md", text)
self.assertRegex(text, r"可直接照写[^\n]*(不等于|不代表)[^\n]*(验证|可用)")
def test_concept_map_is_plain_text_without_navigation_or_code(self) -> None:
rendered = lookup.render_concept_map(lookup.build_concept_map())
self.assertIsNone(re.search(r"\[[^\]]+\]\([^)]+\)", rendered))
self.assertNotIn("```", rendered)
self.assertNotIn("`", rendered)
def test_high_risk_reference_pages_defer_api_scope(self) -> None:
for name in (
"10_runtime_context_and_with.md",
"15_debug_and_profiler.md",
"22_matrix_deep_dive.md",
):
text = read_text(REFERENCES_DIR / name)
with self.subTest(page=name):
self.assertIn("tsl-api-reference", text)
self.assertRegex(text, r"签名|参数")
self.assertRegex(text, r"scope|环境|解释器|可用性")
def test_local_link_targets_includes_local_images(self) -> None:
text = "![local diagram](images/router.png)\n![remote](https://example.com/router.png)"
self.assertEqual(local_link_targets(text), ["images/router.png"])