| 1 | #!/usr/bin/env python3 |
| 2 | """Check storage-host platform selection before any native rebuild can repair it.""" |
| 3 | |
| 4 | import io |
| 5 | import json |
| 6 | from pathlib import Path |
| 7 | import sys |
| 8 | import tarfile |
| 9 | import tempfile |
| 10 | import unittest |
| 11 | |
| 12 | import client |
| 13 | |
| 14 | |
| 15 | class PlatformTest(unittest.TestCase): |
| 16 | def test_only_darwin_arm64_optional_packages_are_imported(self): |
| 17 | with tempfile.TemporaryDirectory(prefix="infra-platform-", dir=client.ROOT) as temporary: |
| 18 | workspace = Path(temporary) / "main" |
| 19 | workspace.mkdir() |
| 20 | optional = {} |
| 21 | for platform, cpu in (("darwin", "arm64"), ("linux", "x64")): |
| 22 | name = f"@project-platform-test/{platform}-{cpu}" |
| 23 | package = dict(name=name, version="1.0.0", os=[platform], cpu=[cpu]) |
| 24 | content = json.dumps(package).encode() |
| 25 | archive = workspace / f"{platform}-{cpu}.tgz" |
| 26 | with tarfile.open(archive, "w:gz") as output: |
| 27 | entry = tarfile.TarInfo("package/package.json") |
| 28 | entry.size = len(content) |
| 29 | output.addfile(entry, io.BytesIO(content)) |
| 30 | optional[name] = "file:" + archive.name |
| 31 | (workspace / "package.json").write_text(json.dumps(dict( |
| 32 | name="platform-fixture", private=True, packageManager="pnpm@12.14.0", |
| 33 | optionalDependencies=optional))) |
| 34 | response = client.request(dict(command="pnpm", cwd=str(workspace), |
| 35 | engine=client.engine(), args=["install", "--ignore-scripts"])) |
| 36 | self.assertEqual(response.returncode, 0) |
| 37 | result = json.loads(response.stdout) |
| 38 | self.assertIs(result.get("installed"), True, result) |
| 39 | client.finish_install(workspace, None, ignore_scripts=True, modules_hash=result["modules_hash"]) |
| 40 | packages = workspace / "node_modules/@project-platform-test" |
| 41 | self.assertTrue((packages / "darwin-arm64/package.json").is_file()) |
| 42 | self.assertFalse((packages / "linux-x64").exists()) |
| 43 | |
| 44 | |
| 45 | if __name__ == "__main__": |
| 46 | if sys.platform != "darwin" or not client.ROOT.is_dir(): |
| 47 | sys.exit("Run this test in the development VM with Code mounted.") |
| 48 | unittest.main() |