@@ -745,6 +745,94 @@ def capture_stdout
745745 end
746746end
747747
748+ class Git ::Pkgs ::TestInfoCommand < Minitest ::Test
749+ include TestHelpers
750+
751+ def setup
752+ create_test_repo
753+ add_file ( "Gemfile" , "source 'https://rubygems.org'\n gem 'rails'" )
754+ commit ( "Add rails" )
755+ @git_dir = File . join ( @test_dir , ".git" )
756+ Git ::Pkgs ::Database . connect ( @git_dir )
757+ Git ::Pkgs ::Database . create_schema
758+ end
759+
760+ def teardown
761+ cleanup_test_repo
762+ end
763+
764+ def test_info_with_zero_snapshots_does_not_crash
765+ # Create commits with dependency changes but no snapshots
766+ sha = SecureRandom . hex ( 20 )
767+ Git ::Pkgs ::Models ::Commit . create! (
768+ sha : sha ,
769+ message : "Test commit" ,
770+ author_name : "Test User" ,
771+ author_email :
"[email protected] " , 772+ committed_at : Time . now ,
773+ has_dependency_changes : true
774+ )
775+
776+ # Should not raise FloatDomainError
777+ output = capture_stdout do
778+ Dir . chdir ( @test_dir ) do
779+ Git ::Pkgs ::Commands ::Info . new ( [ ] ) . run
780+ end
781+ end
782+
783+ assert_includes output , "Commits with dependency changes: 1"
784+ assert_includes output , "Commits with snapshots: 0"
785+ assert_includes output , "Coverage: 0.0%"
786+ refute_includes output , "1 snapshot per"
787+ end
788+
789+ def test_info_with_snapshots_shows_ratio
790+ sha = SecureRandom . hex ( 20 )
791+ commit = Git ::Pkgs ::Models ::Commit . create! (
792+ sha : sha ,
793+ message : "Test commit" ,
794+ author_name : "Test User" ,
795+ author_email :
"[email protected] " , 796+ committed_at : Time . now ,
797+ has_dependency_changes : true
798+ )
799+
800+ manifest = Git ::Pkgs ::Models ::Manifest . create! (
801+ path : "Gemfile" ,
802+ ecosystem : "rubygems" ,
803+ kind : "manifest"
804+ )
805+
806+ Git ::Pkgs ::Models ::DependencySnapshot . create! (
807+ commit : commit ,
808+ manifest : manifest ,
809+ name : "rails" ,
810+ ecosystem : "rubygems" ,
811+ requirement : ">= 0" ,
812+ dependency_type : "runtime"
813+ )
814+
815+ output = capture_stdout do
816+ Dir . chdir ( @test_dir ) do
817+ Git ::Pkgs ::Commands ::Info . new ( [ ] ) . run
818+ end
819+ end
820+
821+ assert_includes output , "Commits with dependency changes: 1"
822+ assert_includes output , "Commits with snapshots: 1"
823+ assert_includes output , "Coverage: 100.0%"
824+ end
825+
826+ def capture_stdout
827+ original = $stdout
828+ $stdout = StringIO . new
829+ yield
830+ $stdout. string
831+ ensure
832+ $stdout = original
833+ end
834+ end
835+
748836class Git ::Pkgs ::TestSchemaCommand < Minitest ::Test
749837 include TestHelpers
750838
0 commit comments