From 3fd2e58072446fd65cbaccb4b51d79874dc0c559 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 22:20:12 +0100 Subject: [PATCH] H-A-192: the Go build module refuses a requirement with no pin of its own MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Given no pin, the module took the version of another package of the same repository, or the latest, and built against versions never published. A requirement of another repository is now taken at the pin the ask names for its own path, else the build fails naming the path; a same-repository requirement is still built from the fetched tree. Builds: design 47 H H-A-192, H-A-198, G §370 --- .../mesh-build-go/cmd/mesh-build-go/pins.go | 30 +++++------------ .../cmd/mesh-build-go/pins_test.go | 32 +++++++++++-------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/modules/mesh-build-go/cmd/mesh-build-go/pins.go b/modules/mesh-build-go/cmd/mesh-build-go/pins.go index 00c5e900c..6ae7c685d 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/pins.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/pins.go @@ -365,9 +365,9 @@ func (m *Module) takeReplacedZeroPins(ctx context.Context, root, repository, dir } // takeZeroRequirements takes, for each requirement at the zero version, the version it is built against (ADR 0573 §2, -// §4: whatever go.mod names): the commit the ask names for the package; else the head of the package's repository among -// the asked versions (the check's or try's members: another package of the same repository names it); else the latest -// published version, the trunk's head. It never looks for the commit 000000000000 among the pull request heads. One +// §4: whatever go.mod names): a module of the checked repository from the fetched tree (H-A-198); any other at the pin +// the ask names for that package path, and with no pin it refuses the build, never taking another path's version or +// the latest (design 47 H, H-A-192). It never looks for the commit 000000000000 among the pull request heads. One // taken before (dir's modfile requires or replaces it) is left as it is. func (m *Module) takeZeroRequirements(ctx context.Context, root, repository, dir, d string, reqs []zeroRequirement, asked sdkstep.PackageVersions, pins *sync.Mutex) ([]TakenVersion, error) { resolved := map[string]string{} @@ -409,13 +409,13 @@ func (m *Module) takeZeroRequirements(ctx context.Context, root, repository, dir taken = append(taken, tv) continue } - tv := TakenVersion{Dir: d, Package: p.module, Asked: askedFor(asked, p), Named: named} - why := "the ask names it" + // The ask's pin for this path alone: a build module given no pin refuses the build, loud, and never takes another + // path's version nor the latest (design 47 H, H-A-192). + tv := TakenVersion{Dir: d, Package: p.module, Asked: asked[p.module], Named: named} if tv.Asked == "" { - tv.Asked, why = "latest", "the ask names no commit of its repository, so its latest published version" - } else if _, ok := asked[p.module]; !ok { - why = "the head of its repository among the asked versions" + return taken, fmt.Errorf("no pin for %s: the builder pins or waits (H-A-192)", p.module) } + why := "the ask names it" if err := m.takeVersion(ctx, root, dir, &tv, pins); err != nil { return taken, fmt.Errorf("the requirement of %s at the zero version: %w", p.module, err) } @@ -431,20 +431,6 @@ func (m *Module) takeZeroRequirements(ctx context.Context, root, repository, dir // namedBySaid says that a module dir replaces by the directory by names a package, and dir's go.mod does not. func namedBySaid(by string) string { return "named by " + by + ", not by this go.mod" } -// askedFor is the commit the ask names for the package p: its own, else that of the first package of the same repository -// in order (the members' heads are by repository), else none. -func askedFor(asked sdkstep.PackageVersions, p pin) string { - if c := asked[p.module]; c != "" { - return c - } - for _, pkg := range slices.Sorted(maps.Keys(asked)) { - if pkg == forgePrefix+p.repo || strings.HasPrefix(pkg, forgePrefix+p.repo+"/") { - return asked[pkg] - } - } - return "" -} - // useOwnModules replaces, in dir's temporary modfile, every module of the fetched tree whose path lies in the repository // repo by its directory in the tree (once), and answers the paths of those modules. A replace of a module dir does not // require is harmless to Go; one module of a repository requires another of it at the zero version. diff --git a/modules/mesh-build-go/cmd/mesh-build-go/pins_test.go b/modules/mesh-build-go/cmd/mesh-build-go/pins_test.go index 920da2bc4..a55468fc6 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/pins_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/pins_test.go @@ -301,10 +301,10 @@ func TestARelativeReplaceStillResolvesInTheTemporaryModfile(t *testing.T) { } // A go.mod requirement at the zero version v0.0.0-00010101000000-000000000000 names no commit (ADR 0573 §2, §4: whatever -// go.mod names): it is taken from the commit the ask names for the package, else from the head of its repository among -// the asked versions, else from the trunk's latest published version, and never looked for as the commit 000000000000 -// among the pull request heads. -func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) { +// go.mod names): it is taken from the pin the ask names for that package path alone, and never looked for as the commit +// 000000000000 among the pull request heads. With no pin of its own the build is refused, loud, naming the path: never +// built at another package's pin of the same repository nor at the latest (design 47 H, H-A-192). +func TestARequirementAtTheZeroVersionIsTakenFromItsPinOrRefused(t *testing.T) { t.Parallel() const sdk = "git.novox.be/novox/mesh-sdk/go" zeroMod := "module fixture/member\n\ngo 1.26\n\nrequire (\n\t" + sdk + " v0.0.0-00010101000000-" + zeroShort + "\n)\n" @@ -314,6 +314,7 @@ func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) { packages map[string]any download string // what go mod download -json answers want string // the version asked of go + refused bool // the step fails, naming the path: the ask carries no pin for it (H-A-192) head bool // the asked commit is on no trunk: only a pull request head carries it // replaced: the directory's go.mod names no mesh package; a module it replaces by a directory of the tree requires // it at the zero version, so go mod download passes and only a shut-off package load would look it up (1966/AC178-1) @@ -321,18 +322,14 @@ func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) { }{ {name: "the ask names the package", packages: map[string]any{sdk: trunk}, want: sdk + "@" + trunk, download: `{"Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip="}`}, - {name: "the ask names another package of its repository", packages: map[string]any{"git.novox.be/novox/mesh-sdk/other": trunk}, want: sdk + "@" + trunk, - download: `{"Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip="}`}, - {name: "the ask names the root of its repository, which no package of is published", packages: map[string]any{"git.novox.be/novox/mesh-sdk": trunk}, want: sdk + "@" + trunk, - download: `{"Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip="}`}, + {name: "the ask pins only another package of its repository", packages: map[string]any{"git.novox.be/novox/mesh-sdk/other": trunk}, refused: true}, + {name: "the ask pins only the root of its repository", packages: map[string]any{"git.novox.be/novox/mesh-sdk": trunk}, refused: true}, {name: "the ask names the head of a pull request", packages: map[string]any{sdk: commitSHA}, want: sdk + "@" + commitSHA, head: true}, - {name: "the ask names nothing of its repository", packages: map[string]any{"git.novox.be/novox/mesh-tools/go": trunk}, want: sdk + "@latest", - download: `{"Version":"v0.1.20-0.20261104000000-bbbbbbbbbbbb","Sum":"h1:zip="}`}, - {name: "no ask", want: sdk + "@latest", download: `{"Version":"v0.1.20-0.20261104000000-bbbbbbbbbbbb","Sum":"h1:zip="}`}, + {name: "the ask names nothing of its repository", packages: map[string]any{"git.novox.be/novox/mesh-tools/go": trunk}, refused: true}, + {name: "no ask", refused: true}, {name: "named only by a module the directory replaces, the ask names it", packages: map[string]any{sdk: trunk}, want: sdk + "@" + trunk, replaced: true, download: `{"Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip="}`}, - {name: "named only by a module the directory replaces, no ask", want: sdk + "@latest", replaced: true, - download: `{"Version":"v0.1.20-0.20261104000000-bbbbbbbbbbbb","Sum":"h1:zip="}`}, + {name: "named only by a module the directory replaces, no ask", replaced: true, refused: true}, } { t.Run(c.name, func(t *testing.T) { gomod := zeroMod @@ -375,6 +372,15 @@ func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) { t.Fatal(err) } st := states.waitEnd(t) + if c.refused { + if st.State == sdkstep.StepPassed || !strings.Contains(st.Reason, "no pin for "+sdk) { + t.Fatalf("the step ended %s (%s), want it failed naming no pin for %s", st.State, st.Reason, sdk) + } + if h.ran(" mod download -json " + sdk + "@") { + t.Errorf("go was asked for a version of %s with no pin:\n%s", sdk, strings.Join(h.f.lines(), "\n")) + } + return + } if st.State != sdkstep.StepPassed { t.Fatalf("the step ended %s: %s", st.State, st.Reason) }