@@ -754,6 +754,22 @@ def test_addable_lines_by_path_indexes_each_file_patch
754754 assert_empty map . fetch ( "infra/no_patch.bin" )
755755 end
756756
757+ def test_pr_files_metadata_paginates_all_pages
758+ calls = [ ]
759+ pages = [
760+ [ { "filename" => "infra/main.tf" } ] ,
761+ [ { "filename" => "infra/extra.tf" } ]
762+ ]
763+
764+ EvalOpsPrLensReview . stub ( :gh_api , -> ( *args , **_kwargs ) { calls << args ; JSON . generate ( pages ) } ) do
765+ files = EvalOpsPrLensReview . pr_files_metadata ( repo : "evalops/deploy" , pr : 1 )
766+
767+ assert_equal [ "infra/main.tf" , "infra/extra.tf" ] , files . map { |file | file . fetch ( "filename" ) }
768+ assert_includes calls . fetch ( 0 ) , "--paginate"
769+ assert_includes calls . fetch ( 0 ) , "--slurp"
770+ end
771+ end
772+
757773 def test_finding_inline_anchorable_only_when_line_in_diff
758774 addable = { "infra/main.tf" => [ 22 , 23 ] . to_set }
759775 in_diff = finding ( "Anchorable" , 0.9 , 1 , "infra/main.tf" , 22 )
@@ -896,11 +912,21 @@ def test_meta_review_green_status_states_coverage_when_only_low_confidence
896912 end
897913 end
898914
899- def test_publish_review_posts_summary_comment_and_inline_comments_idempotently
915+ def test_publish_review_posts_inline_comments_before_summary_and_clears_prior_on_success
900916 api_calls = [ ]
901917 fake_api = lambda do |*args , **kwargs |
902918 api_calls << { args : args , input : kwargs [ :input ] }
903- ""
919+ if args . include? ( "repos/evalops/deploy/issues/10/comments" ) && !args . include? ( "--method" )
920+ "111\n "
921+ elsif args . include? ( "repos/evalops/deploy/pulls/10/comments" ) && !args . include? ( "--method" )
922+ "222\n 333\n "
923+ elsif args . include? ( "repos/evalops/deploy/pulls/10/comments" )
924+ JSON . generate ( "id" => 444 )
925+ elsif args . include? ( "repos/evalops/deploy/issues/10/comments" )
926+ JSON . generate ( "id" => 555 )
927+ else
928+ ""
929+ end
904930 end
905931
906932 inline = [
@@ -910,38 +936,93 @@ def test_publish_review_posts_summary_comment_and_inline_comments_idempotently
910936 )
911937 ]
912938
913- EvalOpsPrLensReview . stub ( :clear_prior_publication , -> ( **_kwargs ) { api_calls << { clear : true } } ) do
914- EvalOpsPrLensReview . stub ( :gh_api , fake_api ) do
915- EvalOpsPrLensReview . publish_review (
916- repo : "evalops/deploy" ,
917- pr : 10 ,
918- head_sha : "abc123" ,
919- inline_findings : inline ,
920- summary_findings : [ ] ,
921- comment_min_confidence : 0.55 ,
922- target_url : "https://github.com/evalops/.github/actions/runs/1"
923- )
924- end
939+ EvalOpsPrLensReview . stub ( :gh_api , fake_api ) do
940+ EvalOpsPrLensReview . publish_review (
941+ repo : "evalops/deploy" ,
942+ pr : 10 ,
943+ head_sha : "abc123" ,
944+ inline_findings : inline ,
945+ summary_findings : [ ] ,
946+ comment_min_confidence : 0.55 ,
947+ target_url : "https://github.com/evalops/.github/actions/runs/1"
948+ )
925949 end
926950
927- # Prior publication is cleared before posting (idempotency).
928- assert_equal ( { clear : true } , api_calls . fetch ( 0 ) )
929- summary_call = api_calls . find { | call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/issues/10/comments" ) }
951+ summary_call = api_calls . find do | call |
952+ Array ( call [ :args ] ) . include? ( "--method" ) && Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/issues/10/comments" )
953+ end
930954 assert summary_call
931955 summary_payload = JSON . parse ( summary_call . fetch ( :input ) )
932956 assert_includes summary_payload . fetch ( "body" ) , EvalOpsPrLensReview ::MARKER
933957
934- comment_call = api_calls . find { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/pulls/10/comments" ) }
958+ comment_call = api_calls . find do |call |
959+ Array ( call [ :args ] ) . include? ( "--method" ) && Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/pulls/10/comments" )
960+ end
935961 assert comment_call
936962 comment = JSON . parse ( comment_call . fetch ( :input ) )
937963 assert_equal "abc123" , comment . fetch ( "commit_id" )
938964 assert_equal "infra/main.tf" , comment . fetch ( "path" )
939965 assert_equal 22 , comment . fetch ( "line" )
940966 assert_equal "RIGHT" , comment . fetch ( "side" )
941967 assert_includes comment . fetch ( "body" ) , EvalOpsPrLensReview ::MARKER
968+ assert_operator api_calls . index ( comment_call ) , :< , api_calls . index ( summary_call )
969+ assert ( api_calls . any? { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/issues/comments/111" ) } )
970+ assert ( api_calls . any? { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/pulls/comments/222" ) } )
971+ assert ( api_calls . any? { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/pulls/comments/333" ) } )
942972 refute ( api_calls . any? { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/pulls/10/reviews" ) } )
943973 end
944974
975+ def test_publish_review_rolls_back_partial_inline_publication_without_deleting_prior_comments
976+ api_calls = [ ]
977+ inline_posts = 0
978+ inline = 2 . times . map do |index |
979+ finding ( "Inline #{ index } " , 0.9 , 1 , "infra/main.tf" , index + 1 ) . merge (
980+ "lens" => "iam-blast-radius" ,
981+ "check_id" => "evalops-pr-lens/iam-blast-radius"
982+ )
983+ end
984+
985+ fake_api = lambda do |*args , **kwargs |
986+ api_calls << { args : args , input : kwargs [ :input ] }
987+ if args . include? ( "repos/evalops/deploy/issues/10/comments" ) && !args . include? ( "--method" )
988+ "111\n "
989+ elsif args . include? ( "repos/evalops/deploy/pulls/10/comments" ) && !args . include? ( "--method" )
990+ "222\n "
991+ elsif args . include? ( "repos/evalops/deploy/pulls/10/comments" )
992+ inline_posts += 1
993+ raise "inline publish failed" if inline_posts == 2
994+
995+ JSON . generate ( "id" => 444 )
996+ elsif args . include? ( "repos/evalops/deploy/issues/10/comments" )
997+ JSON . generate ( "id" => 555 )
998+ else
999+ ""
1000+ end
1001+ end
1002+
1003+ error = assert_raises ( RuntimeError ) do
1004+ EvalOpsPrLensReview . stub ( :gh_api , fake_api ) do
1005+ EvalOpsPrLensReview . publish_review (
1006+ repo : "evalops/deploy" ,
1007+ pr : 10 ,
1008+ head_sha : "abc123" ,
1009+ inline_findings : inline ,
1010+ summary_findings : [ ] ,
1011+ comment_min_confidence : 0.55 ,
1012+ target_url : "https://github.com/evalops/.github/actions/runs/1"
1013+ )
1014+ end
1015+ end
1016+
1017+ assert_equal "inline publish failed" , error . message
1018+ refute ( api_calls . any? do |call |
1019+ Array ( call [ :args ] ) . include? ( "--method" ) && Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/issues/10/comments" )
1020+ end )
1021+ assert ( api_calls . any? { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/pulls/comments/444" ) } )
1022+ refute ( api_calls . any? { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/issues/comments/111" ) } )
1023+ refute ( api_calls . any? { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/pulls/comments/222" ) } )
1024+ end
1025+
9451026 def test_publish_review_moves_inline_overflow_into_summary_comment
9461027 api_calls = [ ]
9471028 fake_api = lambda do |*args , **kwargs |
@@ -969,14 +1050,18 @@ def test_publish_review_moves_inline_overflow_into_summary_comment
9691050 end
9701051 end
9711052
972- summary_call = api_calls . find { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/issues/10/comments" ) }
1053+ summary_call = api_calls . find do |call |
1054+ Array ( call [ :args ] ) . include? ( "--method" ) && Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/issues/10/comments" )
1055+ end
9731056 assert summary_call
9741057 summary_body = JSON . parse ( summary_call . fetch ( :input ) ) . fetch ( "body" )
9751058 assert_includes summary_body , "#{ EvalOpsPrLensReview ::MAX_FINDINGS_PER_COMMENT } anchored inline below."
9761059 assert_includes summary_body , "Additional diff findings"
9771060 assert_includes summary_body , "`infra/main.tf:13`"
9781061
979- inline_posts = api_calls . count { |call | Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/pulls/10/comments" ) }
1062+ inline_posts = api_calls . count do |call |
1063+ Array ( call [ :args ] ) . include? ( "--method" ) && Array ( call [ :args ] ) . include? ( "repos/evalops/deploy/pulls/10/comments" )
1064+ end
9801065 assert_equal EvalOpsPrLensReview ::MAX_FINDINGS_PER_COMMENT , inline_posts
9811066 end
9821067
0 commit comments