feat(skill): 新增项目规范维护 Skill
This commit is contained in:
@@ -140,7 +140,7 @@ plan-change
|
||||
2. `dev/style`(已完成,基于项目视觉基线设计样式)
|
||||
3. `dev/form`(已完成,设计表单结构、响应布局和可访问性)
|
||||
4. `skill/guidance`(特殊样本已完成)
|
||||
5. `skill/guidance-edit`
|
||||
5. `skill/guidance-edit`(已完成,建立、检查和维护项目规范索引)
|
||||
|
||||
这里只实现读取和维护“当前项目自身规范”的机制,不随 CraftKit 提供任何来源项目规范。
|
||||
原前端导航能力由上述 Skill 的精确触发描述和 Codex 自动发现替代,不再维护独立路由 Skill。混合任务按 `style` → `component` → `form` → 前端设计或实现的依赖顺序处理。
|
||||
@@ -238,3 +238,4 @@ plan-change
|
||||
- [x] 完成 Git 高风险隔离集成样本:`integrate`。
|
||||
- [x] 完成知识管理批次:`trace`、`distill`、`lessons`、`worklog`。
|
||||
- [x] 完成前端辅助批次:`component`、`style`、`form`,并以精确触发替代独立路由。
|
||||
- [x] 完成项目规范维护能力:`guidance-edit`。
|
||||
|
||||
@@ -390,8 +390,10 @@
|
||||
"source-b:31dec2fa162b06d3": {
|
||||
"sourcePathHash": "31dec2fa162b06d379aa676d426d2de01c3b082061ff15adb7a8c721cd5635af",
|
||||
"sourceSha256": "a146d79ccfec7b1f9275cda8e6cf3ab1190430d0c3bc11886a722ce1d6fabc90",
|
||||
"status": "specified",
|
||||
"target": "plugins/skill/skills/guidance-edit"
|
||||
"status": "migrated",
|
||||
"target": "plugins/skill/skills/guidance-edit",
|
||||
"targetVersion": "0.1.0",
|
||||
"reviewedAt": "2026-08-25"
|
||||
},
|
||||
"source-b:988b200efd0b8be0": {
|
||||
"sourcePathHash": "988b200efd0b8be024060e0785da2f864bf7ee30d7c7b434fde7ab1e4cdcc9d8",
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
"""规范索引维护 Skill 的确定性行为测试。"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SKILL = ROOT / "plugins" / "skill" / "skills" / "guidance-edit"
|
||||
SCRIPT = SKILL / "scripts" / "check_index.py"
|
||||
|
||||
|
||||
class GuidanceEditTest(unittest.TestCase):
|
||||
"""验证索引检查器和读写职责边界。"""
|
||||
|
||||
def run_check(self, standards: Path) -> subprocess.CompletedProcess[str]:
|
||||
"""以 JSON 模式执行检查器。"""
|
||||
return subprocess.run(
|
||||
[sys.executable, str(SCRIPT), str(standards), "--json"],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
def test_clean_index_is_reachable(self) -> None:
|
||||
"""根索引能够逐级访问所有规范时应检查通过。"""
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
standards = Path(temp)
|
||||
(standards / "frontend").mkdir()
|
||||
(standards / "index.md").write_text(
|
||||
"[前端](frontend/index.md)\n", encoding="utf-8"
|
||||
)
|
||||
(standards / "frontend" / "index.md").write_text(
|
||||
"[组件](components.md)\n", encoding="utf-8"
|
||||
)
|
||||
(standards / "frontend" / "components.md").write_text(
|
||||
"# 组件\n", encoding="utf-8"
|
||||
)
|
||||
result = self.run_check(standards)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
report = json.loads(result.stdout)
|
||||
self.assertEqual([], report["unindexed"])
|
||||
self.assertEqual([], report["broken"])
|
||||
|
||||
def test_reports_unindexed_broken_and_cycle(self) -> None:
|
||||
"""未索引文件、失效链接和循环引用应同时报告。"""
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
standards = Path(temp)
|
||||
(standards / "index.md").write_text(
|
||||
"[主题](topic.md)\n[缺失](missing.md)\n", encoding="utf-8"
|
||||
)
|
||||
(standards / "topic.md").write_text(
|
||||
"[返回](index.md)\n", encoding="utf-8"
|
||||
)
|
||||
(standards / "orphan.md").write_text("# 未索引\n", encoding="utf-8")
|
||||
result = self.run_check(standards)
|
||||
self.assertEqual(1, result.returncode)
|
||||
report = json.loads(result.stdout)
|
||||
self.assertEqual(["orphan.md"], report["unindexed"])
|
||||
self.assertEqual("missing.md", report["broken"][0]["target"])
|
||||
self.assertTrue(report["cycles"])
|
||||
|
||||
def test_missing_entry_is_input_error(self) -> None:
|
||||
"""入口不存在时应返回输入错误,而不是覆盖问题。"""
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
result = self.run_check(Path(temp))
|
||||
self.assertEqual(2, result.returncode)
|
||||
self.assertIn("索引入口不存在", result.stderr)
|
||||
|
||||
def test_skill_separates_read_and_write_modes(self) -> None:
|
||||
"""检查默认只读,所有写入均需预览与确认。"""
|
||||
content = (SKILL / "SKILL.md").read_text(encoding="utf-8")
|
||||
self.assertIn("检查默认只读", content)
|
||||
self.assertIn("经用户确认后写入", content)
|
||||
self.assertIn("不强制创建固定层级", content)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user