test_scaffold_plugin.py
python
| 1 | """Tests for muse/plugins/scaffold/plugin.py — snapshot .museignore integration. |
| 2 | |
| 3 | Verifies that the scaffold plugin reference implementation correctly honours |
| 4 | the TOML .museignore file during snapshot(), including global patterns, domain- |
| 5 | specific patterns, negation, and cross-domain isolation. |
| 6 | """ |
| 7 | |
| 8 | from __future__ import annotations |
| 9 | |
| 10 | import pathlib |
| 11 | |
| 12 | from muse.plugins.scaffold.plugin import ScaffoldPlugin |
| 13 | |
| 14 | |
| 15 | class TestScaffoldPluginSnapshot: |
| 16 | """ScaffoldPlugin.snapshot() honours .museignore TOML rules.""" |
| 17 | |
| 18 | plugin = ScaffoldPlugin() |
| 19 | |
| 20 | def _make_repo(self, tmp_path: pathlib.Path) -> pathlib.Path: |
| 21 | workdir = tmp_path |
| 22 | return tmp_path |
| 23 | |
| 24 | def test_snapshot_no_ignore_includes_all(self, tmp_path: pathlib.Path) -> None: |
| 25 | root = self._make_repo(tmp_path) |
| 26 | workdir = root |
| 27 | (workdir / "a.scaffold").write_text("data") |
| 28 | (workdir / "b.scaffold").write_text("data") |
| 29 | |
| 30 | snap = self.plugin.snapshot(workdir) |
| 31 | assert "a.scaffold" in snap["files"] |
| 32 | assert "b.scaffold" in snap["files"] |
| 33 | |
| 34 | def test_snapshot_global_pattern_excluded(self, tmp_path: pathlib.Path) -> None: |
| 35 | root = self._make_repo(tmp_path) |
| 36 | workdir = root |
| 37 | (workdir / "keep.scaffold").write_text("keep") |
| 38 | (workdir / "skip.scaffold").write_text("skip") |
| 39 | (root / ".museignore").write_text('[global]\npatterns = ["skip.scaffold"]\n') |
| 40 | |
| 41 | snap = self.plugin.snapshot(workdir) |
| 42 | assert "keep.scaffold" in snap["files"] |
| 43 | assert "skip.scaffold" not in snap["files"] |
| 44 | |
| 45 | def test_snapshot_domain_specific_pattern_excluded( |
| 46 | self, tmp_path: pathlib.Path |
| 47 | ) -> None: |
| 48 | root = self._make_repo(tmp_path) |
| 49 | workdir = root |
| 50 | (workdir / "keep.scaffold").write_text("keep") |
| 51 | (workdir / "generated.scaffold").write_text("generated") |
| 52 | (root / ".museignore").write_text( |
| 53 | '[domain.scaffold]\npatterns = ["generated.scaffold"]\n' |
| 54 | ) |
| 55 | |
| 56 | snap = self.plugin.snapshot(workdir) |
| 57 | assert "keep.scaffold" in snap["files"] |
| 58 | assert "generated.scaffold" not in snap["files"] |
| 59 | |
| 60 | def test_snapshot_other_domain_pattern_not_applied( |
| 61 | self, tmp_path: pathlib.Path |
| 62 | ) -> None: |
| 63 | root = self._make_repo(tmp_path) |
| 64 | workdir = root |
| 65 | (workdir / "keep.scaffold").write_text("keep") |
| 66 | # This pattern belongs to the "midi" domain — must NOT affect scaffold. |
| 67 | (root / ".museignore").write_text( |
| 68 | '[domain.midi]\npatterns = ["keep.scaffold"]\n' |
| 69 | ) |
| 70 | |
| 71 | snap = self.plugin.snapshot(workdir) |
| 72 | assert "keep.scaffold" in snap["files"] |
| 73 | |
| 74 | def test_snapshot_negation_un_ignores(self, tmp_path: pathlib.Path) -> None: |
| 75 | root = self._make_repo(tmp_path) |
| 76 | workdir = root |
| 77 | (workdir / "important.scaffold").write_text("keep me") |
| 78 | (workdir / "other.scaffold").write_text("discard") |
| 79 | (root / ".museignore").write_text( |
| 80 | '[global]\npatterns = ["*.scaffold", "!important.scaffold"]\n' |
| 81 | ) |
| 82 | |
| 83 | snap = self.plugin.snapshot(workdir) |
| 84 | assert "important.scaffold" in snap["files"] |
| 85 | assert "other.scaffold" not in snap["files"] |
| 86 | |
| 87 | def test_snapshot_domain_negation_overrides_global( |
| 88 | self, tmp_path: pathlib.Path |
| 89 | ) -> None: |
| 90 | root = self._make_repo(tmp_path) |
| 91 | workdir = root |
| 92 | (workdir / "keep.scaffold").write_text("keep") |
| 93 | (root / ".museignore").write_text( |
| 94 | '[global]\npatterns = ["*.scaffold"]\n' |
| 95 | '[domain.scaffold]\npatterns = ["!keep.scaffold"]\n' |
| 96 | ) |
| 97 | |
| 98 | snap = self.plugin.snapshot(workdir) |
| 99 | # keep.scaffold globally ignored but un-ignored by domain section. |
| 100 | assert "keep.scaffold" in snap["files"] |
| 101 | |
| 102 | def test_snapshot_empty_museignore(self, tmp_path: pathlib.Path) -> None: |
| 103 | root = self._make_repo(tmp_path) |
| 104 | workdir = root |
| 105 | (workdir / "a.scaffold").write_text("data") |
| 106 | (root / ".museignore").write_text("# empty\n") |
| 107 | |
| 108 | snap = self.plugin.snapshot(workdir) |
| 109 | assert "a.scaffold" in snap["files"] |
| 110 | |
| 111 | def test_snapshot_domain_is_scaffold(self, tmp_path: pathlib.Path) -> None: |
| 112 | root = self._make_repo(tmp_path) |
| 113 | workdir = root |
| 114 | (workdir / "a.scaffold").write_text("data") |
| 115 | |
| 116 | snap = self.plugin.snapshot(workdir) |
| 117 | assert snap["domain"] == "scaffold" |