Research-Stack/scripts/math-first/test_require_math_evidence.py
Devin AI 0613305be6 feat(infra): add math-first CI scripts and fix wolfram-verification
Create the five missing scripts referenced by .pre-commit-config.yaml
and .github/workflows/math-check.yml:

- validate_deepseek_receipts.py — validates *.receipt.json against schema
- validate_claims_registry.py — validates claims.yaml against schema + path checks
- require_math_evidence.py — enforces evidence alongside math-track edits
- test_validate_deepseek_receipts.py — 4 self-tests for receipt validator
- test_require_math_evidence.py — 3 self-tests for evidence checker

Fix wolfram-verification workflow:
- Change permissions from issues:write to pull-requests:write (fixes 403)
- Add TODO(wolfram-verify) annotations to E8Sidon.lean false positives
  ("normalized" in docstrings matching the normalize pattern)

Co-Authored-By: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
2026-06-15 01:24:48 +00:00

115 lines
3.2 KiB
Python

#!/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())