diff --git a/modules/mesh-build-go/cmd/mesh-build-go/compose.go b/modules/mesh-build-go/cmd/mesh-build-go/compose.go index 524ada97d..1d55fbf9d 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/compose.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/compose.go @@ -50,7 +50,11 @@ func (m *Module) compose(ctx context.Context, fetch buildstep.StepFunc, a delive if err != nil { return nil, err } - key := delivery.ComposerKey(repository, commit, job.Dir, job.Package, delivery.ToolchainUsed{Version: installed, Recipe: m.Recipe.Version()}) + versions, err := sdkstep.PackagesArg(job.Fetch["packages"]) + if err != nil { + return nil, buildstep.Refuse("the compose ask %s: %v", a.ID, err) + } + key := delivery.ComposerKey(repository, commit, job.Dir, job.Package, delivery.ToolchainUsed{Version: installed, Recipe: m.Recipe.Version()}, versions) exe, built, err := m.composerOf(ctx, fetch, job, key) if err != nil { return nil, err diff --git a/modules/mesh-build-go/cmd/mesh-build-go/compose_test.go b/modules/mesh-build-go/cmd/mesh-build-go/compose_test.go index 17dda5cd8..61cdf6f30 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/compose_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/compose_test.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "errors" "os" "path/filepath" "slices" @@ -64,7 +65,7 @@ func TestAKeptComposerIsRunWithTheManifestsFilled(t *testing.T) { read, digests := indexerHolds(t, `{"module":"demo","version":"1"}`) m.ReadManifest = read a := composeAskOf(t, digests[0]) - key := delivery.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, delivery.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()}) + key := delivery.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, delivery.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()}, nil) exe := m.composerPath(key) if err := os.MkdirAll(filepath.Dir(exe), 0o700); err != nil { t.Fatal(err) @@ -95,13 +96,40 @@ func TestAKeptComposerIsRunWithTheManifestsFilled(t *testing.T) { } } +// 1921: the versions an ask names are an input of the composer it builds, so a composer kept for one set is not run for +// another; an ask naming none keeps the key it always had. +func TestAComposerIsKeptPerAskedVersions(t *testing.T) { + m := composeModule(t) + m.ReadManifest, _ = indexerHolds(t) + a := composeAskOf(t, "feedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeed") + tc := delivery.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()} + plain := delivery.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, tc, nil) + a.Compose.Fetch["packages"] = map[string]any{"git.novox.be/novox/mesh-sdk/go": strings.Repeat("3", 40)} + named := delivery.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, tc, delivery.PackageVersions{"git.novox.be/novox/mesh-sdk/go": strings.Repeat("3", 40)}) + if plain == named { + t.Fatal("the key ignores the versions") + } + // A composer kept under the key without versions is not used for the ask that names some: it is fetched. + os.MkdirAll(filepath.Dir(m.composerPath(plain)), 0o700) + os.WriteFile(m.composerPath(plain), []byte("#!/bin/sh\nexit 0\n"), 0o700) + fetched := false + fetch := func(context.Context, map[string]any) (any, error) { + fetched = true + return nil, errors.New("stop") + } + m.compose(context.Background(), fetch, a) + if !fetched { + t.Error("a composer built for no versions was run for an ask naming some") + } +} + // 1622: a manifest the indexer does not keep fails the ask, naming its digest; a fetched commit with no go.mod where // the ask builds fails it naming the directory, and its workspace is released. func TestAComposeAskFailsLoudly(t *testing.T) { m := composeModule(t) m.ReadManifest, _ = indexerHolds(t) a := composeAskOf(t, "feedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeed") - key := delivery.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, delivery.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()}) + key := delivery.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, delivery.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()}, nil) os.MkdirAll(filepath.Dir(m.composerPath(key)), 0o700) os.WriteFile(m.composerPath(key), []byte("#!/bin/sh\nexit 0\n"), 0o700) if _, err := m.compose(context.Background(), nil, a); err == nil || !strings.Contains(err.Error(), "feedfeed") { @@ -168,7 +196,7 @@ func TestAComposeAskBuildsTheNodeEnginesComposerAtItsRoot(t *testing.T) { t.Fatal(err) } ans := out.(delivery.ComposeAnswer) - key := delivery.ComposerKey("novox/mesh-host", composeCommit, delivery.RootPath, nodeEngineComposer, delivery.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()}) + key := delivery.ComposerKey("novox/mesh-host", composeCommit, delivery.RootPath, nodeEngineComposer, delivery.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()}, nil) var v composer.Verdict if err := json.Unmarshal(ans.Verdict, &v); err != nil { t.Fatal(err)