|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Regression checks for skills committed in this repository. |
| 4 | +""" |
| 5 | + |
| 6 | +from __future__ import annotations |
| 7 | + |
| 8 | +import sys |
| 9 | +import tempfile |
| 10 | +from pathlib import Path |
| 11 | +from unittest import TestCase, TextTestRunner, defaultTestLoader |
| 12 | + |
| 13 | +SCRIPT_DIR = Path(__file__).resolve().parent |
| 14 | +REPO_ROOT = SCRIPT_DIR.parent |
| 15 | +SKILLS_ROOT = REPO_ROOT / "skills" |
| 16 | +SKILL_CREATOR_SCRIPTS = SKILLS_ROOT / "skill-creator" / "scripts" |
| 17 | +SKILL_DOC_FILENAME = "SKILL.md" |
| 18 | + |
| 19 | +if str(SKILL_CREATOR_SCRIPTS) not in sys.path: |
| 20 | + sys.path.insert(0, str(SKILL_CREATOR_SCRIPTS)) |
| 21 | + |
| 22 | +from package_skill import package_skill |
| 23 | +from quick_validate import validate_skill |
| 24 | + |
| 25 | + |
| 26 | +def iter_skill_dirs() -> list[Path]: |
| 27 | + return sorted(skill_md.parent for skill_md in SKILLS_ROOT.glob(f"*/{SKILL_DOC_FILENAME}")) |
| 28 | + |
| 29 | + |
| 30 | +class TestRepositorySkills(TestCase): |
| 31 | + def test_repository_contains_skills(self) -> None: |
| 32 | + self.assertTrue(iter_skill_dirs(), f"No skills found under {SKILLS_ROOT}") |
| 33 | + |
| 34 | + def test_all_repository_skills_validate(self) -> None: |
| 35 | + for skill_dir in iter_skill_dirs(): |
| 36 | + with self.subTest(skill=skill_dir.name): |
| 37 | + valid, message = validate_skill(skill_dir) |
| 38 | + self.assertTrue(valid, f"{skill_dir.name}: {message}") |
| 39 | + |
| 40 | + def test_all_repository_skills_package(self) -> None: |
| 41 | + with tempfile.TemporaryDirectory(prefix="test_repo_skills_") as temp_dir: |
| 42 | + output_dir = Path(temp_dir) |
| 43 | + for skill_dir in iter_skill_dirs(): |
| 44 | + with self.subTest(skill=skill_dir.name): |
| 45 | + result = package_skill(skill_dir, output_dir) |
| 46 | + self.assertIsNotNone(result, f"{skill_dir.name}: packaging failed") |
| 47 | + self.assertTrue(result.exists(), f"{skill_dir.name}: archive missing") |
| 48 | + |
| 49 | + |
| 50 | +def main() -> int: |
| 51 | + suite = defaultTestLoader.loadTestsFromTestCase(TestRepositorySkills) |
| 52 | + result = TextTestRunner(verbosity=2).run(suite) |
| 53 | + return 0 if result.wasSuccessful() else 1 |
| 54 | + |
| 55 | + |
| 56 | +if __name__ == "__main__": |
| 57 | + sys.exit(main()) |
0 commit comments