#!/usr/bin/env python3
import json
import pathlib
import sys
from pack_rules import validate_pack


def _reject_nonfinite(token):
    raise ValueError(f"non-standard/non-finite JSON numeric token is not allowed: {token}")


def main():
    if len(sys.argv) != 2:
        print("usage: python run_checks.py <evidence-pack.json>")
        return 2
    path = pathlib.Path(sys.argv[1])
    try:
        pack = json.loads(path.read_text(encoding="utf-8"), parse_constant=_reject_nonfinite)
    except Exception as exc:
        print(json.dumps({"status": "ERROR", "error": str(exc)}, ensure_ascii=False, indent=2))
        return 2
    issues = validate_pack(pack)
    blockers = [x for x in issues if x["severity"] == "BLOCKER"]
    print(json.dumps({
        "status": "CONSISTENT" if not blockers else "BLOCKED",
        "blocker_count": len(blockers),
        "issues": issues,
        "note": "This checker tests consistency against declared evidence. It does not choose or approve the learner's final decision."
    }, ensure_ascii=False, indent=2))
    return 0 if not blockers else 1

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