R8: a mover's released version is heard from version-released
The runner consumes mesh-catalog.version-released and writes its version into the mover of that module in the pipeline of the source revision built, on the branch the version was released for (the registration's first watched branch), by compare-and-set, so pipeline-ended names the version released. Unit tests 80 to 81. Builds: design 47 H §746 (the released version per mover); lead answers H-A-52, H-A-62 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -262,6 +262,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err := hearTakenIn(heard, starter, rv.Catalog, logger.Printf); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := hearReleased(heard, hearer, starter.Registration, logger.Printf); err != nil {
|
||||
return err
|
||||
}
|
||||
// An entry whose step ended and was not appended is appended at the start, in order (§606, §549).
|
||||
hearer.AppendUnlogged()
|
||||
// A test run whose bound passed while the runner was away ends now, as its expiry would have ended it (§725).
|
||||
|
||||
@@ -90,3 +90,23 @@ func hearTakenIn(hub handlers, starter *pipeline.Starter, v *pipeline.Views, log
|
||||
_ = m.Ack()
|
||||
})
|
||||
}
|
||||
|
||||
// hearReleased writes each version-released's version into its mover (design 47 H §746, H-A-52), so the pipeline's end names
|
||||
// the version released; a write that failed is heard again.
|
||||
func hearReleased(hub handlers, h *pipeline.Hearer, reg func(string) (catalog.Registration, bool), logf func(string, ...any)) error {
|
||||
return hub.Handle(catalog.SubjectVersionReleased, func(m jetstream.Msg) {
|
||||
var ev catalog.VersionReleasedEvent
|
||||
if err := json.Unmarshal(m.Data(), &ev); err != nil {
|
||||
logf("%s is no version-released: %v", m.Subject(), err)
|
||||
_ = m.Term()
|
||||
return
|
||||
}
|
||||
n, err := h.Released(ev, pipeline.ReleasedBranch(reg, ev.Module))
|
||||
if err != nil {
|
||||
logf("the version %s of %s: %d movers written, then %v; heard again", ev.Version, ev.Module, n, err)
|
||||
_ = m.Nak()
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
)
|
||||
@@ -98,3 +99,29 @@ func TestThePipelinePassesOnNothingToRunAndFailsOnOneMover(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// R8 (design 47 H §746, H-A-52, H-A-62): a version-released writes its version into the mover of that module in the pipeline
|
||||
// of the source revision built, on the branch it was released for, so pipeline-ended names it; another branch's pipeline,
|
||||
// and a version heard again, write nothing.
|
||||
func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
h, store, _, _ := twoMovers(t)
|
||||
other := store[pkey]
|
||||
other.p.Pipeline, other.p.Branch, other.p.Movers = "beta.5", "beta", append([]seat.Mover(nil), other.p.Movers...)
|
||||
store["beta.5"] = other
|
||||
ev := catalog.VersionReleasedEvent{Module: "app", Version: "0.4.1", Source: 5}
|
||||
if n, err := h.Released(ev, "main"); n != 1 || err != nil {
|
||||
t.Fatalf("released wrote %d (%v), want app's mover of main.5", n, err)
|
||||
}
|
||||
if m, _ := MoverOf(store[pkey].p, "app"); m.Version != "0.4.1" {
|
||||
t.Errorf("app's mover = %+v, want version 0.4.1", m)
|
||||
}
|
||||
if m, _ := MoverOf(store["beta.5"].p, "app"); m.Version != "" {
|
||||
t.Errorf("beta's mover = %+v, want no version: released for main", m)
|
||||
}
|
||||
if n, _ := h.Released(ev, "main"); n != 0 {
|
||||
t.Errorf("the version heard again wrote %d", n)
|
||||
}
|
||||
if got := pipelineEnded(store[pkey].p).Movers[1]; got.Module != "app" || got.Version != "0.4.1" {
|
||||
t.Errorf("pipeline-ended names %+v, want app at 0.4.1", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
// Released writes a version-released's version into the entry of the mover it names (design 47 H §746, H-A-52): the mover of
|
||||
// that module in each pipeline of the source revision built, a run's aside, so its pipeline-ended names the released version.
|
||||
// branch, when not empty, is the one watched branch the version was released for (H-A-62); empty matches every branch's
|
||||
// pipeline of that source. It says how many movers it wrote.
|
||||
func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int, error) {
|
||||
if ev.Module == "" || ev.Version == "" || ev.Source <= 0 {
|
||||
return 0, fmt.Errorf("a version-released names its module, version and source revision: %+v", ev)
|
||||
}
|
||||
b := "*"
|
||||
if branch != "" {
|
||||
b = keys.EscapeName(branch)
|
||||
}
|
||||
source := strconv.FormatInt(ev.Source, 10)
|
||||
var pkeys []string
|
||||
for _, f := range []string{b + "." + source, b + "." + source + ".published.*.*"} {
|
||||
k, err := h.Store.Keys(f)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("the pipelines of source %s are not listed: %w", source, err)
|
||||
}
|
||||
pkeys = append(pkeys, k...)
|
||||
}
|
||||
wrote := 0
|
||||
for _, key := range pkeys {
|
||||
for {
|
||||
p, rev, err := h.Store.Get(key)
|
||||
if err != nil {
|
||||
return wrote, fmt.Errorf("the pipeline %s is not read: %w", key, err)
|
||||
}
|
||||
i := -1
|
||||
for j, m := range p.Movers {
|
||||
if m.Module == ev.Module {
|
||||
i = j
|
||||
}
|
||||
}
|
||||
if i < 0 || p.Movers[i].Version == ev.Version {
|
||||
break
|
||||
}
|
||||
p.Movers[i].Version = ev.Version
|
||||
if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return wrote, fmt.Errorf("the pipeline %s cannot be written: %w", key, err)
|
||||
}
|
||||
wrote++
|
||||
break
|
||||
}
|
||||
}
|
||||
if wrote == 0 {
|
||||
h.logf("the version %s of %s at source %d names no mover of a pipeline here", ev.Version, ev.Module, ev.Source)
|
||||
}
|
||||
return wrote, nil
|
||||
}
|
||||
|
||||
// ReleasedBranch is the watched branch a module's versions are released for, its registration's first (H-A-62); empty when
|
||||
// the registration is not held.
|
||||
func ReleasedBranch(reg func(string) (catalog.Registration, bool), module string) string {
|
||||
if reg == nil {
|
||||
return ""
|
||||
}
|
||||
if r, ok := reg(module); ok && len(r.Branches) > 0 {
|
||||
return r.Branches[0]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -26,6 +26,7 @@ func (m memStore) Get(key string) (seat.Pipeline, uint64, error) {
|
||||
}
|
||||
// A read is a copy, as one from the bus is: a change not written is not seen by the next read.
|
||||
e.p.Steps = append([]seat.StepResult(nil), e.p.Steps...)
|
||||
e.p.Movers = append([]seat.Mover(nil), e.p.Movers...)
|
||||
return e.p, e.rev, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestManifest(t *testing.T) {
|
||||
"operator-channel.decided", "node-build-go.step-ended", "node-build-node.step-ended",
|
||||
"node-build-image.step-ended", "node-build-go.ask-taken", "node-build-node.ask-taken", "node-build-image.ask-taken",
|
||||
"node-build-go.step-progress", "node-build-node.step-progress", "node-build-image.step-progress", "mesh-wants.step-ended", "mesh-catalog.registration-changed",
|
||||
"mesh-catalog.catalog-revision", "mesh-conditions.findings-asked", "mesh-delivery.recovery-merged",
|
||||
"mesh-catalog.catalog-revision", "mesh-catalog.version-released", "mesh-conditions.findings-asked", "mesh-delivery.recovery-merged",
|
||||
// A-186: the seat list its write verbs' callers are checked against, heard as it changes.
|
||||
"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed",
|
||||
// §647 as A-466z amends it: no holder is read from the seat-holders view.
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
"mesh-wants.step-ended",
|
||||
"mesh-catalog.registration-changed",
|
||||
"mesh-catalog.catalog-revision",
|
||||
"mesh-catalog.version-released",
|
||||
"mesh-conditions.findings-asked",
|
||||
"mesh-delivery.recovery-merged",
|
||||
"mesh-catalog.seat-definition-changed",
|
||||
|
||||
Reference in New Issue
Block a user