diff --git a/syft/pkg/cataloger/python/parse_uv_lock.go b/syft/pkg/cataloger/python/parse_uv_lock.go index 26c2492e6..f39987149 100644 --- a/syft/pkg/cataloger/python/parse_uv_lock.go +++ b/syft/pkg/cataloger/python/parse_uv_lock.go @@ -137,6 +137,9 @@ func extractUvExtras(p uvPackage) []pkg.PythonUvLockExtraEntry { Dependencies: extraDeps, }) } + sort.Slice(extras, func(i, j int) bool { + return extras[i].Name < extras[j].Name + }) return extras } diff --git a/syft/pkg/cataloger/python/parse_uv_lock_test.go b/syft/pkg/cataloger/python/parse_uv_lock_test.go index 9aafc2471..206c278fa 100644 --- a/syft/pkg/cataloger/python/parse_uv_lock_test.go +++ b/syft/pkg/cataloger/python/parse_uv_lock_test.go @@ -4,6 +4,8 @@ import ( "context" "testing" + "github.com/stretchr/testify/assert" + "github.com/anchore/syft/syft/artifact" "github.com/anchore/syft/syft/file" "github.com/anchore/syft/syft/pkg" @@ -253,3 +255,23 @@ func TestParseUvLockWithLicenseEnrichment(t *testing.T) { }) } } + +func TestExtractUvExtrasIsSortedByName(t *testing.T) { + p := uvPackage{ + OptionalDependencies: map[string]uvDependencies{ + "socks": {{Name: "socksio"}}, + "brotli": {{Name: "brotli"}, {Name: "brotlicffi"}}, + "http2": {{Name: "h2"}}, + "cli": {{Name: "click"}, {Name: "rich"}}, + }, + } + + // map iteration order is randomized, so check many runs rather than one + for i := 0; i < 50; i++ { + var names []string + for _, e := range extractUvExtras(p) { + names = append(names, e.Name) + } + assert.Equal(t, []string{"brotli", "cli", "http2", "socks"}, names) + } +}