The builder takes each step ask on a worker of its own and says step-progress (design 47 H2, H-A-514) #348

Merged
mesh-tools merged 7 commits from fix/builder-events-backlog into main 2026-11-23 08:46:19 +00:00
20 changed files with 562 additions and 94 deletions
@@ -1,12 +1,18 @@
package main
import (
"encoding/json"
"errors"
"slices"
"sync"
"time"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
stdio "git.novox.be/novox/mesh-sdk/go"
"mesh-delivery-builder/internal/versions"
)
// slowEventSetting is the setting slow-event (design 47 H2 §794; H-A-461 (2), P11): how long the handling of one heard event
@@ -53,3 +59,79 @@ func takeEvent(m jetstream.Msg, takers []eventTaker, rest eventTaker, slow time.
logf("the event %s took %s to handle, over %s: %s took it", m.Subject(), took.Round(time.Millisecond), slow, part)
}
}
// eventWorkers hands each event of the builder's durable to a worker of its key (design 47 H2 H-A-514 addenda): the name the
// event carries (a registry seat's outcome's package name, a version-released's module), one shared worker for the events that
// name none. One key's events are handled in the order heard, the keys side by side, so a slow event of one name delays no
// other name's. A worker ends when its queue is empty. The builder holds no timer (ADR 0437 §8), so the events still waiting in
// a queue are said in progress to the bus each time its worker ends a handling, and none waits out the ack wait behind another.
type eventWorkers struct {
handle func(jetstream.Msg)
keyOf func(jetstream.Msg) string
mu sync.Mutex
queues map[string]*eventQueue
}
// eventQueue is one key's events not yet handled, the one handled now first.
type eventQueue struct{ msgs []jetstream.Msg }
// take queues m on its key's worker, starting the worker when none runs.
func (w *eventWorkers) take(m jetstream.Msg) {
key := w.keyOf(m)
w.mu.Lock()
if w.queues == nil {
w.queues = map[string]*eventQueue{}
}
q, running := w.queues[key]
if !running {
q = &eventQueue{}
w.queues[key] = q
}
q.msgs = append(q.msgs, m)
w.mu.Unlock()
if !running {
go w.run(key, q)
}
}
// run handles key's events in order until its queue is empty, saying those still waiting in progress after each.
func (w *eventWorkers) run(key string, q *eventQueue) {
for {
w.mu.Lock()
if len(q.msgs) == 0 {
delete(w.queues, key)
w.mu.Unlock()
return
}
m := q.msgs[0]
w.mu.Unlock()
w.handle(m)
w.mu.Lock()
q.msgs = q.msgs[1:]
waiting := slices.Clone(q.msgs)
w.mu.Unlock()
for _, m := range waiting {
_ = m.InProgress()
}
}
}
// eventKey is the worker key of a builder's event (H-A-514 second addendum): a registry seat's outcome's name, a
// version-released's module, else "" (one worker for the events naming none).
func eventKey(m jetstream.Msg) string {
if _, ok := seatEvents[m.Subject()]; ok {
var o versions.Outcome
if json.Unmarshal(m.Data(), &o) == nil {
return "name " + o.Name
}
return ""
}
if m.Subject() == meshcatalog.SubjectVersionReleased {
var ev meshcatalog.VersionReleasedEvent
if json.Unmarshal(m.Data(), &ev) == nil {
return "module " + ev.Module
}
}
return ""
}
@@ -316,8 +316,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
return reserved.r.Of(ctx, module, version)
},
republish: republish.Republish, endedWith: reserved.unreleased,
// A publish is asked again only while no published of it may be unheard and the registry's record lacks it (H-A-269 (2), H-A-272).
unheard: unheardVia(js, process.EventsStream, cred.EventConsumerName()),
// A publish is asked again while the registry's record lacks it (H-A-269 (2), H-A-272; H-A-514 addendum: no backlog count).
judge: func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error) {
return republish.Held(ctx, v, registryVersionsVia(calls.Call))
},
@@ -502,7 +501,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
{"the registry seats' outcomes", func(m jetstream.Msg) bool { return seatHeard.heard(ctx, m) }},
}
gone := eventTaker{"the artifacts gone", func(m jetstream.Msg) bool { heardGone(ctx, b, m, logger.Printf); return true }}
events := func(m jetstream.Msg) { takeEvent(m, takers, gone, slow, nil, logger.Printf) }
// Each event goes to a worker of the name it carries, one name's events in order, the names side by side (H-A-514 addenda).
workers := &eventWorkers{keyOf: eventKey, handle: func(m jetstream.Msg) { takeEvent(m, takers, gone, slow, nil, logger.Printf) }}
events := workers.take
// The seats' events (artifacts-gone, the registry seats' words, the build seats' toolchain-reported, the indexer's take-in.taken and
// manifest-reads-changed and the seat mesh-conditions' condition-cleared: seatEventPatterns); the owners' views events and the
// catalog half's catalog-revision and registration-changed and the gate's source-moved are the views reader's (a message has
@@ -58,9 +58,6 @@ type publishItems struct {
// retired are the done builds a newer reservation or release of the same module supersedes, with why (H-A-291 (1)); nil
// retires none.
retired func(ctx context.Context, all []versions.ReservedVersion) (map[string]string, error)
// unheard is how many messages the builder's durable on the events stream holds pending and unacknowledged, read before each
// try (design 47 H H-A-269 (2), H-A-272); nil reads none.
unheard func(ctx context.Context) (int, error)
// judge is what the registries' own record says of a version's missing artifacts (H-A-272, H-A-274, H-A-275); nil judges none.
judge func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error)
// markHeld marks the artifacts the registries hold with the built digest published from their record, as their published heard
@@ -386,20 +383,11 @@ func (p *publishItems) Ended(ctx context.Context, module, version string) {
}
// notAgain says why a version's publish is not asked again now, empty when it is (design 47 H H-A-269 (2), H-A-272, H-A-274,
// H-A-275): the builder's durable holds UnheardBound messages or more not yet heard, so a published of it may be among them; or the
// registries' own record holds every missing artifact at its version with its built digest, which marks them published from that
// record; or a registry holds the version at another digest, which moves the build to the next free number (gone: this item is
// ended with the old number). A count or a record that cannot be read is said, and does not hold the ask.
// H-A-275), judged from what the builder recorded and the registries' record, never from a count of its events unheard (design
// 47 H2 H-A-514 addendum): the registries' own record holds every missing artifact at its version with its built digest, which
// marks them published from that record; or a registry holds the version at another digest, which moves the build to the next
// free number (gone: this item is ended with the old number). A record that cannot be read is said, and does not hold the ask.
func (p *publishItems) notAgain(ctx context.Context, v versions.ReservedVersion) (why string, gone bool) {
if p.unheard != nil {
n, err := p.unheard(ctx)
switch {
case err != nil:
p.logf("%s %s: the builder's events consumer cannot be read, so the publish is asked again as it stands: %v", v.Module, v.Version, err)
case n >= versions.UnheardBound:
return fmt.Sprintf("the builder's events consumer holds %d messages not yet heard (the bound is %d), a published of it may be among them", n, versions.UnheardBound), false
}
}
if p.judge == nil {
return "", false
}
@@ -424,22 +412,6 @@ func (p *publishItems) notAgain(ctx context.Context, v versions.ReservedVersion)
return "", false
}
// unheardVia reads the builder's durable on the events stream: its messages pending and those given and not yet acknowledged
// (design 47 H H-A-272), what it has not yet heard.
func unheardVia(js jetstream.JetStream, stream, durable string) func(context.Context) (int, error) {
return func(ctx context.Context) (int, error) {
c, err := js.Consumer(ctx, stream, durable)
if err != nil {
return 0, err
}
info, err := c.Info(ctx)
if err != nil {
return 0, err
}
return int(info.NumPending) + info.NumAckPending, nil
}
}
// registryVersionsVia asks a registry seat's verb versions for a name (H-A-272): each version it holds with its digest.
func registryVersionsVia(call toolCaller) func(context.Context, string, string) ([]versions.HeldVersion, error) {
return func(_ context.Context, seat, name string) ([]versions.HeldVersion, error) {
@@ -361,12 +361,12 @@ func TestThePublishItemsAreWiredToTheReservationsAndTheReAskWatch(t *testing.T)
}
}
// TestAPublishIsNotAskedAgainWhileItsPublishedMayBeUnheard: design 47 H H-A-269 (2), H-A-272, H-A-274, H-A-275 — a try asks the
// publish again only while the builder's durable holds fewer than a hundred messages not yet heard and the registries' record lacks
// an artifact; a record holding every missing artifact with the built digest marks them published from it; a record holding the
// version at another digest moves the build to the next free number and ends this item; a skipped try spends no try and is written
// again with its pause; a count that cannot be read holds no ask.
func TestAPublishIsNotAskedAgainWhileItsPublishedMayBeUnheard(t *testing.T) {
// Design 47 H H-A-269 (2), H-A-272, H-A-274, H-A-275, and design 47 H2 H-A-514 addendum: a publish is asked again judged from
// what the builder recorded and the registries' record alone, never from how many events its consumer holds unheard: a
// reservation marking every artifact published is acknowledged; a record holding every missing artifact with the built digest
// marks them published from it; a record holding the version at another digest moves the build to the next free number and
// ends this item; a record lacking it is asked again; a skipped try spends no try and is written again with its pause.
func TestAPublishIsAskedAgainFromWhatTheBuilderRecorded(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 11, 21, 15, 21, 0, 0, time.UTC)
v := versions.ReservedVersion{Module: "node-tools", Version: "0.1.37", Artifacts: map[string]string{"node-tools:program": "sha256:7c9b10"}, BuiltAt: now}
@@ -375,28 +375,31 @@ func TestAPublishIsNotAskedAgainWhileItsPublishedMayBeUnheard(t *testing.T) {
other.Digest = "sha256:83bec1"
for _, c := range []struct {
name string
unheard int
countErr error
published bool
judged versions.Judged
wantAsked, wantMark, wantMov bool
}{
{name: "thousands behind: no ask, the registry not read", unheard: 2944},
{name: "at the bound: no ask", unheard: versions.UnheardBound},
{name: "heard up, the registry holds it: marked from its record, no ask", unheard: versions.UnheardBound - 1, judged: versions.Judged{All: true, Held: []versions.HeldArtifact{at}}, wantMark: true},
{name: "the registry holds the number at another digest: moved, no ask", unheard: 3, judged: versions.Judged{Elsewhere: []versions.HeldArtifact{other}}, wantMov: true},
{name: "heard up, the registry lacks it: asked", unheard: 3, judged: versions.Judged{Lacks: "none"}, wantAsked: true},
{name: "the count unreadable, the registry lacks it: asked", countErr: errors.New("no consumer"), judged: versions.Judged{Lacks: "none"}, wantAsked: true},
{name: "its reservation marks it published: acknowledged, no ask", published: true},
{name: "the registry holds it: marked from its record, no ask", judged: versions.Judged{All: true, Held: []versions.HeldArtifact{at}}, wantMark: true},
{name: "the registry holds the number at another digest: moved, no ask", judged: versions.Judged{Elsewhere: []versions.HeldArtifact{other}}, wantMov: true},
{name: "the registry lacks it: asked, whatever the events consumer holds", judged: versions.Judged{Lacks: "none"}, wantAsked: true},
} {
t.Run(c.name, func(t *testing.T) {
kv := &itemKV{vals: map[string][]byte{}, revs: map[string]uint64{}}
asked, judged, marked, moved := 0, 0, 0, 0
p := &publishItems{reasks: func() jetstream.KeyValue { return kv }, set: defaultPublishSettings, now: func() time.Time { return now }, logf: t.Logf,
reserved: func(context.Context, string, string) (versions.ReservedVersion, bool, error) { return v, true, nil },
reserved: func(context.Context, string, string) (versions.ReservedVersion, bool, error) {
if c.published {
w := v
w.Published = map[string]bool{"node-tools:program": true}
return w, true, nil
}
return v, true, nil
},
send: func(context.Context, versions.QueuedPublish) versions.SendFate {
asked++
return versions.SendFate{Sent: true}
},
unheard: func(context.Context) (int, error) { return c.unheard, c.countErr },
judge: func(context.Context, versions.ReservedVersion) (versions.Judged, error) {
judged++
return c.judged, nil
@@ -421,6 +424,12 @@ func TestAPublishIsNotAskedAgainWhileItsPublishedMayBeUnheard(t *testing.T) {
if (asked == 1) != c.wantAsked || (marked == 1) != c.wantMark || (moved == 1) != c.wantMov {
t.Fatalf("asked %d, marked %d, moved %d; want asked %v, marked %v, moved %v", asked, marked, moved, c.wantAsked, c.wantMark, c.wantMov)
}
if c.published {
if fmt.Sprint(m.settled) != "[ack]" || judged != 0 {
t.Errorf("a version its reservation marks published settled %v, the registry read %d times; want acknowledged, none read", m.settled, judged)
}
return
}
if c.wantMov {
if _, ok := kv.vals[key]; ok || fmt.Sprint(m.settled) != "[term]" {
t.Errorf("the moved version's old item is written again, or its item settled %v, not terminated", m.settled)
@@ -434,9 +443,6 @@ func TestAPublishIsNotAskedAgainWhileItsPublishedMayBeUnheard(t *testing.T) {
if !c.wantAsked && fmt.Sprint(m.settled) != "[nak 30s]" {
t.Errorf("an item not sent was settled %v, want it handed back with the pause and no try spent", m.settled)
}
if c.unheard >= versions.UnheardBound && judged != 0 {
t.Error("the registry is read while a published may be unheard")
}
})
}
}
@@ -328,6 +328,10 @@ func (rv *reservations) heard(ctx context.Context, m jetstream.Msg) bool {
// release takes a released version in as the catalog's version-released says it (design 47 G §369): its reservation released,
// its bound and publish item ended and its findings cleared. No git tag is written (design 47 H2 H-A-494).
func (rv *reservations) release(ctx context.Context, ev meshcatalog.VersionReleasedEvent) error {
// A version no reservation holds is acknowledged at once from its one key, never by listing (H-A-514 addendum).
if held, err := rv.r.Holds(ctx, ev.Module, ev.Version); err == nil && !held {
return nil
}
gone, err := rv.r.Released(ctx, ev.Module, ev.Version)
if err != nil {
return err
@@ -7,6 +7,7 @@ import (
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
"slices"
"strings"
"sync/atomic"
"testing"
"time"
@@ -14,6 +15,7 @@ import (
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
stdio "git.novox.be/novox/mesh-sdk/go"
@@ -24,8 +26,9 @@ import (
// memReserve is the state reserved in memory.
type memReserve struct {
vals map[string][]byte
revs map[string]uint64
vals map[string][]byte
revs map[string]uint64
lists int // how often its keys were listed
}
func (m *memReserve) Get(_ context.Context, key string) ([]byte, uint64, bool, error) {
@@ -47,6 +50,7 @@ func (m *memReserve) Update(_ context.Context, key string, v []byte, rev uint64)
return rev + 1, nil
}
func (m *memReserve) KeysOf(_ context.Context, filter string) ([]string, error) {
m.lists++
var out []string
for k := range m.vals {
if versions.FilterMatches(filter, k) { // as the bus reads a filter
@@ -213,6 +217,21 @@ func TestAReleasedVersionWritesNoTag(t *testing.T) {
if all, _ := rv.r.All(ctx); len(all) != 0 {
t.Fatalf("the released version still stands: %v", all)
}
// Design 47 H2 H-A-514 addendum: a version-released of a version no reservation holds is acknowledged at once from its
// series' one key, the module's keys never listed.
if _, err := rv.Reserve(ctx, "late", "0.2", []string{"late:bin"}, versions.Source{Repository: "o/l", Commit: "c1", Fingerprint: "fpL"}); err != nil {
t.Fatal(err)
}
store.lists = 0
if m := release("late", "0.2.7"); !m.acked || m.naked || store.lists != 0 {
t.Fatalf("a release no reservation holds: acked %v naked %v, the keys listed %d times; want it acknowledged with none", m.acked, m.naked, store.lists)
}
if _, standing, _ := rv.r.Of(ctx, "late", "0.2.0"); !standing {
t.Fatal("a release of another version took the standing reservation late 0.2.0")
}
if _, err := rv.r.Drop(ctx, "late", "0.2"); err != nil {
t.Fatal(err)
}
// The start check (H-A-484 c): a built reservation the catalog holds released is released at the start, no tag written; one
// not built, or not released, stands.
// Design 47 H2 H-A-492: at the start, a standing reservation with no digests recorded whose build key is done has them
@@ -657,6 +676,58 @@ func TestAPublishedThatMarksNothingIsSaidFromWhatItRead(t *testing.T) {
})
}
// Design 47 H2 H-A-514 addenda: each event goes to the worker of the name it carries, so a slow handling of one name holds
// no other name's events, one name's events are handled in the order heard, and an event waiting in its worker's queue is
// said in progress at each tick, so the bus does not give it again.
func TestEventsAreHandledByAWorkerPerName(t *testing.T) {
pub := func(name, v string) *queuedEvent {
return &queuedEvent{wakeMsg: wakeMsg{subject: gopackageregistry.SubjectPublished, data: []byte(`{"name":"` + name + `","version":"` + v + `","digest":"sha256:aa"}`)}}
}
if got := eventKey(&pub("a", "1").wakeMsg); got != "name a" {
t.Errorf("a published's key is %q, want its name", got)
}
if got := eventKey(&wakeMsg{subject: meshcatalog.SubjectVersionReleased, data: []byte(`{"module":"m","version":"0.1.0"}`)}); got != "module m" {
t.Errorf("a version-released's key is %q, want its module", got)
}
if got := eventKey(&wakeMsg{subject: takenInSubject, data: []byte(`{}`)}); got != "" {
t.Errorf("a take-in's key is %q, want the shared worker's", got)
}
release := make(chan struct{})
handled := make(chan string, 4)
w := &eventWorkers{keyOf: eventKey, handle: func(m jetstream.Msg) {
var o versions.Outcome
_ = json.Unmarshal(m.Data(), &o)
if o.Name == "a" && o.Version == "1" {
<-release
}
handled <- o.Name + "@" + o.Version
}}
a1, a2, a3, b1 := pub("a", "1"), pub("a", "2"), pub("a", "3"), pub("b", "1")
w.take(a1)
w.take(a2)
w.take(a3)
w.take(b1)
if got := <-handled; got != "b@1" {
t.Fatalf("handled %s first, want b's event while a's first one is slow", got)
}
close(release)
if got := []string{<-handled, <-handled, <-handled}; !slices.Equal(got, []string{"a@1", "a@2", "a@3"}) {
t.Errorf("a's events handled %v, want in the order heard", got)
}
// a's worker said its waiting events in progress at each end: a2 and a3 after a1, a3 again after a2.
if a1.progressed.Load() != 0 || a2.progressed.Load() != 1 || a3.progressed.Load() != 2 {
t.Errorf("in progress said %d, %d and %d times of a's events, want 0, 1 and 2", a1.progressed.Load(), a2.progressed.Load(), a3.progressed.Load())
}
}
// queuedEvent is an event of the builder's durable that counts its in-progress.
type queuedEvent struct {
wakeMsg
progressed atomic.Int32
}
func (m *queuedEvent) InProgress() error { m.progressed.Add(1); return nil }
// oneHandler is an event hub with one handler.
type oneHandler struct{ handle func(jetstream.Msg) }
@@ -178,4 +178,66 @@ func TestTheProcessAnswersReserved(t *testing.T) {
if _, err := drop("", json.RawMessage(`{"id":"ask-3"}`)); err == nil {
t.Error("a drop with no why was taken")
}
// Design 47 H2 H-A-514: each ask's take and its ask-taken are its own worker's, started at the pull, so an ask whose
// ask-taken hangs holds neither the pull nor the next ask's ask-taken.
hang, release := make(chan struct{}), make(chan struct{})
saidTaken := make(chan string, 4)
slow := &stepQueue{node: "n1", builder: blockingBuilder{started: make(chan string, 2)}, taken: &takenFake{vals: map[string][]byte{}, ttls: map[string]time.Duration{}},
takenBound: 10 * time.Minute, inProgress: func() time.Duration { return 0 }, logf: t.Logf, now: time.Now, running: map[string]*runningAsk{},
say: func(_ context.Context, subject, _ string, _ any) error {
if subject == meshbuilds.SubjectAskTaken("ask-5") {
close(hang)
<-release
}
if strings.Contains(subject, "ask-taken") {
saidTaken <- subject
}
return nil
}}
pulled := make(chan struct{})
go func() {
slow.take(t.Context(), stepMsg("ask-5"))
<-hang
slow.take(t.Context(), stepMsg("ask-6"))
close(pulled)
}()
await(t, pulled, "the pull of ask-6 while ask-5's ask-taken hangs")
select {
case s := <-saidTaken:
if s != meshbuilds.SubjectAskTaken("ask-6") {
t.Errorf("said %s first, want ask-6's ask-taken", s)
}
case <-time.After(5 * time.Second):
t.Error("ask-6's ask-taken waited behind ask-5's")
}
close(release)
await(t, saidTaken, "ask-5's ask-taken once let go")
// The H-A-514 addendum: while an ask builds or its build waits for a package, the builder says the seat mesh-builds'
// step-progress of it at each tick of its minute clock, so the runner's bound of the ask is armed again.
tick := make(chan time.Time)
progressed := make(chan meshbuilds.StepProgressEvent, 1)
building := make(chan string, 1)
pq := &stepQueue{node: "n1", builder: blockingBuilder{started: building}, taken: &takenFake{vals: map[string][]byte{}, ttls: map[string]time.Duration{}},
takenBound: 10 * time.Minute, inProgress: func() time.Duration { return 0 }, logf: t.Logf, now: time.Now, running: map[string]*runningAsk{},
progress: func() (<-chan time.Time, func()) { return tick, func() {} },
say: func(_ context.Context, subject, _ string, body any) error {
if p, ok := body.(meshbuilds.StepProgressEvent); ok && subject == meshbuilds.SubjectStepProgress("n1") {
progressed <- p
}
return nil
}}
pq.take(t.Context(), stepMsg("ask-7"))
await(t, building, "the build of ask-7")
at := time.Date(2026, 11, 23, 2, 41, 0, 0, time.UTC)
tick <- at
select {
case p := <-progressed:
if p.Ask != "ask-7" || p.Asker != "main.1.m" || p.Phase != meshbuilds.StepProgressEventPhaseBuild || !p.At.Equal(at) {
t.Errorf("step-progress said %+v", p)
}
case <-time.After(5 * time.Second):
t.Error("no step-progress was said of ask-7 while it builds")
}
}
@@ -66,6 +66,9 @@ type stepQueue struct {
takenBound time.Duration
// inProgress is how often a running ask is said in progress: the seat definition's in-progress.
inProgress func() time.Duration
// progress is the clock step-progress is said on while an ask builds or its build waits for a package: every
// stepProgressEvery (design 47 H2 H-A-514 addendum); a test's when set.
progress func() (<-chan time.Time, func())
// say publishes a seat event of the builder (emitSeatEvent).
say func(ctx context.Context, subject, id string, body any) error
logf func(string, ...any)
@@ -75,6 +78,19 @@ type stepQueue struct {
running map[string]*runningAsk
}
// stepProgressEvery is how often the builder says step-progress of an ask it builds (design 47 H2 H-A-514 addendum): once a
// minute, as the seat mesh-wants' holder says its own.
const stepProgressEvery = time.Minute
// progressClock is the clock of step-progress: the test's, else a ticker of stepProgressEvery.
func (q *stepQueue) progressClock() (<-chan time.Time, func()) {
if q.progress != nil {
return q.progress()
}
t := time.NewTicker(stepProgressEvery)
return t.C, t.Stop
}
// runningAsk is an ask the builder took and builds now.
type runningAsk struct {
run meshbuilds.StepRun
@@ -91,10 +107,9 @@ func askIDOf(h nats.Header) string {
}
// take handles one ask pulled from the queue: an ask that is no build step with an id is terminated, said; one this
// builder runs already (handed again while it runs) is left to the run that holds it; any other is taken (ask-taken said
// the first time its id is taken) and built on its own goroutine, in progress while it runs, acknowledged once its end is
// said. A repeat of an id taken before that runs here no longer (the builder started again) is answered as its builds
// stand now, read afresh by BuildStep (H-A-381 (1)): an entry built is answered built, never built twice.
// builder runs already (handed again while it runs) is left to the run that holds it; any other is held here and handed to
// a worker of its own, started at once (design 47 H2 H-A-514): the pull never waits on a state call or a publish of an
// earlier ask, so each ask's ask-taken is said within its bound whatever the others do.
func (q *stepQueue) take(ctx context.Context, m queueMsg) {
id := askIDOf(m.Headers())
var run meshbuilds.StepRun
@@ -110,36 +125,43 @@ func (q *stepQueue) take(ctx context.Context, m queueMsg) {
q.logf("the ask %s (%s) was handed again while it runs here: its run answers it", id, run.Pipeline)
return
}
// An ask dropped before it was pulled ends could-not-run naming the drop, with no build (H-A-404).
if d := q.droppedAsk(id); d != nil {
work, cancel := context.WithCancelCause(ctx)
cancel(d)
ra := &runningAsk{run: run, taken: q.now(), cancel: cancel}
q.running[id] = ra
q.mu.Unlock()
q.logf("the ask %s (%s) was dropped before it was pulled: %s", id, run.Pipeline, d.Error())
go q.build(work, m, id, ra)
return
}
first, err := q.taken.TakeOnce(meshbuilds.Seat, id, q.takenBound)
if err != nil {
q.mu.Unlock()
q.logf("the ask %s (%s) is not taken, the state %s refused it: %v; it is handed again", id, run.Pipeline, process.TakenState, err)
_ = m.Nak()
return
}
work, cancel := context.WithCancelCause(ctx)
ra := &runningAsk{run: run, taken: q.now(), cancel: cancel}
q.running[id] = ra
q.mu.Unlock()
go q.work(ctx, work, m, id, ra)
}
// work is one ask's worker (H-A-514): an ask dropped before it was pulled ends could-not-run naming the drop, with no build
// (H-A-404); any other is taken once by its id in the state taken (ask-taken said the first time it is taken) and built, in
// progress while it runs, acknowledged once its end is said. A repeat of an id taken before that runs here no longer (the
// builder started again) is answered as its builds stand now, read afresh by BuildStep (H-A-381 (1)): an entry built is
// answered built, never built twice. An ask the state taken refuses is let go and handed again.
func (q *stepQueue) work(ctx, work context.Context, m queueMsg, id string, ra *runningAsk) {
if d := q.droppedAsk(id); d != nil {
ra.cancel(d)
q.logf("the ask %s (%s) was dropped before it was pulled: %s", id, ra.run.Pipeline, d.Error())
q.build(work, m, id, ra)
return
}
first, err := q.taken.TakeOnce(meshbuilds.Seat, id, q.takenBound)
if err != nil {
ra.cancel(nil)
q.mu.Lock()
delete(q.running, id)
q.mu.Unlock()
q.logf("the ask %s (%s) is not taken, the state %s refused it: %v; it is handed again", id, ra.run.Pipeline, process.TakenState, err)
_ = m.Nak()
return
}
if first {
if err := q.say(ctx, meshbuilds.SubjectAskTaken(id), id+"-taken", meshbuilds.AskTakenEvent{Ask: id, Node: q.node, At: ra.taken.UTC()}); err != nil {
q.logf("saying ask-taken of %s: %v", id, err)
}
} else {
q.logf("the ask %s (%s) was taken before: it is answered as its builds stand now", id, run.Pipeline)
q.logf("the ask %s (%s) was taken before: it is answered as its builds stand now", id, ra.run.Pipeline)
}
go q.build(work, m, id, ra)
q.build(work, m, id, ra)
}
// build runs one taken ask to its end and says it.
@@ -157,6 +179,10 @@ func (q *stepQueue) build(ctx context.Context, m queueMsg, id string, ra *runnin
defer t.Stop()
tick = t.C
}
// step-progress is said every minute while the step builds or waits for a package, so the asker's bound of the ask is
// armed again (design 47 H2 H-A-514 addendum).
progress, stop := q.progressClock()
defer stop()
done := make(chan meshbuilds.StepEnded, 1)
go func() { done <- q.builder.BuildStep(ctx, id, ra.run) }()
var end meshbuilds.StepEnded
@@ -166,6 +192,11 @@ func (q *stepQueue) build(ctx context.Context, m queueMsg, id string, ra *runnin
waiting = false
case <-tick:
_ = m.InProgress()
case at := <-progress:
p := meshbuilds.StepProgressEvent{Ask: id, Asker: ra.run.Pipeline, Phase: meshbuilds.StepProgressEventPhaseBuild, At: at.UTC()}
if err := q.say(ctx, meshbuilds.SubjectStepProgress(q.node), fmt.Sprintf("%s-progress-%d", id, at.UnixNano()), p); err != nil {
q.logf("saying step-progress of %s: %v", id, err)
}
}
}
if err := q.say(context.WithoutCancel(ctx), meshbuilds.SubjectStepEnded(q.node), id, end); err != nil {
@@ -843,11 +843,6 @@ func (r *Reserver) MarkUnstored(ctx context.Context, module, version, artifact,
}
}
// UnheardBound is how many messages the builder's durable on the events stream may hold pending and unacknowledged while a
// publish is asked again (design 47 H H-A-269 (2), H-A-272): at or above it a published of the version may still be unheard, so
// the try is skipped. A constant of the builder, no setting.
const UnheardBound = 100
// HeldVersion is one version a registry seat's verb versions answers of a name, with its digest.
type HeldVersion struct {
Version, Digest string
@@ -534,6 +534,17 @@ func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version
}
}
// Holds answers whether a reservation holds module's version, from the one key of its series (design 47 H2 H-A-514
// addendum): a version-released of a version none holds is acknowledged at once, never by listing the module's keys.
func (r *Reserver) Holds(ctx context.Context, module, version string) (bool, error) {
series, _, err := SplitVersion(version)
if err != nil {
return false, err
}
cur, _, found, err := r.get(ctx, ReservedKey(module, series))
return found && cur.Version == version, err
}
// Released takes the catalog's version-released in: the key of that version is deleted, and every key of module's other
// series (the manifest moved on). A key holding a newer reserved version of the same series stays. It answers the keys
// deleted.
@@ -19,7 +19,7 @@ const Form = 2
// whose fields changed while its forms did not (design 47 H2 §780).
const (
generatedForms = "2"
generatedFieldsDigest = "AskTakenEvent=6d5d3da7ac39 BuildEntry=3c829a0a3d58 Dependency=90a32b07c563 DropAnswer=7538f2f5e68e PackagePublished=34dd069a6aab PackagePublishedEvent=8e12888c1559 PublishQueueAnswer=0f1326e35e17 PublishQueueAnswerCountsItem=b770db2f0920 PublishQueueAnswerQueueItem=b1eebc09f41e PublishedAnswer=69a801982819 ReservedAnswer=2272a4d6f0f4 ReservedAnswerArtifactsItem=d74eb6e00abb StepAccept=18efeefb6c34 StepEnded=40a0090f7cb5 StepEndedEvent=207787118dac StepRun=dc5893aef7e5 ToolchainAgreed=f3d9ce993734 ToolchainAgreedDigestsItem=1d42893a96b9 ToolchainAgreedEvent=e3502d6f194d VersionReservedEvent=984547d6ad07"
generatedFieldsDigest = "AskTakenEvent=6d5d3da7ac39 BuildEntry=3c829a0a3d58 Dependency=90a32b07c563 DropAnswer=7538f2f5e68e PackagePublished=34dd069a6aab PackagePublishedEvent=8e12888c1559 PublishQueueAnswer=0f1326e35e17 PublishQueueAnswerCountsItem=b770db2f0920 PublishQueueAnswerQueueItem=b1eebc09f41e PublishedAnswer=69a801982819 ReservedAnswer=2272a4d6f0f4 ReservedAnswerArtifactsItem=d74eb6e00abb Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=40a0090f7cb5 StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=dc5893aef7e5 ToolchainAgreed=f3d9ce993734 ToolchainAgreedDigestsItem=1d42893a96b9 ToolchainAgreedEvent=e3502d6f194d VersionReservedEvent=984547d6ad07"
)
const (
@@ -38,6 +38,7 @@ const (
EventToolchainAgreed = "toolchain-agreed"
EventStepEnded = "step-ended"
EventAskTaken = "ask-taken"
EventStepProgress = "step-progress"
EventVersionReserved = "version-reserved"
)
@@ -64,7 +65,7 @@ func VerbDescription(verb string) string {
// Events is every event published on the seat's subject: a new copy each call.
func Events() []string {
return []string{EventPackagePublished, EventToolchainAgreed, EventStepEnded, EventAskTaken, EventVersionReserved}
return []string{EventPackagePublished, EventToolchainAgreed, EventStepEnded, EventAskTaken, EventStepProgress, EventVersionReserved}
}
// Family is where the seat's events are kept: the shared events stream, filtered to the seat's subjects.
@@ -100,6 +101,14 @@ func SubjectAskTaken(ask string) string { return "mesh.seat.mesh-builds.event.as
// SubjectAskTakenAll hears every ask-taken.
const SubjectAskTakenAll = "mesh.seat.mesh-builds.event.ask-taken.*"
// SubjectStepProgress is where step-progress is published, on mesh.seat.mesh-builds.event.step-progress.<node>.
func SubjectStepProgress(node string) string {
return "mesh.seat.mesh-builds.event.step-progress." + node
}
// SubjectStepProgressAll hears every step-progress.
const SubjectStepProgressAll = "mesh.seat.mesh-builds.event.step-progress.*"
// SubjectVersionReserved is where version-reserved is published.
const SubjectVersionReserved = "mesh.seat.mesh-builds.event.version-reserved"
@@ -150,6 +159,26 @@ type PackagePublished struct {
Version string `json:"version"`
}
// SharedAskedBy is the step that asked the run, for a test step reading another's run.
type SharedAskedBy struct {
// its artifact, <module>:<artifact>
Artifact string `json:"artifact"`
// its pipeline's key
Pipeline string `json:"pipeline"`
}
// Shared is a run whose result a step took or waits on, asked once for every step that reads it (design 47 G §729, A-469t): for a composition step one per machine composed, `run` the `composition-runs` key and `ask` its run ask's id; for a test step one with no machine, `run` the `test-runs` key, `ask` its build seat ask's id and `asked-by` the step that asked the run, left out for that step itself.
type Shared struct {
// the id of the run's ask of the build seat
Ask string `json:"ask"`
// the step that asked the run, for a test step reading another's run
AskedBy *SharedAskedBy `json:"asked-by,omitempty"`
// the machine composed, for a composition run
Machine string `json:"machine,omitempty"`
// the run's key: in the assigner's composition-runs, or the runner's test-runs
Run string `json:"run"`
}
// StepEnded is the build step's end, said by the builder on the node it runs on (design 47 G A-97; ADR 0666 section 21): the runner takes it only from that holder's account, naming the ask and each entry's fingerprint it was asked at.
type StepEnded struct {
// for a rerun, the caller the runtime proved
@@ -403,6 +432,26 @@ type AskTakenEvent struct {
Node string `json:"node"`
}
// StepProgressEvent is the body of the event step-progress.
type StepProgressEvent struct {
Ask string `json:"ask"`
Asker string `json:"asker"`
At time.Time `json:"at"`
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
Form int64 `json:"form,omitempty"`
Phase string `json:"phase"`
// the composition runs the step waits on, by machine, each with its ask (design 47 G §723, §729)
Shared []Shared `json:"shared,omitempty"`
}
// The values of StepProgressEvent's phase.
const (
StepProgressEventPhaseFetch = "fetch"
StepProgressEventPhaseBuild = "build"
StepProgressEventPhaseRun = "run"
StepProgressEventPhaseReport = "report"
)
// VersionReservedEvent is the body of the event version-reserved.
type VersionReservedEvent struct {
Artifact string `json:"artifact"`
@@ -489,6 +538,15 @@ func DecodeAskTakenEvent(raw []byte) (AskTakenEvent, int, error) {
return v, formRead(raw), nil
}
// DecodeStepProgressEvent reads a StepProgressEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeStepProgressEvent(raw []byte) (StepProgressEvent, int, error) {
var v StepProgressEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// DecodeVersionReservedEvent reads a VersionReservedEvent as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
func DecodeVersionReservedEvent(raw []byte) (VersionReservedEvent, int, error) {
var v VersionReservedEvent
@@ -31,6 +31,8 @@ func TestFixtures(t *testing.T) {
decode: func(b []byte) (any, error) { var v AskTakenEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.ask-taken\\.[^.*> ]+$")},
{name: "a version reserved at a fingerprint", subject: "mesh.seat.mesh-builds.event.version-reserved", given: "{\"artifact\":\"mesh-sdk:go\",\"fingerprint\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"form\":1,\"module\":\"mesh-sdk\",\"path\":\"git.novox.be/novox/mesh-sdk/go\",\"revision\":\"412\",\"version\":\"0.1.21\"}", wire: "{\"artifact\":\"mesh-sdk:go\",\"fingerprint\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"form\":1,\"module\":\"mesh-sdk\",\"path\":\"git.novox.be/novox/mesh-sdk/go\",\"revision\":\"412\",\"version\":\"0.1.21\"}",
decode: func(b []byte) (any, error) { var v VersionReservedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.version-reserved$")},
{name: "a build step's progress while its build waits for a package", subject: "mesh.seat.mesh-builds.event.step-progress.anchor", given: "{\"ask\":\"a1b2\",\"asker\":\"mesh-delivery-pipeline\",\"at\":\"2026-11-23T02:40:00Z\",\"phase\":\"build\"}", wire: "{\"ask\":\"a1b2\",\"asker\":\"mesh-delivery-pipeline\",\"at\":\"2026-11-23T02:40:00Z\",\"phase\":\"build\"}",
decode: func(b []byte) (any, error) { var v StepProgressEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.step-progress\\.[^.*> ]+$")},
{name: "reserved asks a module", subject: "", given: "{\"module\":\"mesh-sdk\"}", wire: "{\"module\":\"mesh-sdk\"}",
decode: func(b []byte) (any, error) { var v ReservedInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
{name: "reserved asks a package by its name", subject: "", given: "{\"name\":\"git.novox.be/novox/mesh-sdk/go\",\"version\":\"0.1.15\"}", wire: "{\"name\":\"git.novox.be/novox/mesh-sdk/go\",\"version\":\"0.1.15\"}",
@@ -140,5 +140,16 @@
"revision": "412",
"form": 1
}
},
{
"name": "a build step's progress while its build waits for a package",
"of": "event:step-progress",
"subject": "mesh.seat.mesh-builds.event.step-progress.anchor",
"given": {
"asker": "mesh-delivery-pipeline",
"ask": "a1b2",
"phase": "build",
"at": "2026-11-23T02:40:00Z"
}
}
]
@@ -373,6 +373,48 @@
"description": "the seat's holder took the ask from the seat's work queue, at the pull: only the holder says it; the runner arms the ask's bound from it (design 47 H2 §777, §778)"
}
},
{
"name": "step-progress",
"subject": "step-progress.<node>",
"body": {
"type": "object",
"description": "a build step's progress, said once a minute while the seat's holder builds it or its build waits for a package, so the asker's bound of the ask is armed again (design 47 H2 H-A-514 addendum)",
"properties": {
"asker": {
"type": "string"
},
"ask": {
"type": "string"
},
"phase": {
"type": "string",
"enum": [
"fetch",
"build",
"run",
"report"
]
},
"at": {
"type": "string",
"format": "date-time"
},
"shared": {
"type": "array",
"items": {
"$ref": "#/defs/Shared"
},
"description": "the composition runs the step waits on, by machine, each with its ask (design 47 G §723, §729)"
}
},
"required": [
"asker",
"ask",
"phase",
"at"
]
}
},
{
"name": "version-reserved",
"body": {
@@ -703,6 +745,46 @@
"module",
"fingerprint"
]
},
"Shared": {
"type": "object",
"description": "a run whose result a step took or waits on, asked once for every step that reads it (design 47 G §729, A-469t): for a composition step one per machine composed, `run` the `composition-runs` key and `ask` its run ask's id; for a test step one with no machine, `run` the `test-runs` key, `ask` its build seat ask's id and `asked-by` the step that asked the run, left out for that step itself",
"properties": {
"machine": {
"type": "string",
"description": "the machine composed, for a composition run"
},
"run": {
"type": "string",
"description": "the run's key: in the assigner's composition-runs, or the runner's test-runs"
},
"ask": {
"type": "string",
"description": "the id of the run's ask of the build seat"
},
"asked-by": {
"type": "object",
"description": "the step that asked the run, for a test step reading another's run",
"properties": {
"pipeline": {
"type": "string",
"description": "its pipeline's key"
},
"artifact": {
"type": "string",
"description": "its artifact, <module>:<artifact>"
}
},
"required": [
"pipeline",
"artifact"
]
}
},
"required": [
"run",
"ask"
]
}
},
"form": 2
@@ -20,6 +20,7 @@ export declare const events: {
readonly toolchainAgreed: "toolchain-agreed";
readonly stepEnded: "step-ended";
readonly askTaken: "ask-taken";
readonly stepProgress: "step-progress";
readonly versionReserved: "version-reserved";
};
@@ -43,6 +44,10 @@ export declare function askTakenSubject(ask: string): string;
export declare const askTakenSubjectAll: "mesh.seat.mesh-builds.event.ask-taken.*";
export declare function stepProgressSubject(node: string): string;
export declare const stepProgressSubjectAll: "mesh.seat.mesh-builds.event.step-progress.*";
export declare const versionReservedSubject: "mesh.seat.mesh-builds.event.version-reserved";
export declare const stepSubject: "mesh.seat.mesh-builds.accept.step";
@@ -91,6 +96,26 @@ export interface PackagePublished {
"version": string;
}
/** the step that asked the run, for a test step reading another's run */
export interface SharedAskedBy {
/** its artifact, <module>:<artifact> */
"artifact": string;
/** its pipeline's key */
"pipeline": string;
}
/** a run whose result a step took or waits on, asked once for every step that reads it (design 47 G §729, A-469t): for a composition step one per machine composed, `run` the `composition-runs` key and `ask` its run ask's id; for a test step one with no machine, `run` the `test-runs` key, `ask` its build seat ask's id and `asked-by` the step that asked the run, left out for that step itself */
export interface Shared {
/** the id of the run's ask of the build seat */
"ask": string;
/** the step that asked the run, for a test step reading another's run */
"asked-by"?: SharedAskedBy;
/** the machine composed, for a composition run */
"machine"?: string;
/** the run's key: in the assigner's composition-runs, or the runner's test-runs */
"run": string;
}
/** the build step's end, said by the builder on the node it runs on (design 47 G A-97; ADR 0666 section 21): the runner takes it only from that holder's account, naming the ask and each entry's fingerprint it was asked at */
export interface StepEnded {
/** for a rerun, the caller the runtime proved */
@@ -309,6 +334,18 @@ export interface AskTakenEvent {
"node": string;
}
/** is the body of the event step-progress. */
export interface StepProgressEvent {
"ask": string;
"asker": string;
"at": string;
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
"form"?: number;
"phase": "fetch" | "build" | "run" | "report";
/** the composition runs the step waits on, by machine, each with its ask (design 47 G §723, §729) */
"shared"?: Shared[];
}
/** is the body of the event version-reserved. */
export interface VersionReservedEvent {
"artifact": string;
@@ -20,6 +20,7 @@ export const events = {
toolchainAgreed: "toolchain-agreed",
stepEnded: "step-ended",
askTaken: "ask-taken",
stepProgress: "step-progress",
versionReserved: "version-reserved",
};
@@ -47,6 +48,12 @@ export function askTakenSubject(ask) {
export const askTakenSubjectAll = "mesh.seat.mesh-builds.event.ask-taken.*";
export function stepProgressSubject(node) {
return "mesh.seat.mesh-builds.event.step-progress." + node;
}
export const stepProgressSubjectAll = "mesh.seat.mesh-builds.event.step-progress.*";
export const versionReservedSubject = "mesh.seat.mesh-builds.event.version-reserved";
export const stepSubject = "mesh.seat.mesh-builds.accept.step";
@@ -11,6 +11,7 @@ import (
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
wants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
"mesh-delivery-pipeline/internal/pipeline"
@@ -91,19 +92,29 @@ func progressed(c *pipeline.AskClock, onSeat, ask string, logf func(string, ...a
}
}
// hearWantsProgress takes a step progress of the seat mesh-wants as its holder's word on the ask it names: the ask's bound
// is armed again from now (H-A-395).
// hearWantsProgress takes a step progress of the seat mesh-wants, and of the seat mesh-builds (design 47 H2 H-A-514
// addendum), as its holder's word on the ask it names: the ask's bound on that seat is armed again from now (H-A-395).
func hearWantsProgress(hub handlers, c *pipeline.AskClock, logf func(string, ...any)) error {
return hub.Handle(wants.SubjectStepProgressAll, func(m jetstream.Msg) {
var ev wants.StepProgressEvent
for _, on := range []struct{ seat, subject string }{{wants.Seat, wants.SubjectStepProgressAll}, {meshbuilds.Seat, meshbuilds.SubjectStepProgressAll}} {
if err := hub.Handle(on.subject, progressOn(on.seat, c, logf)); err != nil {
return err
}
}
return nil
}
// progressOn is the handler of one seat's step-progress: the ask it names, its bound on onSeat armed again from now.
func progressOn(onSeat string, c *pipeline.AskClock, logf func(string, ...any)) func(jetstream.Msg) {
return func(m jetstream.Msg) {
var ev wants.StepProgressEvent // mesh-builds' step-progress carries the fields of mesh-wants'
if err := json.Unmarshal(m.Data(), &ev); err != nil || ev.Ask == "" {
logf("%s is no step-progress: %v", m.Subject(), err)
_ = m.Term()
return
}
progressed(c, wants.Seat, ev.Ask, logf)
progressed(c, onSeat, ev.Ask, logf)
_ = m.Ack()
})
}
}
// askBoundExpired takes the expiry of an ask's bound (§778): it ends its step.
@@ -2,6 +2,7 @@ package main
import (
"context"
"maps"
"slices"
"testing"
"time"
@@ -10,6 +11,7 @@ import (
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
"mesh-delivery-pipeline/internal/pipeline"
)
@@ -83,4 +85,24 @@ func TestMissedBoundsAtTheStart(t *testing.T) {
if want := []string{key("wordaaaa000005") + " 1m0s", key("goneaaaa000008") + " 1s"}; !slices.Equal(rearmed, want) {
t.Errorf("armed again at the start %v, want %v", rearmed, want)
}
// Design 47 H2 H-A-514 addendum: the seat mesh-builds' step-progress arms its ask's bound again from now, as mesh-wants' does.
progress := map[string]func(jetstream.Msg){}
if err := hearWantsProgress(handlerMap(progress), c, t.Logf); err != nil {
t.Fatal(err)
}
hear, ok := progress[meshbuilds.SubjectStepProgressAll]
if !ok {
t.Fatalf("step-progress is heard on %v, want the seat mesh-builds' too", slices.Sorted(maps.Keys(progress)))
}
rearmed = nil
hear(dataMsg{data: []byte(`{"ask":"buildaaa000009","asker":"main.1.m","phase":"build","at":"2026-11-23T02:41:00Z"}`), acks: new([]string)})
if want := []string{pipeline.AskBoundKey(meshbuilds.Seat, "buildaaa000009") + " 10m0s"}; !slices.Equal(rearmed, want) {
t.Errorf("a mesh-builds step-progress armed %v, want %v", rearmed, want)
}
}
// handlerMap is a hub that keeps each handler by its pattern.
type handlerMap map[string]func(jetstream.Msg)
func (h handlerMap) Handle(pattern string, f func(jetstream.Msg)) error { h[pattern] = f; return nil }
@@ -96,7 +96,9 @@ func TestManifest(t *testing.T) {
// design 47 H2 §777, §778: the bound of an ask on mesh-builds and mesh-wants counts from its holder's pull.
"mesh-builds.ask-taken", "mesh-wants.ask-taken", "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-wants.step-progress", "node-engine.running", "mesh-catalog.registration-changed",
"node-build-go.step-progress", "node-build-node.step-progress", "node-build-image.step-progress", "mesh-wants.step-ended", "mesh-wants.step-progress",
// H-A-514 addendum: the seat mesh-builds says step-progress of a build step that builds or waits for a package.
"mesh-builds.step-progress", "node-engine.running", "mesh-catalog.registration-changed",
"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",
@@ -68,6 +68,7 @@
"node-build-image.step-progress",
"mesh-wants.step-ended",
"mesh-wants.step-progress",
"mesh-builds.step-progress",
"mesh-wants.ask-taken",
"node-engine.running",
"mesh-catalog.registration-changed",