scripts/tests/reproduction_cli/test_proof_discovery.py
scripts/tests/reproduction_cli/test_proof_discovery.pyBrowse 41 files
938 tokens
3,337 bytes
Token encoding: o200k_base
Snapshot a9fb1c3
← Back to SKILL.md
1import sys2from pathlib import Path3 4sys.path.insert(0, str(Path(__file__).resolve().parents[2]))5 6from cli_testlib import _chain, _write_stub_proof7from mechanical_refactor_reproduction_cli import (8 VERDICT_AMBIGUOUS_PROOF,9 VERDICT_MISSING_PROOF,10 VERDICT_PASS,11 verify_chain,12)13 14_MSG = "mechanical_provable: move foo"15 16 17def _run_single(repo: Path, proof: Path):18 base, shas = _chain(repo, [_MSG])19 return shas[0], verify_chain(20 base=base, branch="chain", proof=proof, repo_root=str(repo)21 )22 23 24def test_proof_is_found_under_repro_scripts_by_sha_prefix(25 repo: Path, tmp_path: Path26) -> None:27 """The generator layout repro_scripts/<sha9>.py resolves to the commit's proof."""28 proof = tmp_path / "proof"29 base, shas = _chain(repo, [_MSG])30 _write_stub_proof(proof, shas[0], stem_len=9)31 result = verify_chain(base=base, branch="chain", proof=proof, repo_root=str(repo))32 assert result.verdicts[0].verdict == VERDICT_PASS33 34 35def test_proof_is_found_flat_in_the_proof_folder_by_full_sha(36 repo: Path, tmp_path: Path37) -> None:38 """A flat <proof>/<full-sha>.py layout is also accepted."""39 proof = tmp_path / "proof"40 base, shas = _chain(repo, [_MSG])41 _write_stub_proof(proof, shas[0], flat=True, stem_len=40)42 result = verify_chain(base=base, branch="chain", proof=proof, repo_root=str(repo))43 assert result.verdicts[0].verdict == VERDICT_PASS44 45 46def test_provable_commit_without_a_proof_script_is_missing_proof(47 repo: Path, tmp_path: Path48) -> None:49 """A mechanical_provable commit with no matching script fails as MISSING_PROOF."""50 proof = tmp_path / "proof"51 proof.mkdir()52 sha, result = _run_single(repo, proof)53 assert result.verdicts[0].verdict == VERDICT_MISSING_PROOF54 assert not result.passed55 56 57def test_unrelated_and_non_hex_scripts_do_not_match(repo: Path, tmp_path: Path) -> None:58 """Scripts named for another sha or with a non-hex stem are not this commit's proof."""59 proof = tmp_path / "proof"60 scripts = proof / "repro_scripts"61 scripts.mkdir(parents=True)62 (scripts / "0123456789abcdef.py").write_text("raise SystemExit(1)\n")63 (scripts / "not_a_sha.py").write_text("raise SystemExit(1)\n")64 sha, result = _run_single(repo, proof)65 assert result.verdicts[0].verdict == VERDICT_MISSING_PROOF66 67 68def test_two_scripts_matching_one_commit_are_ambiguous(69 repo: Path, tmp_path: Path70) -> None:71 """A commit matched by both a nested and a flat script fails as AMBIGUOUS_PROOF."""72 proof = tmp_path / "proof"73 base, shas = _chain(repo, [_MSG])74 _write_stub_proof(proof, shas[0], stem_len=9)75 _write_stub_proof(proof, shas[0], flat=True, stem_len=12)76 result = verify_chain(base=base, branch="chain", proof=proof, repo_root=str(repo))77 assert result.verdicts[0].verdict == VERDICT_AMBIGUOUS_PROOF78 assert not result.passed79 80 81def test_short_hex_stem_below_minimum_length_is_ignored(82 repo: Path, tmp_path: Path83) -> None:84 """A 6-char hex stem is too short to name a commit and is not treated as a proof."""85 proof = tmp_path / "proof"86 base, shas = _chain(repo, [_MSG])87 _write_stub_proof(proof, shas[0], stem_len=6)88 result = verify_chain(base=base, branch="chain", proof=proof, repo_root=str(repo))89 assert result.verdicts[0].verdict == VERDICT_MISSING_PROOF90