@@ -1849,6 +1849,89 @@ def test_list_filters_by_ecosystem
18491849
18501850 assert_includes output , "No dependencies found"
18511851 end
1852+
1853+ def test_list_filters_by_manifest
1854+ sha = SecureRandom . hex ( 20 )
1855+ commit = Git ::Pkgs ::Models ::Commit . create (
1856+ sha : sha , message : "Add deps" ,
1857+ author_name : "alice" , author_email : "alice@example.com" ,
1858+ committed_at : Time . now , has_dependency_changes : true
1859+ )
1860+
1861+ gemfile = Git ::Pkgs ::Models ::Manifest . find_or_create ( path : "Gemfile" , ecosystem : "rubygems" , kind : "manifest" )
1862+ package_json = Git ::Pkgs ::Models ::Manifest . find_or_create ( path : "package.json" , ecosystem : "npm" , kind : "manifest" )
1863+
1864+ branch = Git ::Pkgs ::Models ::Branch . create ( name : "main" , last_analyzed_sha : sha )
1865+ Git ::Pkgs ::Models ::BranchCommit . create ( branch : branch , commit : commit , position : 1 )
1866+
1867+ Git ::Pkgs ::Models ::DependencySnapshot . create (
1868+ commit : commit , manifest : gemfile , name : "rails" ,
1869+ ecosystem : "rubygems" , requirement : "~> 7.0" , dependency_type : "runtime"
1870+ )
1871+ Git ::Pkgs ::Models ::DependencySnapshot . create (
1872+ commit : commit , manifest : package_json , name : "lodash" ,
1873+ ecosystem : "npm" , requirement : "^4.0" , dependency_type : "runtime"
1874+ )
1875+
1876+ output = capture_stdout do
1877+ Dir . chdir ( @test_dir ) do
1878+ Git ::Pkgs ::Commands ::List . new ( [ "--commit=#{ sha } " , "--manifest=Gemfile" ] ) . run
1879+ end
1880+ end
1881+
1882+ assert_includes output , "rails"
1883+ refute_includes output , "lodash"
1884+ end
1885+
1886+ def test_list_manifest_filter_no_match
1887+ commit = create_commit_with_changes ( "alice" , [
1888+ { name : "rails" , change_type : "added" }
1889+ ] )
1890+ create_branch_with_snapshot ( "main" , commit , [ { name : "rails" } ] )
1891+
1892+ output = capture_stdout do
1893+ Dir . chdir ( @test_dir ) do
1894+ Git ::Pkgs ::Commands ::List . new ( [ "--commit=#{ commit . sha } " , "--manifest=package.json" ] ) . run
1895+ end
1896+ end
1897+
1898+ assert_includes output , "No dependencies found"
1899+ end
1900+
1901+ def test_list_manifest_filter_json_format
1902+ sha = SecureRandom . hex ( 20 )
1903+ commit = Git ::Pkgs ::Models ::Commit . create (
1904+ sha : sha , message : "Add deps" ,
1905+ author_name : "alice" , author_email : "alice@example.com" ,
1906+ committed_at : Time . now , has_dependency_changes : true
1907+ )
1908+
1909+ gemfile = Git ::Pkgs ::Models ::Manifest . find_or_create ( path : "Gemfile" , ecosystem : "rubygems" , kind : "manifest" )
1910+ package_json = Git ::Pkgs ::Models ::Manifest . find_or_create ( path : "package.json" , ecosystem : "npm" , kind : "manifest" )
1911+
1912+ branch = Git ::Pkgs ::Models ::Branch . create ( name : "main" , last_analyzed_sha : sha )
1913+ Git ::Pkgs ::Models ::BranchCommit . create ( branch : branch , commit : commit , position : 1 )
1914+
1915+ Git ::Pkgs ::Models ::DependencySnapshot . create (
1916+ commit : commit , manifest : gemfile , name : "rails" ,
1917+ ecosystem : "rubygems" , requirement : "~> 7.0" , dependency_type : "runtime"
1918+ )
1919+ Git ::Pkgs ::Models ::DependencySnapshot . create (
1920+ commit : commit , manifest : package_json , name : "lodash" ,
1921+ ecosystem : "npm" , requirement : "^4.0" , dependency_type : "runtime"
1922+ )
1923+
1924+ output = capture_stdout do
1925+ Dir . chdir ( @test_dir ) do
1926+ Git ::Pkgs ::Commands ::List . new ( [ "--commit=#{ sha } " , "--manifest=Gemfile" , "--format=json" ] ) . run
1927+ end
1928+ end
1929+
1930+ data = JSON . parse ( output )
1931+ assert_equal 1 , data . length
1932+ assert_equal "rails" , data . first [ "name" ]
1933+ assert_equal "Gemfile" , data . first [ "manifest_path" ]
1934+ end
18521935end
18531936
18541937class Git ::Pkgs ::TestStaleCommand < Git ::Pkgs ::CommandTestBase
0 commit comments