From 6aa4f135c9f6660d2666c531aea405e9a7834852 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 22 Oct 2026 01:22:31 +0200 Subject: [PATCH] Leave the go.mod fixtures under testdata out of the build module's tests and digests, so the checker stops running a fixture as a module (issue 1810) --- .../mesh-build-go/cmd/mesh-build-go/fetch.go | 13 ++++++++- .../cmd/mesh-build-go/gomoddirs_test.go | 27 +++++++++++++++++++ .../mesh-build-go/cmd/mesh-build-go/recipe.go | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 modules/mesh-build-go/cmd/mesh-build-go/gomoddirs_test.go diff --git a/modules/mesh-build-go/cmd/mesh-build-go/fetch.go b/modules/mesh-build-go/cmd/mesh-build-go/fetch.go index 98462762..a6f1ef7c 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/fetch.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/fetch.go @@ -145,7 +145,7 @@ func (m *Module) goModDirs(ctx context.Context, tree string) ([]string, error) { } dirs := []string{} for _, l := range strings.Split(r.Stdout, "\n") { - if l = strings.TrimSpace(l); l != "" { + if l = strings.TrimSpace(l); l != "" && !inTestdata(l) { dirs = append(dirs, filepath.ToSlash(filepath.Dir(l))) } } @@ -153,6 +153,17 @@ func (m *Module) goModDirs(ctx context.Context, tree string) ([]string, error) { return dirs, nil } +// inTestdata says a path lies under a directory named testdata, whose go.mod files are fixtures Go ignores, not modules +// of the tree (issue 1810). +func inTestdata(path string) bool { + for _, seg := range strings.Split(filepath.ToSlash(path), "/") { + if seg == "testdata" { + return true + } + } + return false +} + // goEnv is what a go command of a step is given beyond the base environment: the installed go alone (GOTOOLCHAIN=local, ADR 0477 §1: no toolchain is ever downloaded), // modules resolved by their go.mod and go.sum, the module's own caches, the mesh's own modules fetched directly (by // git, through the account's rewrite of the forge's address to ssh), and nothing that asks a question. For a directory diff --git a/modules/mesh-build-go/cmd/mesh-build-go/gomoddirs_test.go b/modules/mesh-build-go/cmd/mesh-build-go/gomoddirs_test.go new file mode 100644 index 00000000..dfd9bb67 --- /dev/null +++ b/modules/mesh-build-go/cmd/mesh-build-go/gomoddirs_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "context" + "reflect" + "testing" + + "git.novox.be/novox/mesh-sdk/go/forgekey" +) + +// 1810/AC1: the go.mod files under a testdata directory are fixtures Go itself ignores, not modules of the tree, so +// the build modules neither test nor digest them (a repository holding this module held one whose test reads +// MESH_CHECK_BESIDE, which failed every check of it). +func TestGoModDirsLeaveOutTheFixturesUnderTestdata(t *testing.T) { + m := &Module{} + m.Run = func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran { + return forgekey.Ran{Stdout: "checks/deps/go.mod\ngo.mod\nmodules/x/cmd/x/testdata/repos/beside/go.mod\nmodules/x/go.mod\ntestdata/go.mod\n"} + } + got, err := m.goModDirs(context.Background(), t.TempDir()) + if err != nil { + t.Fatal(err) + } + want := []string{".", "checks/deps", "modules/x"} + if !reflect.DeepEqual(got, want) { + t.Fatalf("go.mod directories = %v, want %v", got, want) + } +} diff --git a/modules/mesh-build-go/cmd/mesh-build-go/recipe.go b/modules/mesh-build-go/cmd/mesh-build-go/recipe.go index 7a5c76f6..dc22a616 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/recipe.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/recipe.go @@ -20,7 +20,7 @@ const PostgresMajor = 18 // RecipeSteps is the recipe's own version: changed whenever the steps of fetch, test or build change in a way // that can change what they produce (ADR 0405 §7). It is one of the three values the recipe version hashes. -const RecipeSteps = "1" +const RecipeSteps = "2" // natsModule is the library the integration level's bus is started from (ADR 0470 §2). const natsModule = "github.com/nats-io/nats-server/v2"