@@ -327,6 +327,28 @@ def test_attribution_empty_diff_yields_empty_collections():
327327 assert payload ["deepDependencies" ] == []
328328
329329
330+ def test_attribution_partitions_direct_vs_deep ():
331+ pkg_a = Package (
332+ type = "pypi" , name = "a" , version = "1.0" , id = "pip+a$1.0" ,
333+ score = {}, alerts = [], direct = True ,
334+ )
335+ pkg_b = Package (
336+ type = "pypi" , name = "b" , version = "1.0" , id = "pip+b$1.0" ,
337+ score = {}, alerts = [], direct = False ,
338+ )
339+ pkg_c = Package (
340+ type = "pypi" , name = "c" , version = "1.0" , id = "pip+c$1.0" ,
341+ score = {}, alerts = [], direct = True ,
342+ )
343+ diff = Diff (packages = {"id-a" : pkg_a , "id-b" : pkg_b , "id-c" : pkg_c })
344+ config = CliConfig .from_args (["--api-token" , "test" , "--legal-format" , "fossa" ])
345+ payload = build_fossa_attribution_payload (diff , config )
346+ direct_names = sorted (d ["package" ] for d in payload ["directDependencies" ])
347+ deep_names = sorted (d ["package" ] for d in payload ["deepDependencies" ])
348+ assert direct_names == ["a" , "c" ]
349+ assert deep_names == ["b" ]
350+
351+
330352def test_vulnerability_version_ranges_sourced_from_socket_fields ():
331353 """affectedVersionRanges/patchedVersionRanges come from Socket's singular fields, wrapped."""
332354 from socketsecurity .fossa_compat import _build_vulnerability_entry
0 commit comments