fix(python): sort uv.lock extras by name so the SBOM output is stable (#5468)

Signed-off-by: Wleeaf <179125857+wleeaf@users.noreply.github.com>
Co-authored-by: Wleeaf <179125857+wleeaf@users.noreply.github.com>
This commit is contained in:
Wleeaf
2026-11-13 20:41:01 +00:00
committed by GitHub
co-authored by Wleeaf
parent 26cd875616
commit a90bb39f87
2 changed files with 25 additions and 0 deletions
@@ -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
}
@@ -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)
}
}