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 1a81557c3..7e0072919 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/compose.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/compose.go @@ -57,7 +57,7 @@ func (m *Module) compose(ctx context.Context, fetch buildstep.StepFunc, a sdkste if err != nil { return nil, err } - key := sdkstep.ComposerKey(repository, commit, job.Dir, job.Package, sdkstep.ToolchainUsed{Version: installed, Recipe: m.Recipe.Version()}) + key := sdkstep.ComposerKey(repository, commit, job.Dir, job.Package, sdkstep.ToolchainUsed{Version: installed, Recipe: m.Recipe.Version()}, job.Fetch.Packages) 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 c4a56907d..00fadee25 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 @@ -67,7 +67,7 @@ func TestAKeptComposerIsRunWithTheManifestsFilled(t *testing.T) { read, digests := indexerHolds(t, `{"module":"demo","version":"1"}`) m.ReadManifest = read a := composeAskOf(t, digests[0]) - key := sdkstep.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, sdkstep.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()}) + key := sdkstep.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, sdkstep.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) @@ -98,13 +98,36 @@ 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. +func TestAComposerIsKeptPerAskedVersions(t *testing.T) { + m := composeModule(t) + m.ReadManifest, _ = indexerHolds(t) + a := composeAskOf(t, "feedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeedfeed") + tc := sdkstep.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()} + plain := sdkstep.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, tc, nil) + a.Compose.Fetch.Packages = sdkstep.PackageVersions{"git.novox.be/novox/mesh-sdk/go": strings.Repeat("3", 40)} + // 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 := sdkstep.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, sdkstep.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()}) + key := sdkstep.ComposerKey("novox/mesh-sdk", composeCommit, "go", composer.Package, sdkstep.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") { @@ -193,7 +216,7 @@ func TestAComposeAskBuildsTheNodeEnginesComposerAtItsRoot(t *testing.T) { t.Fatal(err) } ans := out.(sdkstep.ComposeAnswer) - key := sdkstep.ComposerKey("novox/mesh-host", composeCommit, catalogclient.RootPath, nodeEngineComposer, sdkstep.ToolchainUsed{Version: "go1.26.0", Recipe: m.Recipe.Version()}) + key := sdkstep.ComposerKey("novox/mesh-host", composeCommit, catalogclient.RootPath, nodeEngineComposer, sdkstep.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)