scripts/tests/reproduction_cli/test_classification.py
scripts/tests/reproduction_cli/test_classification.pyBrowse 41 files
1,053 tokens
4,144 bytes
Token encoding: o200k_base
Snapshot a9fb1c3
← Back to SKILL.md
1import sys2from pathlib import Path3 4import pytest5 6sys.path.insert(0, str(Path(__file__).resolve().parents[2]))7 8from cli_testlib import _chain, _write_stub_proof9from mechanical_refactor_reproduction_cli import (10 KIND_MECHANICAL,11 KIND_NON_MECHANICAL,12 VERDICT_AMBIGUOUS_KIND,13 VERDICT_HUMAN_REVIEW,14 VERDICT_PASS,15 VERDICT_UNCLASSIFIED,16 verify_chain,17)18 19 20def _single_verdict(repo: Path, tmp_path: Path, message: str, *, with_proof: bool):21 proof = tmp_path / "proof"22 proof.mkdir(exist_ok=True)23 base, shas = _chain(repo, [message])24 if with_proof:25 _write_stub_proof(proof, shas[0])26 result = verify_chain(base=base, branch="chain", proof=proof, repo_root=str(repo))27 return result.verdicts[0]28 29 30def test_mechanical_provable_word_classifies_the_commit_as_mechanical(31 repo: Path, tmp_path: Path32) -> None:33 """A message carrying mechanical_provable is classified mechanical and needs a proof."""34 verdict = _single_verdict(35 repo, tmp_path, "grp(step,mechanical_provable): move foo", with_proof=True36 )37 assert verdict.kind == KIND_MECHANICAL38 assert verdict.verdict == VERDICT_PASS39 40 41def test_non_mechanical_provable_word_is_not_double_counted_as_the_bare_word(42 repo: Path, tmp_path: Path43) -> None:44 """non_mechanical_provable classifies as non-mechanical, not as both words at once."""45 verdict = _single_verdict(46 repo,47 tmp_path,48 "grp(step,non_mechanical_provable): rework foo",49 with_proof=False,50 )51 assert verdict.kind == KIND_NON_MECHANICAL52 assert verdict.verdict == VERDICT_HUMAN_REVIEW53 54 55def test_message_without_either_word_is_unclassified_and_fails_the_chain(56 repo: Path, tmp_path: Path57) -> None:58 """A commit missing both words gets UNCLASSIFIED and the chain does not pass."""59 proof = tmp_path / "proof"60 proof.mkdir()61 base, _ = _chain(repo, ["plain subject with no kind word"])62 result = verify_chain(base=base, branch="chain", proof=proof, repo_root=str(repo))63 assert result.verdicts[0].verdict == VERDICT_UNCLASSIFIED64 assert result.verdicts[0].kind is None65 assert not result.passed66 67 68def test_message_with_both_words_is_ambiguous(repo: Path, tmp_path: Path) -> None:69 """A commit declaring both kinds gets AMBIGUOUS_KIND and fails the chain."""70 verdict = _single_verdict(71 repo,72 tmp_path,73 "subject mechanical_provable\n\nbody also says non_mechanical_provable",74 with_proof=True,75 )76 assert verdict.verdict == VERDICT_AMBIGUOUS_KIND77 assert verdict.kind is None78 79 80def test_kind_word_must_stand_alone_not_as_a_substring(81 repo: Path, tmp_path: Path82) -> None:83 """xmechanical_provable / mechanical_provable_x do not count as the standalone word."""84 verdict = _single_verdict(85 repo,86 tmp_path,87 "xmechanical_provable and mechanical_provable_x only",88 with_proof=False,89 )90 assert verdict.verdict == VERDICT_UNCLASSIFIED91 92 93def test_kind_word_delimited_by_punctuation_counts(repo: Path, tmp_path: Path) -> None:94 """The word inside punctuation, e.g. (step,mechanical_provable), is a valid match."""95 verdict = _single_verdict(96 repo, tmp_path, "grp(step,mechanical_provable): move", with_proof=True97 )98 assert verdict.kind == KIND_MECHANICAL99 100 101def test_repeating_the_same_kind_word_is_accepted(repo: Path, tmp_path: Path) -> None:102 """Multiple occurrences of one kind word still classify unambiguously."""103 verdict = _single_verdict(104 repo,105 tmp_path,106 "mechanical_provable move\n\nthis commit is mechanical_provable",107 with_proof=True,108 )109 assert verdict.kind == KIND_MECHANICAL110 assert verdict.verdict == VERDICT_PASS111 112 113def test_kind_word_in_the_body_counts_when_subject_is_free_form(114 repo: Path, tmp_path: Path115) -> None:116 """Classification scans the whole message, so a body-only word is enough."""117 verdict = _single_verdict(118 repo,119 tmp_path,120 "Move resolve to util\n\nKind: non_mechanical_provable",121 with_proof=False,122 )123 assert verdict.kind == KIND_NON_MECHANICAL124