#!/usr/bin/env python3 """Compare the `digest ` lines of two run logs (deterministic runs). Usage: digest_compare.py A.log B.log → exit 0 when equal, 1 with the first difference. """ import sys from pathlib import Path def digests(path: str) -> list[str]: return [line.strip() for line in Path(path).read_text(errors="replace").splitlines() if line.startswith("digest ")] def main(argv: list[str]) -> int: if len(argv) != 3: print(__doc__.strip()) return 2 a, b = digests(argv[1]), digests(argv[2]) if not a and not b: print("FAIL: no digest lines") return 1 for k, (x, y) in enumerate(zip(a, b), 1): if x != y: print(f"FAIL: digest {k} differs\n {x}\n {y}") return 1 if len(a) != len(b): print(f"FAIL: {len(a)} vs {len(b)} digests") return 1 print(f"ok: {len(a)} digests equal, last {a[-1]}") return 0 if __name__ == "__main__": sys.exit(main(sys.argv))