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 / "state" |
| 22 | workdir.mkdir() |
| 23 | return tmp_path |
| 24 | |
| 25 | def test_snapshot_no_ignore_includes_all(self, tmp_path: pathlib.Path) -> None: |
| 26 | root = self._make_repo(tmp_path) |
| 27 | workdir = root / "state" |
| 28 | (workdir / "a.scaffold").write_text("data") |
| 29 | (workdir / "b.scaffold").write_text("data") |
| 30 | |
| 31 | snap = self.plugin.snapshot(workdir) |
| 32 | assert "a.scaffold" in snap["files"] |
| 33 | assert "b.scaffold" in snap["files"] |
| 34 | |
| 35 | def test_snapshot_global_pattern_excluded(self, tmp_path: pathlib.Path) -> None: |
| 36 | root = self._make_repo(tmp_path) |
| 37 | workdir = root / "state" |
| 38 | (workdir / "keep.scaffold").write_text("keep") |
| 39 | (workdir / "skip.scaffold").write_text("skip") |
| 40 | (root / ".museignore").write_text('[global]\npatterns = ["skip.scaffold"]\n') |
| 41 | |
| 42 | snap = self.plugin.snapshot(workdir) |
| 43 | assert "keep.scaffold" in snap["files"] |
| 44 | assert "skip.scaffold" not in snap["files"] |
| 45 | |
| 46 | def test_snapshot_domain_specific_pattern_excluded( |
| 47 | self, tmp_path: pathlib.Path |
| 48 | ) -> None: |
| 49 | root = self._make_repo(tmp_path) |
| 50 | workdir = root / "state" |
| 51 | (workdir / "keep.scaffold").write_text("keep") |
| 52 | (workdir / "generated.scaffold").write_text("generated") |
| 53 | (root / ".museignore").write_text( |
| 54 | '[domain.scaffold]\npatterns = ["generated.scaffold"]\n' |
| 55 | ) |
| 56 | |
| 57 | snap = self.plugin.snapshot(workdir) |
| 58 | assert "keep.scaffold" in snap["files"] |
| 59 | assert "generated.scaffold" not in snap["files"] |
| 60 | |
| 61 | def test_snapshot_other_domain_pattern_not_applied( |
| 62 | self, tmp_path: pathlib.Path |
| 63 | ) -> None: |
| 64 | root = self._make_repo(tmp_path) |
| 65 | workdir = root / "state" |
| 66 | (workdir / "keep.scaffold").write_text("keep") |
| 67 | # This pattern belongs to the "midi" domain — must NOT affect scaffold. |
| 68 | (root / ".museignore").write_text( |
| 69 | '[domain.midi]\npatterns = ["keep.scaffold"]\n' |
| 70 | ) |
| 71 | |
| 72 | snap = self.plugin.snapshot(workdir) |
| 73 | assert "keep.scaffold" in snap["files"] |
| 74 | |
| 75 | def test_snapshot_negation_un_ignores(self, tmp_path: pathlib.Path) -> None: |
| 76 | root = self._make_repo(tmp_path) |
| 77 | workdir = root / "state" |
| 78 | (workdir / "important.scaffold").write_text("keep me") |
| 79 | (workdir / "other.scaffold").write_text("discard") |
| 80 | (root / ".museignore").write_text( |
| 81 | '[global]\npatterns = ["*.scaffold", "!important.scaffold"]\n' |
| 82 | ) |
| 83 | |
| 84 | snap = self.plugin.snapshot(workdir) |
| 85 | assert "important.scaffold" in snap["files"] |
| 86 | assert "other.scaffold" not in snap["files"] |
| 87 | |
| 88 | def test_snapshot_domain_negation_overrides_global( |
| 89 | self, tmp_path: pathlib.Path |
| 90 | ) -> None: |
| 91 | root = self._make_repo(tmp_path) |
| 92 | workdir = root / "state" |
| 93 | (workdir / "keep.scaffold").write_text("keep") |
| 94 | (root / ".museignore").write_text( |
| 95 | '[global]\npatterns = ["*.scaffold"]\n' |
| 96 | '[domain.scaffold]\npatterns = ["!keep.scaffold"]\n' |
| 97 | ) |
| 98 | |
| 99 | snap = self.plugin.snapshot(workdir) |
| 100 | # keep.scaffold globally ignored but un-ignored by domain section. |
| 101 | assert "keep.scaffold" in snap["files"] |
| 102 | |
| 103 | def test_snapshot_empty_museignore(self, tmp_path: pathlib.Path) -> None: |
| 104 | root = self._make_repo(tmp_path) |
| 105 | workdir = root / "state" |
| 106 | (workdir / "a.scaffold").write_text("data") |
| 107 | (root / ".museignore").write_text("# empty\n") |
| 108 | |
| 109 | snap = self.plugin.snapshot(workdir) |
| 110 | assert "a.scaffold" in snap["files"] |
| 111 | |
| 112 | def test_snapshot_domain_is_scaffold(self, tmp_path: pathlib.Path) -> None: |
| 113 | root = self._make_repo(tmp_path) |
| 114 | workdir = root / "state" |
| 115 | (workdir / "a.scaffold").write_text("data") |
| 116 | |
| 117 | snap = self.plugin.snapshot(workdir) |
| 118 | assert snap["domain"] == "scaffold" |