"""Validate the macOS packaging metadata without requiring a macOS host.""" import importlib.util import plistlib import tempfile import unittest from pathlib import Path spec = importlib.util.spec_from_file_location("macos_package", Path(__file__).with_name("package-macos-worker.py")) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) class PackagingTests(unittest.TestCase): def test_bundle(self): with tempfile.TemporaryDirectory() as root: root = Path(root) binary = root / "worker" binary.write_bytes(b"test-worker") target = root / "Worker.app" executable = module.package_worker(binary, target) self.assertEqual(executable.read_bytes(), binary.read_bytes()) self.assertTrue(executable.stat().st_mode & 0o100) data = plistlib.loads((target / "Contents/Info.plist").read_bytes()) self.assertEqual(data["LSMinimumSystemVersion"], "11.0") self.assertTrue(data["LSUIElement"]) self.assertTrue(data["NSAppTransportSecurity"]["NSAllowsLocalNetworking"]) with self.assertRaises(ValueError): module.package_worker(binary, target) with self.assertRaises(ValueError): module.package_worker(root / "missing", root / "Missing.app") if __name__ == "__main__": unittest.main()