import importlib.util from pathlib import Path import tempfile import unittest ROOT = Path(__file__).resolve().parents[2] SPEC = importlib.util.spec_from_file_location('contracts', ROOT / 'scripts/lib/skill-contracts.py') CONTRACTS = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(CONTRACTS) class SkillContractTests(unittest.TestCase): def setUp(self): directory = tempfile.TemporaryDirectory() self.addCleanup(directory.cleanup) self.home = Path(directory.name) def write(self, relative, text): path = self.home / relative path.parent.mkdir(parents=True, exist_ok=True) path.write_text(text, encoding='utf-8') def test_reports_nothing_when_skills_are_absent(self): self.assertEqual([], CONTRACTS.check(self.home)) def test_passes_complete_skill_and_warns_on_missing_names(self): self.write('.claude/skills/apple-design/SKILL.md', ' '.join(CONTRACTS.CONTRACTS['apple-design'][1])) self.write('.agents/skills/impeccable/SKILL.md', 'critique audit') results = dict((message.split(' at ')[0], status) for status, message in CONTRACTS.check(self.home)) self.assertEqual({'Apple Design': 'PASS', 'Impeccable': 'WARN'}, results) def test_uses_highest_cached_plugin_version(self): tokens = ' '.join(CONTRACTS.CONTRACTS['impeccable'][1]) self.write('.claude/plugins/cache/impeccable/impeccable/4.10.0/skills/impeccable/SKILL.md', tokens) self.write('.claude/plugins/cache/impeccable/impeccable/4.9.2/skills/impeccable/SKILL.md', 'old') [(status, message)] = CONTRACTS.check(self.home) self.assertEqual('PASS', status) self.assertIn('4.10.0', message) if __name__ == '__main__': unittest.main()