run_6400_fuzz.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. """Run the active deterministic protocol fuzz and emit a receipt."""
  3. from __future__ import annotations
  4. import hashlib, json, os, subprocess, sys, time
  5. from pathlib import Path
  6. ROOT = Path(__file__).resolve().parents[1]
  7. def sha256(path: Path) -> str:
  8. h = hashlib.sha256()
  9. with path.open("rb") as stream:
  10. for block in iter(lambda: stream.read(1048576), b""): h.update(block)
  11. return h.hexdigest()
  12. def git(*args: str) -> str:
  13. return subprocess.check_output(["git", *args], cwd=ROOT, text=True).strip()
  14. def main() -> int:
  15. dirty = git("status", "--porcelain")
  16. if dirty:
  17. raise SystemExit("fuzz requires a clean source worktree")
  18. commit, tree = git("rev-parse", "HEAD"), git("rev-parse", "HEAD^{tree}")
  19. test = ROOT / "tests/manual_6400_fuzz.py"
  20. run_root = Path(os.environ.get("PROD2U_FUZZ_RUN_ROOT", "/data/prod2u/runs")) / ("6400-manual-fuzz-" + commit[:8])
  21. run_root.mkdir(parents=True, exist_ok=False)
  22. result = run_root / "fuzz-result.json"
  23. env = os.environ.copy(); env["PROD2U_FUZZ_RESULT"] = str(result)
  24. env.setdefault("PROD2U_FUZZ_ITERATIONS", "10000")
  25. started = time.monotonic()
  26. completed = subprocess.run([sys.executable, "-B", str(test)], cwd=ROOT, env=env, text=True, capture_output=True, check=False)
  27. status = "PASS" if completed.returncode == 0 and result.is_file() else "FAIL"
  28. receipt = {"schema":"prod2u-6400-manual-fuzz-receipt-v1","run_id":run_root.name,"status":status,"commit":commit,"tree":tree,"clean":not bool(dirty),"iterations":int(env["PROD2U_FUZZ_ITERATIONS"]),"duration_seconds":round(time.monotonic()-started,3),"result":json.loads(result.read_text()) if result.is_file() else None,"stdout":completed.stdout[-4000:],"stderr":completed.stderr[-4000:],"hardware":"NOT_RUN"}
  29. path = run_root / "fuzz-receipt.json"; path.write_text(json.dumps(receipt, indent=2, sort_keys=True) + "\n", encoding="utf-8")
  30. print(path); print("MANUAL_FUZZ_PASS" if status == "PASS" else "MANUAL_FUZZ_FAIL")
  31. return 0 if status == "PASS" else 1
  32. if __name__ == "__main__":
  33. raise SystemExit(main())