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
This commit is contained in:
2026-11-21 23:45:30 +01:00
parent ebf4d9896b
commit b5c05b326a
5 changed files with 36 additions and 21 deletions
@@ -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
@@ -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 <module>/<artifact> 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 <module>/<artifact> 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)
}
@@ -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)
}
}
@@ -23,9 +23,10 @@ func transferName(module, artifact, digest string) string {
return steprun.TransferName(module, artifact, digest)
}
// publishArchive publishes body, of digest, as <module>/<artifact> 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 <module>/<artifact> 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
@@ -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: <artifact>: <the