#!/usr/bin/env python3 """Verify pinned Codex bytes without starting a provider process.""" import hashlib import os from pathlib import Path import platform import re import shutil import sys root = Path(__file__).resolve().parent.parent codex = root / "internal/runner/provider/codex" # The release pin on x86-64; the same release's arm64 build on an arm64 # CI machine (pins.go), where no release runs. if platform.machine().lower() in ("aarch64", "arm64"): pin = re.search(r'ExecutableSHA256Arm64\s+= "([a-f0-9]{64})"', (codex / "pins.go").read_text()) else: pin = re.search(r'const ExecutableSHA256 = "([a-f0-9]{64})"', (codex / "launcher.go").read_text()) path = os.environ.get("EQUIPO_CODEX_PATH") or shutil.which("codex") try: if not pin or not path or not os.access(path, os.X_OK): sys.exit(1) with open(path, "rb") as binary: if hashlib.file_digest(binary, "sha256").hexdigest() != pin[1]: sys.exit(1) except OSError: sys.exit(1)