|
| 1 | +"""Tests for .github/scripts/plugin-content-changed.sh (#350). Needs bash + git. |
| 2 | +
|
| 3 | +Run: python tests/test_plugin_content_changed.py -v |
| 4 | +""" |
| 5 | +from __future__ import annotations |
| 6 | + |
| 7 | +import shutil |
| 8 | +import subprocess |
| 9 | +import tempfile |
| 10 | +import unittest |
| 11 | +from pathlib import Path |
| 12 | + |
| 13 | +SCRIPT = Path(__file__).resolve().parent.parent / ".github" / "scripts" / "plugin-content-changed.sh" |
| 14 | +BASH = shutil.which("bash") |
| 15 | + |
| 16 | + |
| 17 | +def git(cwd, *args): |
| 18 | + subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True) |
| 19 | + |
| 20 | + |
| 21 | +@unittest.skipIf(BASH is None or shutil.which("git") is None, "bash/git not available") |
| 22 | +class PluginContentChanged(unittest.TestCase): |
| 23 | + def setUp(self): |
| 24 | + self.tmp = tempfile.TemporaryDirectory() |
| 25 | + self.repo = Path(self.tmp.name) |
| 26 | + git(self.repo, "init", "-q") |
| 27 | + git(self.repo, "config", "user.email", "t@example.com") |
| 28 | + git(self.repo, "config", "user.name", "t") |
| 29 | + (self.repo / "skills" / "a").mkdir(parents=True) |
| 30 | + (self.repo / "skills" / "a" / "SKILL.md").write_text("one\n", encoding="utf-8") |
| 31 | + (self.repo / "README.md").write_text("readme\n", encoding="utf-8") |
| 32 | + git(self.repo, "add", "-A") |
| 33 | + git(self.repo, "commit", "-q", "-m", "base") |
| 34 | + git(self.repo, "tag", "v1") |
| 35 | + |
| 36 | + def tearDown(self): |
| 37 | + self.tmp.cleanup() |
| 38 | + |
| 39 | + def changed(self): |
| 40 | + return subprocess.run([BASH, SCRIPT.as_posix(), "v1"], cwd=self.repo).returncode == 0 |
| 41 | + |
| 42 | + def commit(self, rel, text): |
| 43 | + path = self.repo / rel |
| 44 | + path.parent.mkdir(parents=True, exist_ok=True) |
| 45 | + path.write_text(text, encoding="utf-8") |
| 46 | + git(self.repo, "add", "-A") |
| 47 | + git(self.repo, "commit", "-q", "-m", "docs: change") |
| 48 | + |
| 49 | + def test_no_change(self): |
| 50 | + self.assertFalse(self.changed()) |
| 51 | + |
| 52 | + def test_docs_outside_plugin_is_not_content(self): |
| 53 | + self.commit("README.md", "new readme\n") |
| 54 | + self.commit("docs/gallery/index.html", "<p>x</p>\n") |
| 55 | + self.assertFalse(self.changed()) |
| 56 | + |
| 57 | + def test_skill_edit_is_content(self): |
| 58 | + self.commit("skills/a/SKILL.md", "two\n") |
| 59 | + self.assertTrue(self.changed()) |
| 60 | + |
| 61 | + def test_rule_and_snippet_dirs_count(self): |
| 62 | + self.commit("snippets/x.py", "print(1)\n") |
| 63 | + self.assertTrue(self.changed()) |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == "__main__": |
| 67 | + unittest.main() |
0 commit comments