"""Check the file contract between the ports worker and Vinix's ISO builder.""" import argparse import hashlib from importlib import import_module from pathlib import Path import sys import tempfile import unittest from unittest.mock import patch sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tools")) release_inputs = import_module("release-inputs") class ReleaseInputs(unittest.TestCase): def setUp(self): temp = tempfile.TemporaryDirectory() self.addCleanup(temp.cleanup) root = Path(temp.name) self.args = argparse.Namespace( arch="aarch64", native=root / "native", output=root / "arm64", release="iso-fixture", commit="a" * 40, repo=root / "repo", desktop=root / "desktop", graphics=root / "graphics", auditor=root / "audit", fingerprint="a" * 40) for name in ("bin/vinix-desktop", "sbin/vinix-session", "sbin/vinix-authd", "sbin/vinix-system", "sbin/vinix-account"): path = self.args.native / "usr" / name path.parent.mkdir(parents=True, exist_ok=True) path.write_bytes(b"\x7fELF\x02\x01" + bytes(12) + (183).to_bytes(2, "little")) path.chmod(0o755) def test_freezes_checked_inputs_and_passes_release_tag(self): names = ["initramfs.tar", "vinix-x11-arm64.tar.gz", "vinix-x11-arm64.tar.gz.sha256", "build-info"] def stage(argv, check): self.assertTrue(check) if argv[1].name == "bundle-x11.py": target = argv[-1] target.mkdir() sidecar = target / names[1] sidecar.write_bytes(b"sidecar") digest = hashlib.sha256(sidecar.read_bytes()).hexdigest() (target / names[2]).write_text(f"{digest} {sidecar.name}\n") else: self.assertEqual(argv[1].name, "stage-image.py") self.assertIn("--release=iso-fixture", argv) self.assertEqual(argv[-2:], ["--seed-client", self.args.graphics]) argv[5].mkdir() (argv[5] / names[0]).write_bytes(b"initramfs") with patch.object(release_inputs.subprocess, "run", side_effect=stage): release_inputs.assemble(self.args) output = self.args.output self.assertEqual((output / "build-info").read_text(), f"commit={self.args.commit}\nrelease=iso-fixture\narch=arm64\n") self.assertEqual((output / "SHA256SUMS").read_text().splitlines(), [ f"{hashlib.sha256((output / name).read_bytes()).hexdigest()} {name}" for name in sorted(names) ]) def test_rejects_native_program_for_the_other_cpu(self): self.args.arch = "x86_64" with self.assertRaisesRegex(ValueError, "wrong ELF architecture"): release_inputs.assemble(self.args) self.assertFalse(self.args.output.exists()) if __name__ == "__main__": unittest.main()