#!/usr/bin/env python3
"""Create a four-byte fixture and ask Reverify to judge two byte claims."""

from __future__ import annotations

import json
import subprocess
import sys
import tempfile
from pathlib import Path


def main() -> int:
    checkout = Path(sys.argv[1]).resolve()
    cli = checkout / "reverify" / "cli.py"
    with tempfile.TemporaryDirectory() as temporary:
        fixture = Path(temporary) / "fixture.bin"
        claims = Path(temporary) / "claims.json"
        fixture.write_bytes(bytes.fromhex("4d5a9000"))
        claims.write_text(
            json.dumps(
                [
                    {"kind": "bytes_at", "offset": 0, "expected": "4d5a"},
                    {"kind": "bytes_at", "offset": 0, "expected": "7f45"},
                ]
            ),
            encoding="utf-8",
        )
        result = subprocess.run(
            [sys.executable, str(cli), "verify", str(fixture), "--claims-file", str(claims), "--json"],
            text=True,
            capture_output=True,
        )
    report = json.loads(result.stdout)
    print(
        "claims=%d verified=%d refuted=%d grounded=%s exit=%d"
        % (report["total_claims"], report["verified"], report["refuted"], report["grounded"], result.returncode)
    )
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
