@@ -1004,6 +1004,33 @@ def test_pr_title_check_runs_when_enabled(self):
10041004 "PR title" , ["--message" ], input_text = "feat: a feature"
10051005 )
10061006
1007+ def test_pr_title_is_not_held_to_commit_only_rules (self ):
1008+ # require_body and require_signed_off_by judge a commit; a title has
1009+ # no body or trailers, so it could never pass them.
1010+ title = main .ScopeResult (
1011+ label = "PR title" ,
1012+ checks = [
1013+ make_check ("message" , "pass" , "CC001" , value = "feat: add login" ),
1014+ make_check ("require_body" , "fail" , "CC011" , value = "feat: add login" ),
1015+ make_check ("require_signed_off_by" , "fail" , "CC012" ),
1016+ make_check ("ai_author" , "fail" , "CC017" , value = "Claude <x@y.z>" ),
1017+ ],
1018+ )
1019+ with (
1020+ patch ("main.PR_TITLE_ENABLED" , True ),
1021+ patch ("main.MESSAGE_ENABLED" , False ),
1022+ patch ("main.BRANCH_ENABLED" , False ),
1023+ patch ("main.AUTHOR_NAME_ENABLED" , False ),
1024+ patch ("main.AUTHOR_EMAIL_ENABLED" , False ),
1025+ patch ("main.is_pr_event" , return_value = True ),
1026+ patch ("main.get_pr_title" , return_value = "feat: add login" ),
1027+ patch ("main.check_scope" , return_value = title ),
1028+ patch ("main.run_other_checks" , return_value = []),
1029+ ):
1030+ rc , results = main .run_commit_check ()
1031+ self .assertEqual (rc , 0 )
1032+ self .assertEqual ([c ["rule_id" ] for c in results [0 ].checks ], ["CC001" ])
1033+
10071034 def test_pr_title_failure_propagates (self ):
10081035 with (
10091036 patch ("main.PR_TITLE_ENABLED" , True ),
@@ -4222,6 +4249,18 @@ def test_failing_message(self):
42224249 main .render_report ([scope ]),
42234250 )
42244251
4252+ def test_a_title_meets_only_the_rules_a_title_can (self ):
4253+ with open (self .config , "w" , encoding = "utf-8" ) as f :
4254+ f .write ("[commit]\n require_body = true\n require_signed_off_by = true\n " )
4255+ rc , data = self ._run ("feat: add login page" )
4256+ failed = {c ["rule_id" ] for c in data ["checks" ] if c ["status" ] == "fail" }
4257+ self .assertEqual (rc , 1 )
4258+ self .assertEqual (failed , {"CC011" , "CC012" })
4259+ scope = main .drop_commit_only_rules (
4260+ main .ScopeResult (label = "PR title" , checks = data ["checks" ])
4261+ )
4262+ self .assertEqual (scope .status , "pass" )
4263+
42254264
42264265class TestStderrIsNotPartOfTheJson (unittest .TestCase ):
42274266 """stdout is the JSON; stderr is what the CLI has to say to a person.
0 commit comments