"""Verify the standard Hugging Face loading path and all record checksums.""" import argparse import hashlib import json from pathlib import Path from datasets import load_dataset from huggingface_hub import DatasetCard, hf_hub_download def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--repo-id") parser.add_argument("--revision") args = parser.parse_args() root = Path(__file__).resolve().parents[1] if args.repo_id and not args.revision: parser.error("Remote checks require an exact --revision") source = args.repo_id or str(root) kwargs = {"revision": args.revision} if args.repo_id else {} if args.repo_id: manifest_path = Path(hf_hub_download(args.repo_id, "manifest.json", repo_type="dataset", **kwargs)) card_path = hf_hub_download(args.repo_id, "README.md", repo_type="dataset", **kwargs) card = DatasetCard.load(card_path) else: manifest_path = root / "manifest.json" card = DatasetCard.load(root / "README.md") if card.data.to_dict()["license"] != "mit": raise ValueError("Dataset card license mismatch") manifest = json.loads(manifest_path.read_text(encoding="utf-8")) seen = set() fields = {"id", "header", "formal_statement", "source_file", "source_sha256"} for split in ("test", "validation"): dataset = load_dataset(source, name="lean-4.36.0", split=split, **kwargs) if len(dataset) != 244 or set(dataset.column_names) != fields: raise ValueError(f"Unexpected loaded dataset shape: {split}") paths = [] for row in dataset: if row["id"] in seen: raise ValueError("Duplicate ID across splits") seen.add(row["id"]) paths.append(row["source_file"]) data = (row["header"] + row["formal_statement"]).encode("utf-8") if hashlib.sha256(data).hexdigest() != row["source_sha256"]: raise ValueError(f"Source checksum mismatch: {row['id']}") original_split = "Test" if split == "test" else "Valid" if row["source_file"] != f"MiniF2F/{original_split}/{row['id']}.lean": raise ValueError("Original split or filename changed") if paths != sorted(paths): raise ValueError("Dataset order is not deterministic") print(f"{split}: 244 records, exact source round trips and unique IDs verified", flush=True) for filename, expected in manifest["artifact_sha256"].items(): path = Path(hf_hub_download(args.repo_id, filename, repo_type="dataset", **kwargs)) if args.repo_id else root / filename if hashlib.sha256(path.read_bytes()).hexdigest() != expected: raise ValueError(f"Artifact checksum mismatch: {filename}") print("PASS: standard dataset loading, both splits, schema, provenance, and artifact hashes", flush=True) if __name__ == "__main__": main()