Skills/Python: harden script edge cases and add regression tests (#24277)
* Skill creator: skip self-including .skill output * Skill creator tests: cover output-dir-inside-skill case * Skill validator: parse frontmatter robustly across newlines * Skill validator tests: add CRLF and malformed frontmatter coverage * Model usage: require positive --days value * Model usage tests: cover --days validation and filtering * Nano banana: close input image handles after loading * Skill validator: keep type hints compatible with older python * Changelog: credit @vincentkoc for Python skills hardening
This commit is contained in:
46
skills/skill-creator/scripts/test_quick_validate.py
Normal file
46
skills/skill-creator/scripts/test_quick_validate.py
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Regression tests for quick skill validation.
|
||||
"""
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from unittest import TestCase, main
|
||||
|
||||
from quick_validate import validate_skill
|
||||
|
||||
|
||||
class TestQuickValidate(TestCase):
|
||||
def setUp(self):
|
||||
self.temp_dir = Path(tempfile.mkdtemp(prefix="test_quick_validate_"))
|
||||
|
||||
def tearDown(self):
|
||||
import shutil
|
||||
|
||||
if self.temp_dir.exists():
|
||||
shutil.rmtree(self.temp_dir)
|
||||
|
||||
def test_accepts_crlf_frontmatter(self):
|
||||
skill_dir = self.temp_dir / "crlf-skill"
|
||||
skill_dir.mkdir(parents=True, exist_ok=True)
|
||||
content = "---\r\nname: crlf-skill\r\ndescription: ok\r\n---\r\n# Skill\r\n"
|
||||
(skill_dir / "SKILL.md").write_text(content, encoding="utf-8")
|
||||
|
||||
valid, message = validate_skill(skill_dir)
|
||||
|
||||
self.assertTrue(valid, message)
|
||||
|
||||
def test_rejects_missing_frontmatter_closing_fence(self):
|
||||
skill_dir = self.temp_dir / "bad-skill"
|
||||
skill_dir.mkdir(parents=True, exist_ok=True)
|
||||
content = "---\nname: bad-skill\ndescription: missing end\n# no closing fence\n"
|
||||
(skill_dir / "SKILL.md").write_text(content, encoding="utf-8")
|
||||
|
||||
valid, message = validate_skill(skill_dir)
|
||||
|
||||
self.assertFalse(valid)
|
||||
self.assertEqual(message, "Invalid frontmatter format")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user