The skill itself read as too detailed. SKILL.md is now a short checklist (460 words, was 1,321): 5 steps, 5 rules, and 6 one-line "don't miss" checks that replace the 12 Tebra failure classes (failure-classes.md removed). The MEK Charge Reconciliation SOP - the 3-page PDF ops liked - replaces the Tebra example as the model (emails swapped for examples). New test keeps SKILL.md under 500 words with 6 checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
3.4 KiB
Python
78 lines
3.4 KiB
Python
"""Python templates must stay valid Python before their placeholders are filled."""
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
HOOK_RULES = "E9,F63,F7,F82,F811" # same rule set as the PostToolUse lint hook
|
|
|
|
|
|
@pytest.mark.parametrize("template", ["skills/rpa-dashboard-no-ai/templates/bridge.py",
|
|
"skills/rpa-dashboard-no-ai/templates/bot_runner.py",
|
|
"skills/rpa-dashboard-ai/templates/desktop/ai_bridge.py"])
|
|
def test_template_passes_lint_hook_unfilled(template):
|
|
ruff = shutil.which("ruff") or pytest.skip("ruff not on PATH")
|
|
r = subprocess.run([ruff, "check", "--select", HOOK_RULES, "--no-cache", str(ROOT / template)],
|
|
capture_output=True, text=True)
|
|
assert r.returncode == 0, r.stdout
|
|
|
|
|
|
def test_tebra_sky_preset_is_the_template_default():
|
|
templates = ROOT / "skills" / "rpa-dashboard-no-ai" / "templates"
|
|
themes = (templates / "themes.md").read_text(encoding="utf-8")
|
|
sky = themes.split("## 1. Tebra Sky")[1].split("```css\n")[1].split("```")[0]
|
|
assert sky in (templates / "dashboard.html").read_text(encoding="utf-8")
|
|
|
|
|
|
@pytest.mark.parametrize("skill", ["rpa-dashboard-no-ai", "rpa-dashboard-ai", "rpa-bot-handoff"])
|
|
def test_skill_description_fits_the_1024_char_limit(skill):
|
|
text = (ROOT / "skills" / skill / "SKILL.md").read_text(encoding="utf-8")
|
|
description = re.search(r"^description: (.+)$", text, re.MULTILINE)[1]
|
|
assert len(description) <= 1024, len(description)
|
|
|
|
|
|
def test_ai_skill_references_files_that_exist():
|
|
skill = ROOT / "skills" / "rpa-dashboard-ai"
|
|
text = (skill / "SKILL.md").read_text(encoding="utf-8")
|
|
paths = re.findall(r"`((?:templates/|<no-ai>)[\w./-]+)`", text)
|
|
assert len(paths) > 5
|
|
missing = [p for p in paths
|
|
if not (skill / p.replace("<no-ai>", "../rpa-dashboard-no-ai/templates/")).exists()]
|
|
assert not missing
|
|
|
|
|
|
def test_handoff_skill_references_files_that_exist():
|
|
skill = ROOT / "skills" / "rpa-bot-handoff"
|
|
paths = re.findall(r"`(templates/[\w./-]+)`", (skill / "SKILL.md").read_text(encoding="utf-8"))
|
|
assert len(paths) >= 3
|
|
assert not [p for p in paths if not (skill / p).exists()]
|
|
|
|
|
|
def test_handoff_skill_stays_short():
|
|
skill = (ROOT / "skills" / "rpa-bot-handoff" / "SKILL.md").read_text(encoding="utf-8")
|
|
assert len(skill.split()) <= 500, len(skill.split())
|
|
assert len(re.findall(r"^\d+\. ", skill.split("## Don't miss")[1], re.MULTILINE)) == 6
|
|
|
|
|
|
def test_handoff_sop_has_five_sections_in_order():
|
|
sop = (ROOT / "skills" / "rpa-bot-handoff" / "templates" / "HANDOVER-SOP.md").read_text(encoding="utf-8")
|
|
assert re.search(r"^# \{\{PROJECT_NAME\}\} Handover SOP$", sop, re.MULTILINE)
|
|
assert [int(n) for n in re.findall(r"^## (\d+)\.", sop, re.MULTILINE)] == list(range(1, 6))
|
|
|
|
|
|
def test_handoff_sop_emails_the_developer_with_the_manager_in_cc():
|
|
sop = (ROOT / "skills" / "rpa-bot-handoff" / "templates" / "HANDOVER-SOP.md").read_text(encoding="utf-8")
|
|
email = sop.split("## 5.")[1]
|
|
assert "To: {{DEV_EMAIL}}" in email and "CC: {{MANAGER_EMAIL}}" in email
|
|
|
|
|
|
def test_handoff_docx_selfcheck():
|
|
pytest.importorskip("docx")
|
|
script = ROOT / "skills" / "rpa-bot-handoff" / "templates" / "to_docx.py"
|
|
r = subprocess.run([sys.executable, str(script), "--selfcheck"], capture_output=True, text=True)
|
|
assert r.returncode == 0, r.stderr
|