mcp-sandbox-authority-boundary-profile / scripts /verify_bundle_manifest.py
msaleme's picture
Release v0.1.4 verifiable fixture bundle
ff61273 verified
Raw
History Blame
1.98 kB
#!/usr/bin/env python3
"""Verify a released synthetic fixture bundle after extracting it."""
from __future__ import annotations
import hashlib
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
MANIFEST = ROOT / "bundle-manifest.json"
def sha256(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()
def safe_relative(value: str) -> Path:
path = Path(value)
if path.is_absolute() or ".." in path.parts:
raise SystemExit(f"unsafe manifest path: {value}")
return path
def main() -> None:
if not MANIFEST.is_file():
raise SystemExit("missing bundle-manifest.json; run from an extracted fixture bundle")
manifest = json.loads(MANIFEST.read_text())
files = manifest.get("files")
if not isinstance(files, list) or not files:
raise SystemExit("manifest has no files list")
expected: set[Path] = set()
for item in files:
if not isinstance(item, dict):
raise SystemExit("manifest file entry is not an object")
relative = safe_relative(item.get("path", ""))
expected.add(relative)
path = ROOT / relative
if not path.is_file():
raise SystemExit(f"missing: {relative}")
if path.stat().st_size != item.get("bytes"):
raise SystemExit(f"size mismatch: {relative}")
if sha256(path) != item.get("sha256"):
raise SystemExit(f"digest mismatch: {relative}")
actual = {path.relative_to(ROOT) for path in ROOT.rglob("*") if path.is_file()}
allowed = expected | {Path("bundle-manifest.json")}
if actual != allowed:
unexpected = sorted(str(path) for path in actual - allowed)
missing = sorted(str(path) for path in allowed - actual)
raise SystemExit(f"bundle file set mismatch; unexpected={unexpected}; missing={missing}")
print(f"valid: {len(expected)} bundle files match bundle-manifest.json")
if __name__ == "__main__":
main()