| 1 | #!/usr/bin/env python3 |
| 2 | """Check the pinned programs before either versioned release is built. |
| 3 | |
| 4 | internal/release/manifest.json pins the four programs this repository does |
| 5 | not build: claude, codex, codex-code-mode-host and bwrap. A release is |
| 6 | refused unless the manifest, the pins in the provider packages and the |
| 7 | programs installed on this machine all name the same bytes. The tool |
| 8 | proxy is not pinned here: it is built with the release, and its digest is |
| 9 | recorded then (scripts/runner-install-manifest.py). |
| 10 | """ |
| 11 | import hashlib |
| 12 | import json |
| 13 | import os |
| 14 | from pathlib import Path |
| 15 | import re |
| 16 | import subprocess |
| 17 | import sys |
| 18 | |
| 19 | root = Path(__file__).resolve().parent.parent |
| 20 | variables = {"claude": "EQUIPO_CLAUDE_PATH", "codex": "EQUIPO_CODEX_PATH", |
| 21 | "codex-code-mode-host": "EQUIPO_CODEX_CODE_MODE_HOST_PATH", "bwrap": "EQUIPO_BWRAP_PATH"} |
| 22 | |
| 23 | |
| 24 | def require(condition): |
| 25 | if not condition: |
| 26 | raise ValueError("release pins do not agree") |
| 27 | |
| 28 | |
| 29 | def digest(path): |
| 30 | with path.open("rb") as source: |
| 31 | return hashlib.file_digest(source, "sha256").hexdigest() |
| 32 | |
| 33 | |
| 34 | def constant(path, name): |
| 35 | found = re.search(r'\b' + name + r'\s+= "([^"]+)"', (root / path).read_text()) |
| 36 | require(found) |
| 37 | return found[1] |
| 38 | |
| 39 | |
| 40 | try: |
| 41 | subprocess.run([sys.executable, str(root / "scripts/plan3-copy-check.py")], check=True) |
| 42 | manifest = json.loads((root / "internal/release/manifest.json").read_text()) |
| 43 | require(manifest["schema"] == 3 and manifest["runner_target"] == "linux/amd64") |
| 44 | require(manifest["launcher_version"] == constant("internal/runner/provider/types.go", "LauncherVersion")) |
| 45 | require(manifest["policy_version"] == constant("internal/runner/provider/policy.go", "PolicyVersion")) |
| 46 | require(manifest["bwrap_version"] == "0.11.0") |
| 47 | require(manifest["claude"] == constant("internal/runner/provider/types.go", "ClaudeVersion")) |
| 48 | require(manifest["codex"] == constant("internal/runner/provider/types.go", "CodexVersion")) |
| 49 | require([b["name"] for b in manifest["binaries"]] == list(variables)) |
| 50 | for artifact in manifest["binaries"]: |
| 51 | name = artifact["name"] |
| 52 | path = Path(os.environ[variables[name]]) |
| 53 | require(path.is_absolute() and path.is_file() and os.access(path, os.X_OK)) |
| 54 | require(artifact["version"] == manifest[{"bwrap": "bwrap_version", "codex-code-mode-host": "codex"}.get(name, name)]) |
| 55 | require(re.fullmatch(r"[a-f0-9]{64}", artifact["sha256"]) and digest(path) == artifact["sha256"]) |
| 56 | if name == "bwrap": |
| 57 | require(subprocess.check_output([str(path), "--version"], timeout=5).decode().strip() == "bubblewrap 0.11.0") |
| 58 | else: |
| 59 | family = "codex" if name == "codex-code-mode-host" else name |
| 60 | pin = "CodeModeHostSHA256" if name == "codex-code-mode-host" else "ExecutableSHA256" |
| 61 | require(artifact["sha256"] == constant(f"internal/runner/provider/{family}/launcher.go", "const " + pin)) |
| 62 | except (ValueError, KeyError, OSError, TypeError, subprocess.SubprocessError): |
| 63 | sys.exit(1) |
| 64 | |