#!/usr/bin/env python3 """Self-tests for require_math_evidence.py. Tests the classification logic (is_math_track, is_evidence) without needing a live git repo. Exits 0 on success, 1 on failure. """ from __future__ import annotations import importlib.util import sys from pathlib import Path SCRIPT_DIR = Path(__file__).resolve().parent def _load_module(): """Import require_math_evidence as a module (it has dashes in the dir name).""" spec = importlib.util.spec_from_file_location( "require_math_evidence", SCRIPT_DIR / "require_math_evidence.py", ) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod def test_math_track_classification() -> bool: """Verify is_math_track correctly identifies math-track paths.""" mod = _load_module() positives = [ "0-Core-Formalism/lean/Semantics/Semantics/E8Sidon.lean", "6-Documentation/docs/distilled/ArithmeticSpec.md", "shared-data/data/stack_solidification/receipt.md", ] negatives = [ "4-Infrastructure/shim/some_script.py", "scripts/math-first/validate_deepseek_receipts.py", "README.md", "flake.nix", ] ok = True for p in positives: if not mod.is_math_track(p): print(f"FAIL: {p} should be math-track but is not") ok = False for p in negatives: if mod.is_math_track(p): print(f"FAIL: {p} should NOT be math-track but is") ok = False if ok: print("PASS: math-track classification") return ok def test_evidence_classification() -> bool: """Verify is_evidence correctly identifies evidence paths.""" mod = _load_module() positives = [ "shared-data/artifacts/deepseek_review/foo.receipt.json", "0-Core-Formalism/lean/Semantics/Semantics/E8Sidon.lean", "claims.yaml", ] negatives = [ "4-Infrastructure/shim/some_script.py", "README.md", ] ok = True for p in positives: if not mod.is_evidence(p): print(f"FAIL: {p} should be evidence but is not") ok = False for p in negatives: if mod.is_evidence(p): print(f"FAIL: {p} should NOT be evidence but is") ok = False if ok: print("PASS: evidence classification") return ok def test_lean_file_is_self_evidence() -> bool: """A Lean file IS its own evidence (under the evidence prefix).""" mod = _load_module() lean = "0-Core-Formalism/lean/Semantics/Semantics/E8Sidon.lean" if not mod.is_math_track(lean): print("FAIL: Lean file not detected as math-track") return False if not mod.is_evidence(lean): print("FAIL: Lean file not detected as evidence") return False print("PASS: Lean file is both math-track and evidence (self-evidencing)") return True def main() -> int: tests = [ test_math_track_classification, test_evidence_classification, test_lean_file_is_self_evidence, ] passed = sum(1 for t in tests if t()) total = len(tests) print(f"\n{passed}/{total} tests passed") return 0 if passed == total else 1 if __name__ == "__main__": raise SystemExit(main())