From 02371b32debe2e1a7f9823ff8fb5272c786eebc4 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 23:37:51 +0100 Subject: [PATCH 1/3] 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 --- .../cmd/mesh-build-go/archive_test.go | 64 +++++++++++++++++++ .../mesh-build-go/cmd/mesh-build-go/fetch.go | 10 +-- .../cmd/mesh-build-go/gomoddirs_test.go | 8 +-- 3 files changed, 70 insertions(+), 12 deletions(-) diff --git a/modules/mesh-build-go/cmd/mesh-build-go/archive_test.go b/modules/mesh-build-go/cmd/mesh-build-go/archive_test.go index e7506cba0..6e2d1e2a7 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/archive_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/archive_test.go @@ -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) + } +} 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 bc193a3bc..b41150326 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/fetch.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/fetch.go @@ -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 } 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 index 1f1bafa43..78d4c1a43 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/gomoddirs_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/gomoddirs_test.go @@ -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) } -- 2.54.0 From ebf4d9896b4592ef163848718b381e12803c662f Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 23:38:37 +0100 Subject: [PATCH 2/3] Node build module: a bundle's publish carries the version the ask reserved Every bundle was published with an empty version, a by-digest publish, so the builder never saw package-published and the bundle was not marked against its reservation. Builds: design 47 H H-A-372 --- modules/mesh-build-node/cmd/mesh-build-node/build.go | 5 +++-- .../mesh-build-node/cmd/mesh-build-node/push_test.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/mesh-build-node/cmd/mesh-build-node/build.go b/modules/mesh-build-node/cmd/mesh-build-node/build.go index b0d9e1f07..91d587776 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/build.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/build.go @@ -198,8 +198,9 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) { return nil, fmt.Errorf("packing %s: %w", a.Name, err) } // Published from this process once the build ended, a candidate's as a trunk build's (ADR 0498 §1 §2; CAT-BN3): the - // step answers the seat's reference, or fails not stored. The packed bytes are never written to the node (L9). - if err := m.publishOn(ctx, steprun.ArtifactSeat, a.module+"/"+a.Name, "bundle", "", digest, archive); err != nil { + // step answers the seat's reference, or fails not stored. The packed bytes are never written to the node (L9). The + // publish carries the version the ask reserved, so the builder marks the bundle against its reservation (H-A-372). + if err := m.publishOn(ctx, steprun.ArtifactSeat, a.module+"/"+a.Name, "bundle", version, digest, archive); err != nil { return nil, fmt.Errorf("%s%s: %w", builds.NotStored, a.Name, err) } files := []string{} diff --git a/modules/mesh-build-node/cmd/mesh-build-node/push_test.go b/modules/mesh-build-node/cmd/mesh-build-node/push_test.go index 880a774d7..5e21c8905 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/push_test.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/push_test.go @@ -94,11 +94,14 @@ func archiveOf(t *testing.T, r BuildResult) []byte { } // 1587-S6 (ADR 0498 §1; CAT-BN3): a done bundle is published through oci-artifact-registry and answers the seat's -// reference of its archive, under the manifest's module. +// reference of its archive, under the manifest's module. Its publish names the version the ask reserved, so the bundle +// is marked against its reservation (design 47 H, H-A-372). func TestADoneBundleAnswersTheReferenceOfTheArchiveItPushed(t *testing.T) { m, _, _ := builtMachine(t, ``) store := withStore(t, m) - out, err := m.build(context.Background(), buildArgs()) + args := buildArgs() + args["version"] = "1.4.3" + out, err := m.build(context.Background(), args) if err != nil { t.Fatal(err) } @@ -109,6 +112,9 @@ func TestADoneBundleAnswersTheReferenceOfTheArchiveItPushed(t *testing.T) { if store.blobs["m/tools@"+r.Digest] == nil || len(store.seats) != 1 || store.seats[0] != steprun.ArtifactSeat { t.Errorf("the holder holds %d files through %v, not m/tools@%s through %s", len(store.blobs), store.seats, r.Digest, steprun.ArtifactSeat) } + if len(store.published) != 1 || store.published[0].Version != "1.4.3" { + t.Errorf("the bundle was published as %+v, want the ask's version 1.4.3", store.published) + } } // 1587-S7 and S8 (ADR 0498 §2, the lead's decision L9): a publish the holder refuses fails the step `not stored: -- 2.54.0 From b5c05b326a0b6fa8911a3f2de331446832da4e17 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 23:45:30 +0100 Subject: [PATCH 3/3] Go build module: a bundle's and an archive's publish carry the version the ask reserved Every bundle and archive was published with an empty version, a by-digest publish, so the builder marked none against its reservation: the same kind as the Node build module's bundles. Builds: design 47 H H-A-373 --- .../mesh-build-go/cmd/mesh-build-go/archive.go | 10 +++++----- .../mesh-build-go/cmd/mesh-build-go/build.go | 17 +++++++++-------- .../cmd/mesh-build-go/build_test.go | 8 +++++++- .../mesh-build-go/cmd/mesh-build-go/publish.go | 7 ++++--- .../cmd/mesh-build-go/publish_test.go | 15 +++++++++++---- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/modules/mesh-build-go/cmd/mesh-build-go/archive.go b/modules/mesh-build-go/cmd/mesh-build-go/archive.go index 5957f287c..42d1dd45f 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/archive.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/archive.go @@ -46,9 +46,9 @@ func (m *Module) httpClient() *http.Client { // buildArchive packs one archive artifact of the module in dir: a pinned file when it names a url, else the directory // `from` of the module's tree. -func (m *Module) buildArchive(ctx context.Context, workspace, module, name, dir string, art catalogue.Artifact, keep *sdkstep.KeptFor) (any, error) { +func (m *Module) buildArchive(ctx context.Context, workspace, module, name, dir string, art catalogue.Artifact, version string, keep *sdkstep.KeptFor) (any, error) { if art.URL != "" { - return m.pinnedArchive(ctx, workspace, module, name, art, keep) + return m.pinnedArchive(ctx, workspace, module, name, art, version, keep) } from := strings.Trim(path.Clean("/"+filepath.ToSlash(art.From)), "/") if strings.TrimSpace(art.From) == "" { @@ -80,12 +80,12 @@ func (m *Module) buildArchive(ctx context.Context, workspace, module, name, dir if !within(realDir, realRoot) { return nil, fmt.Errorf("the archive %s is taken from %q, which lies outside the module: it resolves to %s, and the module is %s", art.Name, art.From, realRoot, realDir) } - return m.packInto(ctx, workspace, module, name, art.Name, "archive", root, keep) + return m.packInto(ctx, workspace, module, name, art.Name, "archive", version, root, keep) } // pinnedArchive fetches the file an artifact is pinned to, checks it against the pin, lays it out as the artifact says // (kept whole as `file`, or unpacked from `within`) and packs it. -func (m *Module) pinnedArchive(ctx context.Context, workspace, module, name string, art catalogue.Artifact, keep *sdkstep.KeptFor) (any, error) { +func (m *Module) pinnedArchive(ctx context.Context, workspace, module, name string, art catalogue.Artifact, version string, keep *sdkstep.KeptFor) (any, error) { file, err := m.pinnedFile(ctx, workspace, art) if err != nil { return nil, fmt.Errorf("%s: %w", art.Name, err) @@ -114,7 +114,7 @@ func (m *Module) pinnedArchive(ctx context.Context, workspace, module, name stri } else if err := unpackUpstream(file, laid, art.Within); err != nil { return nil, fmt.Errorf("%s: %s (%s): %w", art.Name, art.URL, art.Version, err) } - return m.packInto(ctx, workspace, module, name, art.Name, "archive", laid, keep) + return m.packInto(ctx, workspace, module, name, art.Name, "archive", version, laid, keep) } // pinnedFile is the path of the pinned file in the workspace: kept from an earlier build when its bytes are still the diff --git a/modules/mesh-build-go/cmd/mesh-build-go/build.go b/modules/mesh-build-go/cmd/mesh-build-go/build.go index c903d1e80..d6a9a78ad 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/build.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/build.go @@ -129,7 +129,7 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) { return m.buildGoPackage(ctx, workspace, dir, *art, version, seat) } if art.Kind == "archive" { - return m.buildArchive(ctx, workspace, module, manifest.Module, dir, *art, keep) + return m.buildArchive(ctx, workspace, module, manifest.Module, dir, *art, version, keep) } if art.Kind != "bundle" || art.Language != "go" { return nil, fmt.Errorf("the artifact %s of %s is a %s of language %q: this module builds Go bundles and archives", name, manifest.Module, art.Kind, art.Language) @@ -176,7 +176,7 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) { if err := m.insideModule(workspace, dir, out); err != nil { return nil, fmt.Errorf("the output directory of %s: %w", art.Name, err) } - res, err := m.packInto(ctx, workspace, module, manifest.Module, art.Name, "bundle", out, keep) + res, err := m.packInto(ctx, workspace, module, manifest.Module, art.Name, "bundle", version, out, keep) if err != nil { return nil, err } @@ -186,16 +186,17 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) { // packInto packs a directory with mesh-sdk's Pack, as the build agent packs every artifact, and publishes the archive // on the seat oci-artifact-registry from this process, after the build step ended (design 51 *Publishing*; publish.go): -// a candidate's as a trunk build's, under / by its digest, of kind (bundle or archive). The step -// answers the reference; a publish the seat refuses fails the step `not stored:`, unless keep names the build of the -// artifact store's holder, which this node then keeps and answers as kept (keptbuilds.go). The packed bytes never stay on -// the node: they are held in this process until the publish answered (the lead's decision L9). -func (m *Module) packInto(ctx context.Context, workspace, module, name, artifact, kind, root string, keep *sdkstep.KeptFor) (BuildResult, error) { +// a candidate's as a trunk build's, under / by its digest and the ask's version (H-A-373), of kind +// (bundle or archive). The step answers the reference; a publish the seat refuses fails the step `not stored:`, unless +// keep names the build of the artifact store's holder, which this node then keeps and answers as kept (keptbuilds.go). +// The packed bytes never stay on the node: they are held in this process until the publish answered (the lead's +// decision L9). +func (m *Module) packInto(ctx context.Context, workspace, module, name, artifact, kind, version, root string, keep *sdkstep.KeptFor) (BuildResult, error) { archive, digest, err := steprun.Pack(root) if err != nil { return BuildResult{}, fmt.Errorf("packing %s: %w", artifact, err) } - if err := m.publishArchive(ctx, name, artifact, kind, digest, archive); err != nil { + if err := m.publishArchive(ctx, name, artifact, kind, version, digest, archive); err != nil { if keep == nil { return BuildResult{}, fmt.Errorf("%s%s: %w", builds.NotStored, artifact, err) } diff --git a/modules/mesh-build-go/cmd/mesh-build-go/build_test.go b/modules/mesh-build-go/cmd/mesh-build-go/build_test.go index 4b1bebf26..e26f61f48 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/build_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/build_test.go @@ -57,10 +57,16 @@ func buildModule(t *testing.T, manifest, content string) (*Module, *keptStates, } func runBuild(t *testing.T, m *Module, states *keptStates, artifact string) (BuildResult, sdkstep.Step) { + t.Helper() + return runBuildArgs(t, m, states, map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": artifact}) +} + +// runBuildArgs runs the build tool with args, such as an ask's version, and answers what its step ended with. +func runBuildArgs(t *testing.T, m *Module, states *keptStates, args map[string]any) (BuildResult, sdkstep.Step) { t.Helper() for _, tool := range m.Tools(m.StepTools()) { if tool.Name == "build_go_build" { - if _, err := tool.Run(map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": artifact}); err != nil { + if _, err := tool.Run(args); err != nil { t.Fatal(err) } } diff --git a/modules/mesh-build-go/cmd/mesh-build-go/publish.go b/modules/mesh-build-go/cmd/mesh-build-go/publish.go index 43fbdd9f2..b7e469ae8 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/publish.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/publish.go @@ -23,9 +23,10 @@ func transferName(module, artifact, digest string) string { return steprun.TransferName(module, artifact, digest) } -// publishArchive publishes body, of digest, as / of kind (bundle or archive) on the artifact seat. -func (m *Module) publishArchive(ctx context.Context, module, artifact, kind, digest string, body []byte) error { - return m.publishOn(ctx, ArtifactSeat, module+"/"+artifact, kind, "", digest, transferName(module, artifact, digest), body) +// publishArchive publishes body, of digest, as / of kind (bundle or archive) on the artifact seat, under +// the version the ask reserved, so the builder marks it against its reservation (design 47 H, H-A-373). +func (m *Module) publishArchive(ctx context.Context, module, artifact, kind, version, digest string, body []byte) error { + return m.publishOn(ctx, ArtifactSeat, module+"/"+artifact, kind, version, digest, transferName(module, artifact, digest), body) } // publishOn publishes body through steprun.PublishOne: through Call when a test set it, else the runtime's request diff --git a/modules/mesh-build-go/cmd/mesh-build-go/publish_test.go b/modules/mesh-build-go/cmd/mesh-build-go/publish_test.go index 0bd446c43..92b0cc160 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/publish_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/publish_test.go @@ -102,11 +102,12 @@ func archiveOf(t *testing.T, res BuildResult) []byte { } // 1587-S2 (ADR 0498 §1): a done build answers a reference of the stated form whose tail is the build's digest, and the -// store holds the archive there; a bundle and an archive alike. +// store holds the archive there; a bundle and an archive alike. Each publish names the version the ask reserved, so the +// builder marks it against its reservation (design 47 H, H-A-373). func TestADoneBuildAnswersTheReferenceOfTheArchiveItPushed(t *testing.T) { m, states, _ := buildModule(t, manifestWith(goBundle), "the program") store := withStore(t, m) - res, st := runBuild(t, m, states, "tools") + res, st := runBuildArgs(t, m, states, map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": "tools", "version": "1.4.3"}) if st.State != sdkstep.StepPassed { t.Fatalf("the step ended %s: %s", st.State, st.Reason) } @@ -116,12 +117,18 @@ func TestADoneBuildAnswersTheReferenceOfTheArchiveItPushed(t *testing.T) { if store.blobs["demo/tools@"+res.Digest] == nil || store.asked[0] != "seat:oci-artifact-registry.publish" { t.Errorf("the seat was asked %v and holds %d blobs, not demo/tools@%s", store.asked, len(store.blobs), res.Digest) } + if len(store.published) != 1 || store.published[0].Version != "1.4.3" { + t.Errorf("the bundle was published as %+v, want the ask's version 1.4.3", store.published) + } a, states2, _ := archiveModule(t, "") - withStore(t, a) - arch, st := runBuild(t, a, states2, "files") + astore := withStore(t, a) + arch, st := runBuildArgs(t, a, states2, map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": "files", "version": "1.4.3"}) if st.State != sdkstep.StepPassed || arch.Reference != "oci-artifact-registry/demo/files@"+arch.Digest { t.Errorf("the archive artifact: %s %q, reference %q", st.State, st.Reason, arch.Reference) } + if len(astore.published) != 1 || astore.published[0].Version != "1.4.3" { + t.Errorf("the archive was published as %+v, want the ask's version 1.4.3", astore.published) + } } // 1587-S3 (ADR 0498 §2), CAT-BG1: a publish the seat's holder refuses fails the step `not stored: :