@@ -3737,6 +3737,89 @@ def test_no_description_nothing_to_check(self):
37373737 self .assertEqual (results , [])
37383738
37393739
3740+ class TestDescriptionLineChanges (unittest .TestCase ):
3741+ BODY = "## Summary\n Adds a parser.\n \n Link to Devin run: https://app.devin.ai/sessions/1\n "
3742+
3743+ def _scope (self , * checks ):
3744+ return main .ScopeResult (label = "PR description" , checks = list (checks ))
3745+
3746+ def test_lines_removed_keeps_order_and_counts_copies (self ):
3747+ self .assertEqual (main .lines_removed ("a\n b\n a\n \n c" , "a\n c" ), ["b" , "a" ])
3748+
3749+ def test_forbid_names_the_line_to_delete (self ):
3750+ scope = self ._scope (
3751+ {
3752+ "rule_id" : "CC013" ,
3753+ "suggest" : "Remove the AI lines." ,
3754+ "fix" : "## Summary\n Adds a parser." ,
3755+ }
3756+ )
3757+ main .name_the_line_changes (scope , self .BODY )
3758+ self .assertEqual (
3759+ scope .checks [0 ]["suggest" ],
3760+ 'In the description, remove "Link to Devin run: https://app.devin.ai/sessions/1"' ,
3761+ )
3762+ self .assertEqual (scope .checks [0 ]["fix" ], "" )
3763+
3764+ def test_disclose_names_the_line_to_add_and_the_one_it_replaces (self ):
3765+ body = "Adds a parser.\n \n Co-Authored-By: Claude <noreply@anthropic.com>"
3766+ scope = self ._scope (
3767+ {
3768+ "rule_id" : "CC015" ,
3769+ "suggest" : "x" ,
3770+ "fix" : "Adds a parser.\n \n Assisted-by: Claude" ,
3771+ },
3772+ {"rule_id" : "CC014" , "suggest" : "x" , "fix" : body + "\n Assisted-by: Claude" },
3773+ )
3774+ main .name_the_line_changes (scope , body )
3775+ self .assertEqual (
3776+ [c ["suggest" ] for c in scope .checks ],
3777+ [
3778+ (
3779+ 'In the description, remove "Co-Authored-By: Claude'
3780+ ' <noreply@anthropic.com>", and add "Assisted-by: Claude"'
3781+ ),
3782+ 'In the description, add "Assisted-by: Claude"' ,
3783+ ],
3784+ )
3785+
3786+ def test_a_check_without_a_fix_or_a_change_is_left_alone (self ):
3787+ scope = self ._scope (
3788+ {"rule_id" : "CC013" , "suggest" : "s" , "fix" : "" },
3789+ {"rule_id" : "CC013" , "suggest" : "s" , "fix" : "same" },
3790+ )
3791+ main .name_the_line_changes (scope , "same" )
3792+ self .assertEqual (
3793+ scope .checks ,
3794+ [
3795+ {"rule_id" : "CC013" , "suggest" : "s" , "fix" : "" },
3796+ {"rule_id" : "CC013" , "suggest" : "s" , "fix" : "same" },
3797+ ],
3798+ )
3799+
3800+ def test_run_names_the_lines_for_a_reported_description (self ):
3801+ scope = self ._scope (
3802+ {
3803+ "rule_id" : "CC013" ,
3804+ "status" : "fail" ,
3805+ "suggest" : "s" ,
3806+ "fix" : "## Summary\n Adds a parser." ,
3807+ }
3808+ )
3809+ with (
3810+ patch ("main.PR_TITLE_ENABLED" , False ),
3811+ patch ("main.PR_BODY_AI_ATTRIBUTION_ENABLED" , True ),
3812+ patch .dict (os .environ , {"AI_LABEL" : "false" }),
3813+ patch ("main.MESSAGE_ENABLED" , False ),
3814+ patch ("main.is_pr_event" , return_value = True ),
3815+ patch ("main.get_pr_body" , return_value = self .BODY ),
3816+ patch ("main.check_scope" , return_value = scope ),
3817+ patch ("main.run_other_checks" , return_value = []),
3818+ ):
3819+ _rc , results = main .run_commit_check ()
3820+ self .assertEqual (results [0 ].checks [0 ]["fix" ], "" )
3821+
3822+
37403823class TestAiToolsFound (unittest .TestCase ):
37413824 def setUp (self ):
37423825 main .PR_BODY_AI_TOOLS .clear ()
0 commit comments