Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970"""The bundle staged on a remote host holds the python sources and nothing atool left in the tree: a cache directory would travel to every host, andshipping it changed what the host runs from."""
import iofrom pathlib import Pathimport subprocessimport sysimport tarfileimport tempfileimport unittestfrom unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "python"))import albedo_bundle # noqa: E402import albedo_ssh # noqa: E402
class ArchiveTest(unittest.TestCase): def test_read_only_source_directories_can_be_staged(self): with tempfile.TemporaryDirectory() as scratch: root = Path(scratch) / "bundle" plugins = root / "plugins" plugins.mkdir(parents=True) (plugins / "example.py").write_text("x") for directory in (root, plugins): directory.chmod(0o555) try: with mock.patch.object(albedo_bundle, "ROOT", root): data = albedo_ssh.archive() finally: for directory in (root, plugins): directory.chmod(0o755) destination = Path(scratch) / "remote" / "digest" subprocess.run( ["sh", "-c", albedo_ssh.stage_script(str(destination))], input=data, check=True, ) self.assertEqual((destination / "plugins/example.py").read_text(), "x") self.assertTrue((destination / "plugins").stat().st_mode & 0o200)
def test_sources_travel_and_caches_do_not(self): with tempfile.TemporaryDirectory() as scratch: root = Path(scratch) for name in ( "a.py", "plugins/b.py", "plugins/__pycache__/b.cpython-314.pyc", ".ruff_cache/0.16.10/entry", "plugins/.mypy_cache/meta.json", ): path = root / name path.parent.mkdir(parents=True, exist_ok=True) path.write_text("x") with mock.patch.object(albedo_bundle, "ROOT", root): data = albedo_ssh.archive() names = { name.removeprefix("./") for name in tarfile.open(fileobj=io.BytesIO(data)).getnames() } self.assertEqual( {name for name in names if not name.endswith(("plugins", "."))}, {"a.py", "plugins/b.py"}, )
if __name__ == "__main__": unittest.main()