@@ -791,4 +791,99 @@ def fetch_subdependencies(_dependency)
791791 update_graph_processor . run
792792 end
793793 end
794+
795+ context "when external code execution is rejected" do
796+ let ( :directories ) { [ dir1 , dir2 ] }
797+ let ( :dir1 ) { "/" }
798+ let ( :dir2 ) { "/subproject" }
799+ let ( :repo_contents_path ) { build_tmp_repo ( "bundler/original" , path : "" ) }
800+
801+ let ( :dependency_files ) do
802+ [
803+ Dependabot ::DependencyFile . new (
804+ name : "Gemfile" ,
805+ content : fixture ( "bundler/original/Gemfile" ) ,
806+ directory : dir1
807+ ) ,
808+ Dependabot ::DependencyFile . new (
809+ name : "Gemfile.lock" ,
810+ content : fixture ( "bundler/original/Gemfile.lock" ) ,
811+ directory : dir1
812+ ) ,
813+ Dependabot ::DependencyFile . new (
814+ name : "Gemfile" ,
815+ content : fixture ( "bundler/original/Gemfile" ) ,
816+ directory : dir2
817+ ) ,
818+ Dependabot ::DependencyFile . new (
819+ name : "Gemfile.lock" ,
820+ content : fixture ( "bundler/original/Gemfile.lock" ) ,
821+ directory : dir2
822+ )
823+ ]
824+ end
825+
826+ before do
827+ allow ( Dependabot ::FileParsers ) . to receive ( :for_package_manager )
828+ . and_raise ( Dependabot ::UnexpectedExternalCode )
829+ end
830+
831+ context "when executing standalone" do
832+ before do
833+ allow ( Dependabot ::Environment ) . to receive ( :github_actions? ) . and_return ( false )
834+ end
835+
836+ it "records an error for each directory" do
837+ expect ( service ) . to receive ( :record_update_job_error ) . with (
838+ error_type : "unexpected_external_code" ,
839+ error_details : { message : "Cannot process directory / without external code execution" }
840+ )
841+ expect ( service ) . to receive ( :record_update_job_error ) . with (
842+ error_type : "unexpected_external_code" ,
843+ error_details : { message : "Cannot process directory /subproject without external code execution" }
844+ )
845+
846+ update_graph_processor . run
847+ end
848+
849+ it "does not send any dependency submissions" do
850+ expect ( service ) . not_to receive ( :create_dependency_submission )
851+
852+ update_graph_processor . run
853+ end
854+
855+ it "does not halt processing of remaining directories" do
856+ call_count = 0
857+ allow ( service ) . to receive ( :record_update_job_error ) { call_count += 1 }
858+
859+ update_graph_processor . run
860+
861+ expect ( call_count ) . to eq ( 2 )
862+ end
863+ end
864+
865+ context "when executing in GitHub Actions" do
866+ before do
867+ allow ( Dependabot ::Environment ) . to receive ( :github_actions? ) . and_return ( true )
868+ end
869+
870+ it "sends a FAILED empty submission for each directory" do
871+ expect ( service ) . to receive ( :create_dependency_submission ) . twice do |args |
872+ payload = args [ :dependency_submission ] . payload
873+ expect ( payload [ :metadata ] [ :status ] ) . to eql (
874+ GithubApi ::DependencySubmission ::SnapshotStatus ::FAILED . serialize
875+ )
876+ expect ( payload [ :metadata ] [ :reason ] ) . to eql ( "unexpected_external_code" )
877+ end
878+
879+ update_graph_processor . run
880+ end
881+
882+ it "records an error for each directory" do
883+ expect ( service ) . to receive ( :record_update_job_error ) . twice
884+
885+ update_graph_processor . run
886+ end
887+ end
888+ end
794889end
0 commit comments