Merge pull request 'Leave the go.mod fixtures under testdata out of the build module's tests and digests (issue 1810)' (#431) from fix/1810-beside-sibling into main

This commit was merged in pull request #431.
This commit is contained in:
2026-10-21 23:44:20 +00:00
3 changed files with 40 additions and 2 deletions
@@ -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
@@ -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)
}
}
@@ -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"