From b5c05b326a0b6fa8911a3f2de331446832da4e17 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 23:45:30 +0100 Subject: [PATCH] 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: :