-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rules.py
More file actions
69 lines (58 loc) · 2.1 KB
/
test_rules.py
File metadata and controls
69 lines (58 loc) · 2.1 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
import os
import re
import pytest
from conftest import REPO_ROOT, parse_frontmatter, get_body
def _read_rule(rule_file):
path = os.path.join(REPO_ROOT, "rules", rule_file)
with open(path, "r", encoding="utf-8") as f:
return f.read()
@pytest.mark.parametrize(
"rule_file",
sorted(
[
f
for f in os.listdir(os.path.join(REPO_ROOT, "rules"))
if f.endswith(".mdc")
]
),
)
class TestRule:
def test_has_frontmatter(self, rule_file):
text = _read_rule(rule_file)
fm = parse_frontmatter(text)
assert fm is not None, f"rules/{rule_file} missing YAML frontmatter"
def test_has_description(self, rule_file):
text = _read_rule(rule_file)
fm = parse_frontmatter(text)
desc = fm.get("description", "")
assert len(desc) >= 10, (
f"rules/{rule_file} description too short: {len(desc)} chars"
)
def test_has_always_apply(self, rule_file):
text = _read_rule(rule_file)
fm = parse_frontmatter(text)
assert "alwaysApply" in fm, f"rules/{rule_file} missing alwaysApply field"
assert isinstance(
fm["alwaysApply"], bool
), f"rules/{rule_file} alwaysApply must be a boolean"
def test_scoped_rules_have_globs(self, rule_file):
text = _read_rule(rule_file)
fm = parse_frontmatter(text)
if not fm.get("alwaysApply", False):
globs = fm.get("globs", [])
assert isinstance(globs, list) and len(globs) > 0, (
f"rules/{rule_file} has alwaysApply=false but no globs"
)
def test_has_h1(self, rule_file):
text = _read_rule(rule_file)
body = get_body(text)
assert re.search(
r"^# .+$", body, re.MULTILINE
), f"rules/{rule_file} missing H1 heading"
def test_minimum_length(self, rule_file):
text = _read_rule(rule_file)
body = get_body(text)
lines = body.strip().split("\n")
assert len(lines) >= 10, (
f"rules/{rule_file} body too short: {len(lines)} lines (minimum 10)"
)