okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

nekomimi.petssh: stage only sources on a remote host, not tool cachesc9b9960

main
1.4 KiB45 linesraw
1"""The bundle staged on a remote host holds the python sources and nothing a
2tool left in the tree: a cache directory would travel to every host, and
3shipping it changed what the host runs from."""
4
5import io
6from pathlib import Path
7import sys
8import tarfile
9import tempfile
10import unittest
11from unittest import mock
12
13sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "priv" / "python"))
14import albedo_bundle  # noqa: E402
15import albedo_ssh  # noqa: E402
16
17
18class ArchiveTest(unittest.TestCase):
19    def test_sources_travel_and_caches_do_not(self):
20        with tempfile.TemporaryDirectory() as scratch:
21            root = Path(scratch)
22            for name in (
23                "a.py",
24                "plugins/b.py",
25                "plugins/__pycache__/b.cpython-314.pyc",
26                ".ruff_cache/0.16.10/entry",
27                "plugins/.mypy_cache/meta.json",
28            ):
29                path = root / name
30                path.parent.mkdir(parents=True, exist_ok=True)
31                path.write_text("x")
32            with mock.patch.object(albedo_bundle, "ROOT", root):
33                data = albedo_ssh.archive()
34        names = {
35            name.removeprefix("./")
36            for name in tarfile.open(fileobj=io.BytesIO(data)).getnames()
37        }
38        self.assertEqual(
39            {name for name in names if not name.endswith(("plugins", "."))},
40            {"a.py", "plugins/b.py"},
41        )
42
43
44if __name__ == "__main__":
45    unittest.main()