#!/usr/bin/env python3
import json
import argparse
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--json", default="Temp/module_io_coverage_v1.json")
    args = parser.parse_args()
    
    path = ROOT / args.json
    if not path.exists():
        print(f"Coverage file not found: {path}")
        return 1
        
    data = json.loads(path.read_text(encoding="utf-8"))
    coverage = data.get("coverage_pct", 0)
    
    print(f"MODULE IO COVERAGE: {coverage:.1f}%")
    if coverage < 100:
        missing = [m["id"] for m in data.get("module_details", []) if not m["covered"]]
        print(f"Missing modules: {', '.join(missing)}")
        return 1
    
    print("PASS: Module IO schema coverage is 100%")
    return 0

if __name__ == "__main__":
    main()
