Download scripts/validate_delivery.py from LianeMarilin/ECG-EdgeBench: direct link, hf CLI and curl.
- Browser
- Download file 4.47 kB
-
https://huggingface.co/datasets/LianeMarilin/ECG-EdgeBench/resolve/4a8de96917a9ac51ec5233bfa15968e85050c22e/scripts/validate_delivery.py
- Command line
-
hf download hf://datasets/LianeMarilin/ECG-EdgeBench@4a8de96917a9ac51ec5233bfa15968e85050c22e/scripts/validate_delivery.py
-
curl -L -o validate_delivery.py https://huggingface.co/datasets/LianeMarilin/ECG-EdgeBench/resolve/4a8de96917a9ac51ec5233bfa15968e85050c22e/scripts/validate_delivery.py
4.47 kB
| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| import argparse | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import re | |
| import subprocess | |
| import sys | |
| ROOT = Path(__file__).resolve().parents[1] | |
| DS1 = {101,106,108,109,112,114,115,116,118,119,122,124,201,203,205,207,208,209,215,220,223,230} | |
| DS2 = {100,103,105,111,113,117,121,123,200,202,210,212,213,214,219,221,222,228,231,232,233,234} | |
| def check(condition: bool, message: str, failures: list[str]) -> None: | |
| if not condition: | |
| failures.append(message) | |
| def main() -> int: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--upstream", type=Path, required=True) | |
| args = parser.parse_args() | |
| failures: list[str] = [] | |
| task_path = ROOT / "sforge" / "mitbih_interpatient_arrhythmia.json" | |
| check(task_path.is_file(), "generated task JSON missing", failures) | |
| task = json.loads(task_path.read_text(encoding="utf-8")) | |
| expected_top = {"task_id","name","base_image","platform","cwd","submit_paths","submit_exclude","internet","game_mode","work","judge"} | |
| check(set(task) == expected_top, "unexpected or missing top-level task fields", failures) | |
| check(task["task_id"] == "mitbih_interpatient_arrhythmia", "task_id mismatch", failures) | |
| check(task["internet"] is False, "runtime internet must be disabled", failures) | |
| check(task["judge"]["parser"] == "structured_json", "parser mismatch", failures) | |
| check(task["judge"]["selection"] == "valid_then_score", "selection mismatch", failures) | |
| check(not DS1 & DS2 and len(DS1 | DS2) == 44, "DS1/DS2 record freeze invalid", failures) | |
| check({102,104,107,217}.isdisjoint(DS1 | DS2), "paced record leaked into split", failures) | |
| sys.path.insert(0, str(args.upstream)) | |
| try: | |
| from sforge.harness.benchmark import load_benchmark | |
| from sforge.harness.task_spec import make_task_spec | |
| from sforge.harness.log_parsers.structured_json import parse_structured_json | |
| benchmark = load_benchmark(ROOT / "sforge") | |
| spec = make_task_spec(task_path, benchmark) | |
| check(spec.task_id == task["task_id"], "upstream task loader mismatch", failures) | |
| probe = '>>>>> Start Structured Result\n{"valid":true,"score":12.5}\n>>>>> End Structured Result\n' | |
| check(parse_structured_json(probe).get("score") == 12.5, "structured parser round-trip failed", failures) | |
| except Exception as exc: | |
| failures.append(f"upstream SForge compatibility failed: {type(exc).__name__}: {exc}") | |
| result = subprocess.run( | |
| [sys.executable, str(ROOT / "task_repo" / "solution.py"), "--self-test"], | |
| capture_output=True, text=True, | |
| ) | |
| check(result.returncode == 0, f"baseline self-test failed: {result.stderr}", failures) | |
| forbidden = [] | |
| for path in ROOT.rglob("*"): | |
| if path.is_file() and any(part in {".git", "__pycache__"} for part in path.parts): | |
| continue | |
| if path.name in {".DS_Store"} or path.suffix in {".part", ".tmp", ".pyc"}: | |
| forbidden.append(str(path.relative_to(ROOT))) | |
| check(not forbidden, f"forbidden files: {forbidden}", failures) | |
| excluded_scan = {Path(__file__).resolve(), (ROOT / "validation_report.json").resolve()} | |
| text = "\n".join( | |
| p.read_text(encoding="utf-8", errors="ignore") | |
| for p in ROOT.rglob("*") | |
| if p.is_file() and p.stat().st_size < 2_000_000 and p.resolve() not in excluded_scan | |
| ) | |
| secret_like = re.search(r"sk-[A-Za-z0-9_-]{20,}|-----BEGIN (?:RSA |EC )?PRIVATE KEY-----", text) | |
| check(secret_like is None, "possible secret material found", failures) | |
| host_path = re.escape(str(ROOT.parent.parent.parent)) | |
| check(re.search(host_path, text) is None, "absolute host path leaked", failures) | |
| report = { | |
| "status": "PASS" if not failures else "FAIL", | |
| "checks": { | |
| "sforge_schema": "PASS" if not any("SForge" in f or "task" in f for f in failures) else "FAIL", | |
| "patient_disjoint_split": "PASS" if not any("split" in f or "paced" in f for f in failures) else "FAIL", | |
| "baseline_self_test": "PASS" if result.returncode == 0 else "FAIL", | |
| "package_hygiene": "PASS" if not forbidden else "FAIL" | |
| }, | |
| "failures": failures | |
| } | |
| (ROOT / "validation_report.json").write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps(report, indent=2)) | |
| return 1 if failures else 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |