H-A-192: the Go build module refuses a requirement with no pin of its own

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
This commit is contained in:
2026-11-20 22:20:12 +01:00
parent dc507ec9ff
commit 3fd2e58072
2 changed files with 27 additions and 35 deletions
@@ -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, // 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 // §4: whatever go.mod names): a module of the checked repository from the fetched tree (H-A-198); any other at the pin
// the asked versions (the check's or try's members: another package of the same repository names it); else the latest // the ask names for that package path, and with no pin it refuses the build, never taking another path's version or
// published version, the trunk's head. It never looks for the commit 000000000000 among the pull request heads. One // 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. // 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) { 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{} resolved := map[string]string{}
@@ -409,13 +409,13 @@ func (m *Module) takeZeroRequirements(ctx context.Context, root, repository, dir
taken = append(taken, tv) taken = append(taken, tv)
continue continue
} }
tv := TakenVersion{Dir: d, Package: p.module, Asked: askedFor(asked, p), Named: named} // The ask's pin for this path alone: a build module given no pin refuses the build, loud, and never takes another
why := "the ask names it" // 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 == "" { if tv.Asked == "" {
tv.Asked, why = "latest", "the ask names no commit of its repository, so its latest published version" return taken, fmt.Errorf("no pin for %s: the builder pins or waits (H-A-192)", p.module)
} else if _, ok := asked[p.module]; !ok {
why = "the head of its repository among the asked versions"
} }
why := "the ask names it"
if err := m.takeVersion(ctx, root, dir, &tv, pins); err != nil { 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) 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. // 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" } 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 // 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 // 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. // require is harmless to Go; one module of a repository requires another of it at the zero version.
@@ -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 // 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 // go.mod names): it is taken from the pin the ask names for that package path alone, and never looked for as the commit
// the asked versions, else from the trunk's latest published version, and never looked for as the commit 000000000000 // 000000000000 among the pull request heads. With no pin of its own the build is refused, loud, naming the path: never
// among the pull request heads. // built at another package's pin of the same repository nor at the latest (design 47 H, H-A-192).
func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) { func TestARequirementAtTheZeroVersionIsTakenFromItsPinOrRefused(t *testing.T) {
t.Parallel() t.Parallel()
const sdk = "git.novox.be/novox/mesh-sdk/go" 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" 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 packages map[string]any
download string // what go mod download -json answers download string // what go mod download -json answers
want string // the version asked of go 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 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 // 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) // 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, {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="}`}, 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, {name: "the ask pins only another package of its repository", packages: map[string]any{"git.novox.be/novox/mesh-sdk/other": trunk}, refused: true},
download: `{"Version":"v0.1.15-0.20261101000000-aaaaaaaaaaaa","Sum":"h1:zip="}`}, {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 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 names the head of a pull request", packages: map[string]any{sdk: commitSHA}, want: sdk + "@" + commitSHA, head: 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", {name: "the ask names nothing of its repository", packages: map[string]any{"git.novox.be/novox/mesh-tools/go": trunk}, refused: true},
download: `{"Version":"v0.1.20-0.20261104000000-bbbbbbbbbbbb","Sum":"h1:zip="}`}, {name: "no ask", refused: true},
{name: "no ask", want: sdk + "@latest", download: `{"Version":"v0.1.20-0.20261104000000-bbbbbbbbbbbb","Sum":"h1:zip="}`},
{name: "named only by a module the directory replaces, the ask names it", packages: map[string]any{sdk: trunk}, want: sdk + "@" + trunk, replaced: 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="}`}, 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, {name: "named only by a module the directory replaces, no ask", replaced: true, refused: true},
download: `{"Version":"v0.1.20-0.20261104000000-bbbbbbbbbbbb","Sum":"h1:zip="}`},
} { } {
t.Run(c.name, func(t *testing.T) { t.Run(c.name, func(t *testing.T) {
gomod := zeroMod gomod := zeroMod
@@ -375,6 +372,15 @@ func TestARequirementAtTheZeroVersionIsTakenFromTheAskOrTheTrunk(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
st := states.waitEnd(t) 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 { if st.State != sdkstep.StepPassed {
t.Fatalf("the step ended %s: %s", st.State, st.Reason) t.Fatalf("the step ended %s: %s", st.State, st.Reason)
} }