"""Fetch the pinned neetandev/m6809 single-step vector corpus (emulator-derived oracle). The corpus is 1,000 MAME-m6809-generated cases per opcode in the SingleStepTests "MOO" binary format. Its expected values come from MAME's m6809 core, so it is a detector, never a judge: see docs/validation.md for the tier and the known deliberate deviation (mixed-width TFR/EXG of CC/DP). The test data is MIT-0 and the generator BSD-3-Clause according to the corpus README; the repository carries no LICENSE file, which docs/validation.md records. """ from __future__ import annotations import hashlib import shutil import subprocess from pathlib import Path REPOSITORY = "https://github.com/neetandev/m6809.git" REVISION = "9dd7b59284ecc2667268149dbad049e91e36cc9e" ROOT = Path(__file__).resolve().parents[1] DESTINATION = ROOT / "tests" / "vectors" / "m6809" # SHA-256 of the corpus index files at REVISION, recorded in docs/validation.md. PINNED_SHA256 = { "v1/manifest.txt": "45e5f52adb82bd142a473b6e4af1ec1591d223de94994b71e2c735d7ee3f8f23", "v1/metadata.json": "9f9c3342219d511e34e55199dfe839edf98189edeeea3c3f3a88d9fd9fc57c0b", } def _sha256(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as source: while chunk := source.read(1024 * 1024): digest.update(chunk) return digest.hexdigest() def main() -> None: """Clone the corpus at the pinned revision and verify its index files.""" if DESTINATION.exists(): raise SystemExit( f"{DESTINATION} already exists; remove it before fetching the pinned corpus" ) if shutil.which("git") is None: raise SystemExit("git is required to fetch the vector corpus") DESTINATION.parent.mkdir(parents=True, exist_ok=True) subprocess.run(["git", "clone", "--quiet", REPOSITORY, str(DESTINATION)], check=True) subprocess.run( ["git", "-C", str(DESTINATION), "checkout", "--quiet", "--detach", REVISION], check=True, ) actual = subprocess.check_output( ["git", "-C", str(DESTINATION), "rev-parse", "HEAD"], text=True ).strip() if actual != REVISION: raise RuntimeError(f"vector revision mismatch: expected {REVISION}, got {actual}") for relative, expected in PINNED_SHA256.items(): digest = _sha256(DESTINATION / relative) if digest != expected: raise RuntimeError(f"{relative}: expected SHA-256 {expected}, got {digest}") files = sorted((DESTINATION / "v1").glob("*.moo.gz")) print(f"Fetched neetandev/m6809 at {actual}: {len(files)} vector files under {DESTINATION}") if __name__ == "__main__": main()