From 11c6b9c85c3e260583faa87c547b2c0320a81e0f Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 25 Aug 2026 14:17:04 +0200 Subject: [PATCH] verifier: allow inferred Windows platform versions Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- exporter/verifier/platforms.go | 13 +++- exporter/verifier/platforms_test.go | 101 ++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 exporter/verifier/platforms_test.go diff --git a/exporter/verifier/platforms.go b/exporter/verifier/platforms.go index 619e0f2cb864..105bd458cc9a 100644 --- a/exporter/verifier/platforms.go +++ b/exporter/verifier/platforms.go @@ -96,12 +96,19 @@ func CheckInvalidPlatforms[T comparable](ctx context.Context, res *result.Result mismatch := len(reqMap) != len(ps.Platforms) if !mismatch { + results: for _, p := range ps.Platforms { pp := platforms.Normalize(p.Platform) - if _, ok := reqMap[platforms.FormatAll(pp)]; !ok { - mismatch = true - break + if _, ok := reqMap[platforms.FormatAll(pp)]; ok { + continue + } + for _, reqP := range reqList { + if platforms.OnlyStrict(reqP.Platform).Match(pp) { + continue results + } } + mismatch = true + break } } diff --git a/exporter/verifier/platforms_test.go b/exporter/verifier/platforms_test.go new file mode 100644 index 000000000000..8deb582bfded --- /dev/null +++ b/exporter/verifier/platforms_test.go @@ -0,0 +1,101 @@ +package verifier + +import ( + "encoding/json" + "testing" + + "github.com/containerd/platforms" + "github.com/moby/buildkit/exporter/containerimage/exptypes" + "github.com/moby/buildkit/solver/result" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/stretchr/testify/require" +) + +func TestMultiPlatformWindowsVersionInferred(t *testing.T) { + res := platformResult(t, + []string{"linux/amd64", "windows/amd64"}, + []exptypes.Platform{ + { + ID: "linux/amd64", + Platform: platforms.MustParse("linux/amd64"), + }, + { + ID: "windows/amd64", + Platform: ocispecs.Platform{ + OS: "windows", + Architecture: "amd64", + OSVersion: "10.0.26100.33296", + }, + }, + }, + ) + + warnings, err := CheckInvalidPlatforms(t.Context(), res) + require.NoError(t, err) + require.Empty(t, warnings) +} + +func TestSinglePlatformWindowsVersionInferred(t *testing.T) { + res := platformResult(t, + []string{"windows/amd64"}, + []exptypes.Platform{ + { + ID: "windows/amd64", + Platform: ocispecs.Platform{ + OS: "windows", + Architecture: "amd64", + OSVersion: "10.0.26100.33296", + }, + }, + }, + ) + + warnings, err := CheckInvalidPlatforms(t.Context(), res) + require.NoError(t, err) + require.Empty(t, warnings) +} + +func TestWindowsVersionMismatch(t *testing.T) { + res := platformResult(t, + []string{"linux/amd64", "windows(10.0.20348.1006)/amd64"}, + []exptypes.Platform{ + { + ID: "linux/amd64", + Platform: platforms.MustParse("linux/amd64"), + }, + { + ID: "windows(10.0.20348.1006)/amd64", + Platform: ocispecs.Platform{ + OS: "windows", + Architecture: "amd64", + OSVersion: "10.0.26100.33296", + }, + }, + }, + ) + + warnings, err := CheckInvalidPlatforms(t.Context(), res) + require.NoError(t, err) + require.Len(t, warnings, 1) + require.Contains(t, string(warnings[0].Short), "Requested platforms") +} + +func platformResult(t *testing.T, requested []string, resultPlatforms []exptypes.Platform) *result.Result[string] { + t.Helper() + res := &result.Result[string]{} + + attrs := map[string]string{"platform": requested[0]} + for _, platform := range requested[1:] { + attrs["platform"] += "," + platform + } + require.NoError(t, CaptureFrontendOpts(attrs, res)) + + dt, err := json.Marshal(exptypes.Platforms{Platforms: resultPlatforms}) + require.NoError(t, err) + res.AddMeta(exptypes.ExporterPlatformsKey, dt) + + for _, p := range resultPlatforms { + res.AddRef(p.ID, p.ID) + } + return res +}