from patcheval_miner.classify import classify, is_production_python, is_test_path from patcheval_miner.models import Candidate, ChangedFile, IssueRef def candidate(*, files: list[str], issues: bool = True, parents: int = 1) -> Candidate: return Candidate( id="owner__repo__pr1", repository="owner/repo", fix_sha="f" * 40, parent_sha="a" * 40 if parents == 1 else None, parent_count=parents, merged_at="2026-01-02T00:00:00Z", pr_number=1, pr_url="https://github.com/owner/repo/pull/1", pr_title="Fix bug", pr_body="Fixes #2", issues=[IssueRef(2, "https://example/2", "Bug", "Reproduction", "closing")] if issues else [], files=[ChangedFile(path, "modified", 2, 1) for path in files], changed_files_count=len(files), ) def test_path_classification() -> None: assert is_test_path("tests/unit/test_parser.py") assert is_test_path("testing/python/approx.py") assert is_test_path("package/parser_test.py") assert not is_test_path("src/package/parser.py") assert is_production_python("src/package/parser.py") assert not is_production_python("docs/example.py") def test_eligible_fix_and_test() -> None: value = classify( candidate(files=["src/package/parser.py", "tests/test_parser.py"]), max_files=30, max_changed_lines=100, ) assert value.structural_status == "eligible" assert value.rejection_reasons == [] def test_feature_without_bug_label_is_rejected() -> None: value = candidate(files=["src/package/parser.py", "tests/test_parser.py"]) value.pr_title = "Add parser support" classified = classify(value, max_files=30, max_changed_lines=100) assert "no-bug-signal" in classified.rejection_reasons def test_bug_label_can_supply_signal() -> None: value = candidate(files=["src/package/parser.py", "tests/test_parser.py"]) value.pr_title = "Handle parser support" value.issues[0] = IssueRef( 2, "https://example/2", "Parser fails", "Reproduction", "closing", ("type: bug",), ) classified = classify(value, max_files=30, max_changed_lines=100) assert classified.structural_status == "eligible" def test_rejections_are_explicit_and_additive() -> None: value = classify( candidate(files=["README.md"], issues=False, parents=2), max_files=30, max_changed_lines=100, ) assert value.structural_status == "rejected" assert value.rejection_reasons == [ "no-linked-issue", "ambiguous-parent", "no-production-python-change", "no-test-change", ]