-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_skills.py
More file actions
91 lines (75 loc) · 2.88 KB
/
test_skills.py
File metadata and controls
91 lines (75 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import re
import pytest
from conftest import REPO_ROOT, parse_frontmatter, get_markdown_sections, get_body
REQUIRED_SECTIONS = [
"Trigger",
"Required Inputs",
"Workflow",
"Example Interaction",
]
def _read_skill(skill_dir):
path = os.path.join(REPO_ROOT, "skills", skill_dir, "SKILL.md")
with open(path, "r", encoding="utf-8") as f:
return f.read()
def test_all_skills_have_skill_md(skill_dirs):
for skill_dir in skill_dirs:
path = os.path.join(REPO_ROOT, "skills", skill_dir, "SKILL.md")
assert os.path.isfile(path), f"Missing SKILL.md in skills/{skill_dir}/"
@pytest.mark.parametrize(
"skill_dir",
sorted(
[
d
for d in os.listdir(os.path.join(REPO_ROOT, "skills"))
if os.path.isdir(os.path.join(REPO_ROOT, "skills", d))
]
),
)
class TestSkill:
def test_has_frontmatter(self, skill_dir):
text = _read_skill(skill_dir)
fm = parse_frontmatter(text)
assert fm is not None, f"skills/{skill_dir}/SKILL.md missing YAML frontmatter"
def test_name_matches_directory(self, skill_dir):
text = _read_skill(skill_dir)
fm = parse_frontmatter(text)
assert (
fm.get("name") == skill_dir
), f"Frontmatter name '{fm.get('name')}' does not match directory '{skill_dir}'"
def test_has_description(self, skill_dir):
text = _read_skill(skill_dir)
fm = parse_frontmatter(text)
desc = fm.get("description", "")
assert len(desc) >= 20, (
f"skills/{skill_dir}/SKILL.md description too short: {len(desc)} chars"
)
def test_has_h1(self, skill_dir):
text = _read_skill(skill_dir)
body = get_body(text)
assert re.search(
r"^# .+$", body, re.MULTILINE
), f"skills/{skill_dir}/SKILL.md missing H1 heading"
def test_has_required_sections(self, skill_dir):
text = _read_skill(skill_dir)
sections = get_markdown_sections(text)
for section in REQUIRED_SECTIONS:
assert (
section in sections
), f"skills/{skill_dir}/SKILL.md missing required section: ## {section}"
def test_minimum_length(self, skill_dir):
text = _read_skill(skill_dir)
lines = text.strip().split("\n")
assert len(lines) >= 50, (
f"skills/{skill_dir}/SKILL.md too short: {len(lines)} lines (minimum 50)"
)
def test_internal_links_resolve(self, skill_dir):
text = _read_skill(skill_dir)
links = re.findall(r"\]\(\.\./([^)]+)\)", text)
skill_base = os.path.join(REPO_ROOT, "skills", skill_dir)
for link in links:
target = os.path.join(skill_base, "..", link)
target = os.path.normpath(target)
assert os.path.exists(target), (
f"skills/{skill_dir}/SKILL.md has broken link: ../{link}"
)