Go build module: a module directory that chooses no Go module is an empty scope

The builder sends a module's directory with every lane, and an archive is
packed by the Go build seat, so the fetch's refusal of a directory without
go.mod left every archive-only module without Go code unbuildable. Such a
directory is now an empty scope (the empty scope file written); a Go bundle
or package without go.mod still fails at its build step, naming it.

Builds: design 47 H H-A-371
This commit is contained in:
2026-11-21 23:37:51 +01:00
parent 32e1ed6c55
commit 02371b32de
3 changed files with 70 additions and 12 deletions
@@ -6,6 +6,7 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"io"
"net"
@@ -305,3 +306,66 @@ func TestAnArchiveOfALinkedModuleDirectoryIsRefused(t *testing.T) {
t.Errorf("an archive of outside files was left: %v", entries)
}
}
// H-A-371: an archive-only lane of a module with no Go code fetches (its directory chooses no Go module: an empty
// scope, never a refusal) and packs its archive.
func TestAnArchiveOnlyLaneOfAModuleWithNoGoCodeFetchesAndPacks(t *testing.T) {
files := map[string]string{}
fixture := filepath.Join("testdata", "repos", "archive")
err := filepath.Walk(fixture, func(p string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() {
return err
}
body, err := os.ReadFile(p)
rel, _ := filepath.Rel(fixture, p)
files[strings.TrimSuffix(filepath.ToSlash(rel), ".fixture")] = string(body)
return err
})
if err != nil {
t.Fatal(err)
}
// Another module of the repository holds Go code; the archive module's directory holds none.
f := &fakeStep{gomods: "modules/other/go.mod\n", files: files}
m, states := fetchModule(t, f)
withStore(t, m)
if _, err := fetchTool(t, m)(map[string]any{"repository": "novox/mesh-catalog", "commit": commitSHA, "dir": "modules/demo"}); err != nil {
t.Fatal(err)
}
st := states.waitEnd(t)
if st.State != sdkstep.StepPassed {
t.Fatalf("the fetch ended %s: %s", st.State, st.Reason)
}
var fetched FetchResult
if err := json.Unmarshal(st.Result, &fetched); err != nil {
t.Fatal(err)
}
if len(fetched.Modules) != 0 {
t.Errorf("the fetch chose the Go modules %v, want none", fetched.Modules)
}
if b, err := os.ReadFile(filepath.Join(m.Work, fetched.Workspace, scopeMark)); err != nil || len(b) != 0 {
t.Errorf("the scope beside the tree is %q, %v; want the empty scope", b, err)
}
for _, l := range f.lines() {
if strings.HasPrefix(l, "go ") {
t.Errorf("a fetch that chose no Go module ran %s", l)
}
}
for _, tool := range m.Tools(m.StepTools()) {
if tool.Name == "build_go_build" {
if _, err := tool.Run(map[string]any{"workspace": fetched.Workspace, "module": "modules/demo", "artifact": "files"}); err != nil {
t.Fatal(err)
}
}
}
st = states.waitEnd(t)
if st.State != sdkstep.StepPassed {
t.Fatalf("the build ended %s: %s", st.State, st.Reason)
}
var res BuildResult
if err := json.Unmarshal(st.Result, &res); err != nil {
t.Fatal(err)
}
if res.Artifact != "files" || res.Size == 0 || res.Reference == "" || len(archiveOf(t, res)) != res.Size {
t.Errorf("the archive was not packed and published: %+v", res)
}
}
@@ -691,8 +691,8 @@ func cleanDir(dir string) string {
// scopedDirs are the go.mod directories of all that a module directory dir chooses: dir itself and each directory its
// go.mod replaces with a local path, followed through their own replaces (design 47 G, A-447), in order. A directory
// the tree holds no go.mod for is left out. A directory holding no go.mod chooses every go.mod under it, and one that
// chooses no Go module at all is an error naming it (A-447a).
// the tree holds no go.mod for is left out. A directory holding no go.mod chooses every go.mod under it (A-447a), and one that
// chooses no Go module at all is an empty scope (H-A-371).
func scopedDirs(tree, dir string, paths, all []string) ([]string, error) {
have := map[string]bool{}
for _, d := range all {
@@ -752,8 +752,8 @@ func scopedDirs(tree, dir string, paths, all []string) ([]string, error) {
out = append(out, d)
}
}
if len(out) == 0 {
return nil, fmt.Errorf("the module directory %q holds no Go module (no go.mod in it or under it)", dir)
}
// A directory that chooses no Go module (a module with an archive artifact and no Go code) is an empty scope, never
// a refusal: the builder sends its directory with every lane, and its archive is packed here. A Go bundle or package
// whose directory holds no go.mod fails at its build step, naming it (design 47 H, H-A-371).
return out, nil
}
@@ -58,7 +58,7 @@ func TestAFetchAskedWithADirectoryChoosesItsModuleAndWhatItReplacesAlone(t *test
{"seats", []string{"seats/a", "seats/b"}}, // a go.mod per seat, none in seats itself
{".", []string{"."}}, // the root holds a go.mod
{"rootless/x", []string{"rootless/x/go"}}, // Go code lies in go/
{"modules/none", nil}, // chooses no Go module: an error naming it
{"modules/none", []string{}}, // chooses no Go module: an empty scope (H-A-371)
} {
tree := t.TempDir()
for d, body := range mods {
@@ -70,12 +70,6 @@ func TestAFetchAskedWithADirectoryChoosesItsModuleAndWhatItReplacesAlone(t *test
}
}
got, err := scopedDirs(tree, cleanDir(c.dir), nil, all)
if c.want == nil {
if err == nil || !strings.Contains(err.Error(), c.dir) {
t.Errorf("dir %q chose %v, %v; want an error naming it", c.dir, got, err)
}
continue
}
if err != nil || !reflect.DeepEqual(got, c.want) {
t.Errorf("dir %q chooses %v, %v; want %v", c.dir, got, err, c.want)
}