From e29aa8aca9139128bffacf6d6305e397d00390f3 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 23:12:29 +0100 Subject: [PATCH] Design 47 H1: a done build key keeps the pins it was built with, and its step's end reports those (H-A-207) A build step whose key was done before reported the pins it resolved at that moment, so a publish since would have the runner ask the waiting test steps against a version the build was never built with. The done key's record keeps the versions its Go ask was built with, beside its digests, and the step's end reports the record's; a done key keeping none reports none, so the runner ends those steps could not run, loud. Builds: design 47 H H-A-207, H-A-203 --- .../mesh-delivery-builder/builds/builds.go | 5 +++++ .../internal/build/run.go | 18 ++++++++++++++- .../internal/build/step.go | 22 ++++++++++++++++--- .../internal/build/step_test.go | 22 +++++++++++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/modules/mesh-delivery-builder/builds/builds.go b/modules/mesh-delivery-builder/builds/builds.go index 8981c7dc..04c3c6cd 100644 --- a/modules/mesh-delivery-builder/builds/builds.go +++ b/modules/mesh-delivery-builder/builds/builds.go @@ -242,6 +242,11 @@ type BuilderBuild struct { // Imports are, on a done key, the mesh packages the built programs import, as the build module answered them // (BuildAnswer.Imports; novox/hq ADR 0593 §2): the builder carries them onto the build's end (BuildLogEntry.Imports). Imports []string `json:"imports,omitempty"` + // Packages are, on a done key only, the mesh packages' versions its Go build was built with, by module path, the ones + // the registry gave a package the entry named with none included (H-A-207): the build step's end reports them, so the + // runner asks the steps that waited for the pins with what the build was built against. A reader that does not know + // the field reads the build as reporting none. + Packages map[string]string `json:"packages,omitempty"` // Needs are, on a done key only, the reader capabilities (`form:`) the build's reference forms need of a // node-engine, beside the ones its manifest needs (novox/hq ADR 0618 §1). A reader that does not know the field // reads the build as needing none. diff --git a/modules/mesh-delivery-builder/internal/build/run.go b/modules/mesh-delivery-builder/internal/build/run.go index ba6f3e3c..b893e9a1 100644 --- a/modules/mesh-delivery-builder/internal/build/run.go +++ b/modules/mesh-delivery-builder/internal/build/run.go @@ -833,6 +833,7 @@ type lane struct { tcVersion string // and the version it ran kept string // the digest of the artifact the build node kept instead of storing it (BuildAnswer.Kept), else empty outOfStep []string // the generated files its build module's compare found out of step, passed or failed + pins map[string]string // the mesh packages' versions its Go ask was built with (H-A-207) err error } @@ -982,7 +983,7 @@ func (b *Builder) build(ctx context.Context, module string, m meshcatalog.Module used = nil } done := builds.BuilderBuild{State: builds.BuildDone, By: b.Claimer.By, Manifest: m.Manifest, Step: step, Artifacts: artifacts, Toolchains: used, - Imports: importsOf(lanes), Needs: forms.Current.Needs(artifacts)} // the forms it is written in (ADR 0618 §1) + Imports: importsOf(lanes), Needs: forms.Current.Needs(artifacts), Packages: pinsOf(lanes)} // the forms it is written in (ADR 0618 §1) for _, l := range lanes { if l.kept != "" { done.KeptOn = l.node // design 47 G §671: the build node that keeps the build @@ -1144,6 +1145,7 @@ func (b *Builder) runLane(ctx context.Context, l *lane, repository string, m mes for _, fb := range req.Builds { delete(ask.Packages, fb.Package) // a package `builds` names is named in neither packages nor package (§465) } + l.pins = maps.Clone(ask.Packages) // kept with the done key, so its step's end reports them (H-A-207) } if id := asked.resume(language); id != "" { ask.ID = id // put before this builder started again: the stream holds it, or a node already ran it @@ -1326,6 +1328,20 @@ func (b *Builder) takeOutOfStep(key string) []string { // importsOf are the mesh packages the lanes' programs import, as their build modules answered them (novox/hq ADR 0593 // §2): sorted and each once; nil when none answered any. A lane kept from a prior build answered none, so a build that // kept one reports only what it built. +// pinsOf is the mesh packages' versions the lanes were built with (H-A-207), nil when none was pinned. +func pinsOf(lanes []*lane) map[string]string { + var out map[string]string + for _, l := range lanes { + for p, v := range l.pins { + if out == nil { + out = map[string]string{} + } + out[p] = v + } + } + return out +} + func importsOf(lanes []*lane) []string { seen := map[string]bool{} for _, l := range lanes { diff --git a/modules/mesh-delivery-builder/internal/build/step.go b/modules/mesh-delivery-builder/internal/build/step.go index cfff2cac..bd24c5a3 100644 --- a/modules/mesh-delivery-builder/internal/build/step.go +++ b/modules/mesh-delivery-builder/internal/build/step.go @@ -66,8 +66,8 @@ func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbui return finish(meshbuilds.StepEndedOutcomePassed, "") } -// buildEntry builds one entry at its fingerprint and waits for its end; pins is set to the pins it is built with, the -// entry's own and those the registry gave a package the entry named with none (H-A-207). +// buildEntry builds one entry at its fingerprint and waits for its end; pins is set, when it is done, to the pins its +// done key keeps it was built with, the registry's included (H-A-207). func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry, pins *map[string]string) (outcome, said string) { entry, err := b.StepEntry(ctx, e.Fingerprint) if err != nil { @@ -82,7 +82,6 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry, pins return outcome, said } entry.Packages = pinned - *pins = pinned key, err := builds.BuilderBuildKey(entry.Module, entry.Fp) if err != nil { return meshbuilds.StepEndedOutcomeCouldNotRun, err.Error() @@ -91,6 +90,8 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry, pins defer b.dropEnd(key, ended) if done, failedWords, found := b.keyEnd(ctx, key); found { if done { + // A key done before reports the pins it was built with, kept with it, never the ones a publish gives now. + *pins = b.keptPins(ctx, key) return b.passedWithItsVersion(ctx, entry) } return meshbuilds.StepEndedOutcomeFailed, failedWords @@ -101,6 +102,7 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry, pins select { case log := <-ended: if log.Outcome == builds.BuildDone { + *pins = b.keptPins(ctx, key) return b.passedWithItsVersion(ctx, entry) } return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s at %s: %s %s", log.Module, log.FP, log.Outcome, log.Error) @@ -149,6 +151,20 @@ func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.Ca return meshbuilds.StepEndedOutcomePassed, "" } +// keptPins are the pins a done key keeps it was built with (H-A-207); none when it keeps none or cannot be read, so the +// runner ends the steps that waited for them could not run, loud. +func (b *Builder) keptPins(ctx context.Context, key string) map[string]string { + raw, _, ok, err := b.Claimer.Store.Get(ctx, key) + if err != nil || !ok { + return nil + } + v, err := builds.DecodeBuilderBuild(raw) + if err != nil || v.State != builds.BuildDone { + return nil + } + return v.Packages +} + // keyEnd reads the build key: whether it is done, and its error when it failed for good; found only for a key that has ended. func (b *Builder) keyEnd(ctx context.Context, key string) (done bool, failed string, found bool) { raw, _, ok, err := b.Claimer.Store.Get(ctx, key) diff --git a/modules/mesh-delivery-builder/internal/build/step_test.go b/modules/mesh-delivery-builder/internal/build/step_test.go index 08bbbedd..c70f1ae4 100644 --- a/modules/mesh-delivery-builder/internal/build/step_test.go +++ b/modules/mesh-delivery-builder/internal/build/step_test.go @@ -193,6 +193,28 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) { if !reflect.DeepEqual(end.Packages, map[string]string{unpinnedX: "v0.1.3", "git.novox.be/novox/mesh-sdk/go": "v0.1.20"}) { t.Errorf("the end reports the pins %v; want the ones it was built with", end.Packages) } + // A done key reports the pins it keeps it was built with, never the newer one a publish gives now (H-A-207). + r.b.PackagePublished(unpinnedX, "v0.1.5") + again := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) + if again.Outcome != meshbuilds.StepEndedOutcomePassed || again.Packages[unpinnedX] != "v0.1.3" { + t.Errorf("the done key's end = %+v; want passed reporting x at v0.1.3, as built", again) + } + // A done key that keeps no pins reports none, so the runner ends the waiting steps loud. + v, err := builds.DecodeBuilderBuild(r.st.vals[r.key]) + if err != nil { + t.Fatal(err) + } + v.Packages = nil + raw, err := builds.EncodeBuilderBuild(v) + if err != nil { + t.Fatal(err) + } + r.st.vals[r.key] = raw + if bare := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41, + Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}); len(bare.Packages) != 0 { + t.Errorf("a done key keeping no pins reported %v; want none", bare.Packages) + } } func aPackageWithNoReleaseFailsPastItsBound(t *testing.T) {