#!/usr/bin/env python3 # SPDX-License-Identifier: Apache-2.0 """Validate GauntletBench Hugging Face dataset package structure and release readiness.""" from __future__ import annotations import json import re from collections import Counter from pathlib import Path ROOT = Path(__file__).resolve().parents[1] DATA_PATH = ROOT / "data" / "test.jsonl" README_PATH = ROOT / "README.md" DATASET_LICENSE = ROOT / "LICENSE" CODE_LICENSE = ROOT / "LICENSE-APACHE" THIRD_PARTY = ROOT / "THIRD_PARTY_NOTICES.md" SUMMARY_PATH = ROOT / "metadata" / "summary.json" REPO_ID = "gauntletbench-flight/gauntletbench" FORBIDDEN_PATHS = ( ROOT / "UPLOAD_INSTRUCTIONS.md", ROOT / "scripts" / "upload_to_hf.sh", ) SECRET_PATTERNS = ( re.compile(r"hf_[A-Za-z0-9]{20,}"), re.compile(r"(?i)(api[_-]?key|secret|password|token)\s*[:=]\s*\S+"), re.compile(r"/Users/[^\s\"']+"), re.compile(r"@[a-zA-Z0-9._%+-]+\.[a-zA-Z]{2,}"), ) PLACEHOLDER_PATTERNS = ( re.compile(r"YOUR_HF_ORG", re.I), re.compile(r"TODO\b", re.I), re.compile(r"PLACEHOLDER", re.I), re.compile(r"example\.com", re.I), ) def fail(message: str) -> None: raise AssertionError(message) def read_text(path: Path) -> str: assert path.is_file(), f"Missing required file: {path.relative_to(ROOT)}" return path.read_text(encoding="utf-8") def parse_readme_front_matter(readme: str) -> dict: if not readme.startswith("---\n"): fail("README must begin with YAML front matter delimited by ---") end = readme.find("\n---\n", 4) if end == -1: fail("README front matter is not closed with ---") block = readme[4:end] try: import yaml except ImportError as e: raise SystemExit("PyYAML is required for README front matter validation") from e metadata = yaml.safe_load(block) if not isinstance(metadata, dict): fail("README front matter must parse to a mapping") return metadata def check_release_readiness() -> None: readme = read_text(README_PATH) front = parse_readme_front_matter(readme) body = readme.split("\n---\n", 2)[-1] license_value = str(front.get("license", "")).strip().lower() if license_value != "cc-by-4.0": fail(f"README front matter license must be cc-by-4.0, got {front.get('license')!r}") configs = front.get("configs") if not isinstance(configs, list) or not configs: fail("README front matter must declare configs for Dataset Viewer/Croissant") default = configs[0] if not isinstance(default, dict): fail("README configs entry must be a mapping") if default.get("config_name") != "default": fail("README configs must include config_name: default") data_files = default.get("data_files") if not isinstance(data_files, list) or not data_files: fail("README configs must declare data_files") test_entry = data_files[0] if test_entry.get("split") != "test" or test_entry.get("path") != "data/test.jsonl": fail("README must declare test split at data/test.jsonl") if not DATA_PATH.is_file(): fail("Declared data file data/test.jsonl is missing") required_sections = { "## License": "licensing", "## Intended use": "intended use", "## Limitations": "limitations", "## Responsible AI considerations": "responsible AI", "## Citation": "citation", "## Third-party materials and exclusions": "third-party exclusions", } for heading, label in required_sections.items(): if heading not in body: fail(f"README missing required {label} section: {heading}") if REPO_ID not in readme: fail(f"README must reference actual dataset repo id {REPO_ID}") for pattern in PLACEHOLDER_PATTERNS: if pattern.search(readme): fail(f"README contains placeholder pattern: {pattern.pattern}") dataset_license = read_text(DATASET_LICENSE) if "Creative Commons Attribution 4.0 International" not in dataset_license: fail("LICENSE must contain full CC BY 4.0 legal text") if "Apache License" in dataset_license: fail("Dataset LICENSE must not contain Apache license text") code_license = read_text(CODE_LICENSE) if "Apache License" not in code_license or "Version 2.0" not in code_license: fail("LICENSE-APACHE must contain full Apache-2.0 legal text") third_party = read_text(THIRD_PARTY) if "opensky-network.org" not in third_party.lower(): fail("THIRD_PARTY_NOTICES must attribute OpenSky with opensky-network.org URL") if "not redistributed" not in third_party.lower(): fail("THIRD_PARTY_NOTICES must state third-party apps/media are not redistributed") if "openstreetmap" in third_party.lower(): fail("Do not claim OpenStreetMap attribution without distributing OSM-derived material") if not SUMMARY_PATH.is_file(): fail("Missing dataset_summary.json metadata summary") for forbidden in FORBIDDEN_PATHS: if forbidden.exists(): fail(f"Internal upload artifact must be removed: {forbidden.relative_to(ROOT)}") self_path = Path(__file__).resolve() scanned_files = [ p for p in ROOT.rglob("*") if p.is_file() and ".git" not in p.parts and "__pycache__" not in p.parts ] for path in scanned_files: if path.resolve() == self_path: continue if path.is_symlink(): fail(f"Symlinks are not allowed: {path.relative_to(ROOT)}") text = path.read_text(encoding="utf-8", errors="ignore") patterns = list(SECRET_PATTERNS) if path == DATA_PATH: patterns = [p for p in patterns if "@" not in p.pattern] for pattern in patterns: if pattern.search(text): fail( f"Potential secret or personal path in {path.relative_to(ROOT)} " f"(pattern: {pattern.pattern})" ) def validate_rows() -> None: rows = [] with DATA_PATH.open(encoding="utf-8") as f: for lineno, line in enumerate(f, 1): try: rows.append(json.loads(line)) except Exception as e: raise SystemExit(f"Invalid JSON on line {lineno}: {e}") from e required = { "id", "application", "application_name", "task_number", "difficulty", "title", "prompt", "result_format", "ground_truth", "ground_truth_type", "source_page", } assert len(rows) == 100, f"Expected 100 rows, got {len(rows)}" assert len({r["id"] for r in rows}) == 100, "IDs are not unique" for r in rows: missing = required - r.keys() assert not missing, f"{r.get('id')}: missing {missing}" assert r["difficulty"] in {"easy", "medium", "hard"} assert r["ground_truth_type"] in {"text_answer", "application_state"} if r["ground_truth_type"] == "text_answer": assert r["ground_truth"] is not None json.loads(r["ground_truth"]) else: assert r["ground_truth"] is None apps = Counter(r["application"] for r in rows) diffs = Counter(r["difficulty"] for r in rows) gt = Counter(r["ground_truth_type"] for r in rows) assert set(apps.values()) == {20}, apps assert diffs == Counter({"hard": 45, "medium": 45, "easy": 10}), diffs assert gt == Counter({"application_state": 72, "text_answer": 28}), gt print("OK") print("rows:", len(rows)) print("applications:", dict(apps)) print("difficulty:", dict(diffs)) print("ground truth types:", dict(gt)) def main() -> None: check_release_readiness() validate_rows() print("release readiness: OK") if __name__ == "__main__": main()