From 2070a91ef7d714a4335a3564b7c6216821430cc0 Mon Sep 17 00:00:00 2001 From: sck_0 Date: Mon, 2 Feb 2026 21:34:14 +0100 Subject: [PATCH] test: add python validator heading detection --- scripts/tests/test_validate_skills_headings.py | 18 ++++++++++++++++++ scripts/validate_skills.py | 12 ++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 scripts/tests/test_validate_skills_headings.py diff --git a/scripts/tests/test_validate_skills_headings.py b/scripts/tests/test_validate_skills_headings.py new file mode 100644 index 00000000..d42a8de6 --- /dev/null +++ b/scripts/tests/test_validate_skills_headings.py @@ -0,0 +1,18 @@ +import os +import sys + +sys.path.append(os.path.dirname(os.path.dirname(__file__))) +from validate_skills import has_when_to_use_section + +SAMPLES = [ + ("## When to Use", True), + ("## Use this skill when", True), + ("## When to Use This Skill", True), + ("## Overview", False), +] + +for heading, expected in SAMPLES: + content = f"\n{heading}\n- item\n" + assert has_when_to_use_section(content) is expected, heading + +print("ok") diff --git a/scripts/validate_skills.py b/scripts/validate_skills.py index f3d796db..4c96fd64 100644 --- a/scripts/validate_skills.py +++ b/scripts/validate_skills.py @@ -3,6 +3,15 @@ import re import argparse import sys +WHEN_TO_USE_PATTERNS = [ + re.compile(r"^##\s+When\s+to\s+Use", re.MULTILINE | re.IGNORECASE), + re.compile(r"^##\s+Use\s+this\s+skill\s+when", re.MULTILINE | re.IGNORECASE), + re.compile(r"^##\s+When\s+to\s+Use\s+This\s+Skill", re.MULTILINE | re.IGNORECASE), +] + +def has_when_to_use_section(content): + return any(pattern.search(content) for pattern in WHEN_TO_USE_PATTERNS) + def parse_frontmatter(content): """ Simple frontmatter parser using regex to avoid external dependencies. @@ -30,7 +39,6 @@ def validate_skills(skills_dir, strict_mode=False): # Pre-compiled regex security_disclaimer_pattern = re.compile(r"AUTHORIZED USE ONLY", re.IGNORECASE) - trigger_section_pattern = re.compile(r"^##\s+When to Use", re.MULTILINE | re.IGNORECASE) valid_risk_levels = ["none", "safe", "critical", "offensive"] @@ -80,7 +88,7 @@ def validate_skills(skills_dir, strict_mode=False): else: warnings.append(msg) # 3. Content Checks (Triggers) - if not trigger_section_pattern.search(content): + if not has_when_to_use_section(content): msg = f"⚠️ {rel_path}: Missing '## When to Use' section" if strict_mode: errors.append(msg.replace("⚠️", "❌")) else: warnings.append(msg)