Refactor code structure for improved readability and maintainability; optimize performance in key functions.
This commit is contained in:
48
scripts/corpus/check-determinism.py
Normal file
48
scripts/corpus/check-determinism.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check determinism by verifying manifest digests match stored values."""
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
MANIFEST = ROOT / "bench" / "golden-corpus" / "corpus-manifest.json"
|
||||
|
||||
|
||||
def sha256(path: Path) -> str:
|
||||
h = hashlib.sha256()
|
||||
with path.open("rb") as fh:
|
||||
while True:
|
||||
chunk = fh.read(8192)
|
||||
if not chunk:
|
||||
break
|
||||
h.update(chunk)
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if not MANIFEST.exists():
|
||||
print(f"Manifest not found: {MANIFEST}")
|
||||
return 1
|
||||
|
||||
data = json.loads(MANIFEST.read_text(encoding="utf-8"))
|
||||
mismatches = []
|
||||
for case in data.get("cases", []):
|
||||
path = ROOT / case["path"]
|
||||
manifest_path = path / "case-manifest.json"
|
||||
digest = f"sha256:{sha256(manifest_path)}"
|
||||
if digest != case.get("manifestDigest"):
|
||||
mismatches.append({"id": case.get("id"), "expected": case.get("manifestDigest"), "actual": digest})
|
||||
|
||||
if mismatches:
|
||||
print(json.dumps({"status": "fail", "mismatches": mismatches}, indent=2))
|
||||
return 1
|
||||
|
||||
print(json.dumps({"status": "ok", "checked": len(data.get("cases", []))}, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user