I13b: the versions fill, the event versions-filled and the builder's fill wait go

The indexer's first fill of the versions from builder_versions was the only
part that said versions-filled, and the numbering it served is gone. So the
fill, its edges and its call go from the indexer, the event leaves the seat
mesh-catalog's definition, its fixture and the generated contracts (the
seat's form rises to 6), and the builder neither hears it nor waits on it:
it reserves from its own reservations alone.

Builds: design 47 H2 H-A-552, H-A-532 (DQ-9, DMC-5), H §756, G §372
This commit is contained in:
2026-11-23 12:26:20 +01:00
parent d0de4a7497
commit f474987827
40 changed files with 85 additions and 972 deletions
@@ -1,87 +0,0 @@
package main
import (
"context"
"errors"
"sync/atomic"
"time"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/process"
)
// lastKept reads whether the stream keeps a message on a subject: found false when the stream or the message is not there.
type lastKept func(ctx context.Context, subject string) (found bool, err error)
// lastKeptOf reads the seat event's own kept stream (the contract's StreamVersionsFilled, kept by age) the way any kept event
// is heard (design 47 G A-411, A-233): the SDK's hearing of it from its first message, whose start read hands every message
// kept to the handler; the reading is stopped once the read ended, the hub's own hearing following the durable. Nothing of
// EVENTS is read.
func lastKeptOf(js jetstream.JetStream, acct process.Account, logf func(string, ...any)) lastKept {
return func(ctx context.Context, subject string) (bool, error) {
var found atomic.Bool
cc, err := acct.HearSeatEvents(ctx, js, meshcatalog.StreamVersionsFilled, func(m jetstream.Msg) {
if m.Subject() == subject {
found.Store(true)
}
_ = m.Ack() // a message of the durable is taken as the hub takes it; an ordered read's has nothing to acknowledge
}, logf, process.FromFirst())
if err != nil {
if errors.Is(err, jetstream.ErrStreamNotFound) {
return false, nil
}
return false, err
}
cc.Stop()
return found.Load(), nil
}
}
// readFilled reads at the builder's start the last versions-filled the stream keeps (design 47 G §369, §372, A-411) and takes it as heard; the event heard later sets it as before. Nothing found leaves it unset, said; a
// read that failed is said and tried again in the background with backoff, never holding the start.
func (rv *reservations) readFilled(ctx context.Context, read lastKept, wait func(context.Context, time.Duration) bool) {
const first, most = time.Second, time.Minute
try := func() (done bool, err error) {
found, err := read(ctx, meshcatalog.SubjectVersionsFilled)
if err != nil {
return false, err
}
if !found {
rv.logf("the stream keeps no versions-filled yet (read at start): versions are reserved once the catalog says it")
return true, nil
}
rv.filled.Store(true)
rv.logf("the catalog said versions-filled (read at start): versions are reserved from now on")
if rv.wake != nil {
rv.wake(ctx)
}
return true, nil
}
if done, err := try(); done {
return
} else {
rv.logf("the last versions-filled is not read at start: %v; read again in the background", err)
}
go func() {
for d := first; ; d = min(d*2, most) {
if !wait(ctx, d) {
return
}
done, err := try()
if done {
return
}
rv.logf("the last versions-filled is not read: %v; read again in %s", err, min(d*2, most))
}
}()
}
// sleeps waits d, as a context's bound (ADR 0437 §8: the builder holds no timer); false when ctx ended first.
func sleeps(ctx context.Context, d time.Duration) bool {
bound, cancel := context.WithTimeout(ctx, d)
defer cancel()
<-bound.Done()
return ctx.Err() == nil
}
@@ -1,64 +0,0 @@
package main
import (
"context"
"errors"
"reflect"
"sync"
"testing"
"time"
)
func TestTheLastVersionsFilledIsReadAtStart(t *testing.T) {
boom := errors.New("bus down")
for _, tc := range []struct {
name string
results []error // per read: nil found, boom fails
notFound bool
wantFilled bool
wantReads int
waits []time.Duration
}{
{"kept", []error{nil}, false, true, 1, nil},
{"none kept", []error{nil}, true, false, 1, nil},
{"read fails then kept", []error{boom, boom, nil}, false, true, 3, []time.Duration{time.Second, 2 * time.Second}},
} {
t.Run(tc.name, func(t *testing.T) {
rv := newReservations(nil, nil, nil, nil, nil, t.Logf)
var mu sync.Mutex
woke := make(chan struct{}, 1)
rv.wake = func(context.Context) { woke <- struct{}{} }
reads := 0
read := func(_ context.Context, subject string) (bool, error) {
mu.Lock()
defer mu.Unlock()
err := tc.results[reads]
reads++
return !tc.notFound, err
}
var waits []time.Duration
wait := func(_ context.Context, d time.Duration) bool {
mu.Lock()
defer mu.Unlock()
waits = append(waits, d)
return true
}
rv.readFilled(context.Background(), read, wait)
if tc.wantFilled {
select {
case <-woke:
case <-time.After(5 * time.Second):
t.Fatal("the read did not take the fill")
}
}
mu.Lock()
defer mu.Unlock()
if rv.Filled() != tc.wantFilled || reads != tc.wantReads {
t.Fatalf("filled %v reads %d", rv.Filled(), reads)
}
if !reflect.DeepEqual(waits, tc.waits) {
t.Fatalf("backoff %v, want %v", waits, tc.waits)
}
})
}
}
@@ -14,8 +14,6 @@ import (
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
sweep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshartifactsweep"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/process"
)
// A done key whose blob the artifact store no longer holds is built again, by the builder whole against the bus
@@ -194,31 +192,3 @@ func artifactsGoneLeadsTheBuilderToBuildTheKeyAgain(t *testing.T) {
b.fake.count("mesh-build-go.build_go_build"))
}
}
// The last versions-filled is read at the start from the seat event's own kept stream, kept by age, through the SDK's hearing
// from the first message (design 47 G A-411), never from EVENTS: a message the stream keeps is found, an empty one is none.
func TestTheLastVersionsFilledIsReadFromItsKeptStream(t *testing.T) {
b := startBed(t)
acct := process.Account{Node: "n1", Module: "mesh-delivery-builder"}
if err := b.js.DeleteStream(b.ctx, eventsStream); err != nil { // the bus keeps a kept event off EVENTS: its subject is nowhere else
t.Fatal(err)
}
if _, err := b.js.CreateOrUpdateStream(b.ctx, jetstream.StreamConfig{Name: meshcatalog.StreamVersionsFilled,
Subjects: []string{meshcatalog.SubjectVersionsFilled}, MaxAge: 24 * time.Hour}); err != nil {
t.Fatal(err)
}
if _, err := b.js.CreateOrUpdateConsumer(b.ctx, meshcatalog.StreamVersionsFilled, jetstream.ConsumerConfig{
Durable: acct.EventConsumerName(), AckPolicy: jetstream.AckExplicitPolicy, FilterSubject: meshcatalog.SubjectVersionsFilled}); err != nil {
t.Fatal(err)
}
read := lastKeptOf(b.js, acct, t.Logf)
if found, err := read(b.ctx, meshcatalog.SubjectVersionsFilled); err != nil || found {
t.Fatalf("empty stream: found %v, %v", found, err)
}
if _, err := b.js.Publish(b.ctx, meshcatalog.SubjectVersionsFilled, []byte(`{"v":1}`)); err != nil {
t.Fatal(err)
}
if found, err := read(b.ctx, meshcatalog.SubjectVersionsFilled); err != nil || !found {
t.Fatalf("kept message: found %v, %v", found, err)
}
}
@@ -231,10 +231,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
waitsBucket.Ready(func(kv jetstream.KeyValue) { b.Waits.(*waitsKept).start(ctx, kv) })
// The plans no seat builds (design 47 H2 §795, H-A-425): kept in the state unbuildable, read by builder_unbuildable.
b.Unbuildables = unbuildableKept{b: process.AwaitBucket(ctx, js, conn, builds.StateBucket(cred.Module, build.UnbuildableState), "the plans no seat builds are said, and builder_unbuildable lists none", logger.Printf)}
// The versions a build reserves at its start (design 47 G §369): its state reserved, and the catalog's versions-filled
// and version-released heard; nothing is reserved before the fill.
// The versions a build reserves at its start (design 47 G §369): its state reserved, and the catalog's version-released
// heard (design 47 H2 H-A-552: no fill is waited for).
reservedKV := process.AwaitBucket(ctx, js, conn, own.reserved, "no version is reserved: builds are made unreserved", logger.Printf)
reserved := newReservations(awaitedReserved{awaitedState{b: reservedKV, bucket: own.reserved}}, calls.Call, pubBoundsKV.KV, found, b.Reconsider, logger.Printf)
reserved := newReservations(awaitedReserved{awaitedState{b: reservedKV, bucket: own.reserved}}, calls.Call, pubBoundsKV.KV, found, logger.Printf)
// The index by digest and by version beside the reservations is written again once the state is bound (H-A-269 (1), H-A-271).
reservedKV.Ready(func(jetstream.KeyValue) { reserved.reindex(ctx) })
// Each artifact the holder says published at a reserved version is said as the seat mesh-builds' package-published (design 47 G §52).
@@ -248,8 +248,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
// A take-over of a series' reservation by another fingerprint withdraws the older build (H-A-225).
reserved.withdraw = b.Withdraw
reserved.recordAgain = b.RecordAgain // a done build's digests its end did not record are recorded at the start (H-A-492)
// The last versions-filled the stream keeps is read at the start (design 47 G §369, §372): a restart does not lose it.
reserved.readFilled(ctx, lastKeptOf(js, cred, logger.Printf), sleeps)
// The versions' hand acts (builder_publish_again, builder_reserved_drop) come through reasks, as builder_build_again.
acts := versions.Acts{DropReserved: reserved.dropped}
// A reserved version left unpublished is published again, by the builder on an event or by a person's tool (design 47 G
@@ -558,8 +556,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
if err := hub.Start(ctx, js, cred); err != nil {
return err
}
// And the kept seat events it handles (the build seats' toolchain-reported, the seat mesh-catalog's versions-filled
// and version-released), each on its own stream: the tool runner reads its own twin there (lead answer A-397).
// And the kept seat events it handles (the build seats' toolchain-reported, the seat mesh-catalog's
// version-released), each on its own stream: the tool runner reads its own twin there (lead answer A-397).
hub.StartKept(ctx, js, cred)
return nil
})
@@ -9,7 +9,7 @@ const namedTreePrefix = "named:"
// seatEventPatterns are the seats' events the builder's own handler takes off its durable consumer (its manifest's `consumes` of
// them): the registry seats' words, artifacts-gone, the build seats' toolchain-reported, the node-engine
// seat's events, of the seat mesh-catalog, version-released and versions-filled. The seat mesh-catalog's
// seat's events, of the seat mesh-catalog, version-released. The seat mesh-catalog's
// catalog-revision and registration-changed and the seat mesh-delivery's source-moved are the views reader's (the branch
// follower's), so no pattern here covers them: a message has one taker.
var seatEventPatterns = func() []string {
@@ -18,7 +18,7 @@ var seatEventPatterns = func() []string {
"mesh-artifact-sweep", "mesh-conditions", "node-engine", "node-build-go", "node-build-image", "node-build-node"} {
out = append(out, "mesh.seat."+seat+".event.>")
}
for _, event := range []string{meshcatalog.EventVersionReleased, meshcatalog.EventVersionsFilled} {
for _, event := range []string{meshcatalog.EventVersionReleased} {
out = append(out, "mesh.seat."+meshcatalog.Seat+".event."+event, "mesh.seat."+meshcatalog.Seat+".event."+event+".>")
}
return out
@@ -300,8 +300,7 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
}
found := &memFindings{vals: map[string][]byte{}}
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} },
&findings{module: builds.BuilderModule, w: found, logf: t.Logf, now: time.Now}, nil, t.Logf)
rv.filled.Store(true)
&findings{module: builds.BuilderModule, w: found, logf: t.Logf, now: time.Now}, t.Logf)
type oldItem struct {
key string
raw []byte
@@ -284,8 +284,7 @@ func TestThePublishItemsAreWiredToTheReservationsAndTheReAskWatch(t *testing.T)
call := func(string, any) (json.RawMessage, error) {
return json.Marshal(meshcatalog.VersionsAnswer{Module: "m"})
}
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} }, found, nil, t.Logf)
rv.filled.Store(true)
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} }, found, t.Logf)
tried := make(chan string, 4)
items := &publishItems{reasks: func() jetstream.KeyValue { return kv }, set: defaultPublishSettings, now: time.Now, logf: t.Logf,
reserved: func(ctx context.Context, m, v string) (versions.ReservedVersion, bool, error) {
@@ -267,9 +267,8 @@ func aSeatsOutcomeIsHeard(t *testing.T) {
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, func(string, any) (json.RawMessage, error) {
return json.Marshal(meshcatalog.VersionsAnswer{Module: "m"})
}, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} },
&findings{module: builds.BuilderModule, w: &memFindings{vals: map[string][]byte{}}, logf: t.Logf, now: time.Now}, nil, t.Logf)
&findings{module: builds.BuilderModule, w: &memFindings{vals: map[string][]byte{}}, logf: t.Logf, now: time.Now}, t.Logf)
rv.say = func(_ context.Context, p meshbuilds.PackagePublished) error { saidPub = append(saidPub, p); return nil }
rv.filled.Store(true)
res, err := rv.Reserve(context.Background(), "m", "0.1", []string{"m:program"}, versions.Source{})
if err != nil {
t.Fatal(err)
@@ -8,7 +8,6 @@ import (
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
"slices"
"strings"
"sync/atomic"
"time"
"github.com/nats-io/nats.go/jetstream"
@@ -22,7 +21,7 @@ import (
)
// The reservations (design 47 G §369): the builder's state reserved, the catalog's versions it numbers from, and the
// catalog's version-released and versions-filled it hears.
// catalog's version-released it hears.
// awaitedReserved is the state reserved as versions.ReserveStore: bound once the bus holds it.
type awaitedReserved struct{ awaitedState }
@@ -48,11 +47,9 @@ type reservations struct {
// ended ends the publish item of a build withdrawn, superseded or dropped, its held items terminated; heard acknowledges the
// held items of a version a published newly marked (design 47 H2 §793). Nil are none.
itemEnded, itemHeard func(ctx context.Context, module, version string)
filled atomic.Bool
bounds func() jetstream.KeyValue
found *findings
bound time.Duration
wake func(context.Context)
logf func(string, ...any)
// withdraw ends the running build of a module's fingerprint, superseded, with why (H-A-225); nil ends none.
withdraw func(module, fingerprint, why string)
@@ -116,9 +113,9 @@ func sayReservedOn(js jetstream.JetStream, cred process.Account) func(context.Co
// newReservations makes the reserving over store; the released versions of a module are asked of the seat mesh-catalog's
// verb versions through call (design 47 G §348), the only source numbering reads them from.
func newReservations(store versions.ReserveStore, call toolCaller, bounds func() jetstream.KeyValue, found *findings, wake func(context.Context), logf func(string, ...any)) *reservations {
rv := &reservations{bounds: bounds, found: found, bound: versions.UnreleasedBound, wake: wake, logf: logf}
rv.r = &versions.Reserver{Store: store, Filled: rv.filled.Load, ReleasedOf: func(_ context.Context, module string) ([]string, error) {
func newReservations(store versions.ReserveStore, call toolCaller, bounds func() jetstream.KeyValue, found *findings, logf func(string, ...any)) *reservations {
rv := &reservations{bounds: bounds, found: found, bound: versions.UnreleasedBound, logf: logf}
rv.r = &versions.Reserver{Store: store, ReleasedOf: func(_ context.Context, module string) ([]string, error) {
raw, err := call("seat:"+meshcatalog.Seat+".versions", meshcatalog.VersionsInput{Module: module})
if err != nil {
return nil, err
@@ -194,8 +191,6 @@ func (rv *reservations) VersionAt(ctx context.Context, module, artifact, branch
return rv.r.VersionAt(ctx, module, artifact, branch, source)
}
func (rv *reservations) Filled() bool { return rv.filled.Load() }
func (rv *reservations) Reserve(ctx context.Context, module, series string, artifacts []string, src versions.Source) (versions.ReservedVersion, error) {
return rv.r.Reserve(ctx, module, series, artifacts, src)
}
@@ -297,16 +292,10 @@ func (rv *reservations) dropBound(ctx context.Context, key string) {
}
}
// heard takes the catalog's version-released and versions-filled in, and a registry seat's published (published): a
// heard takes the catalog's version-released in, and a registry seat's published (published): a
// message that is none of them is left to the others. A state that cannot take one leaves it for the bus to give again.
func (rv *reservations) heard(ctx context.Context, m jetstream.Msg) bool {
switch m.Subject() {
case meshcatalog.SubjectVersionsFilled:
rv.filled.Store(true)
rv.logf("the catalog said versions-filled: versions are reserved from now on")
if rv.wake != nil {
rv.wake(ctx)
}
case meshcatalog.SubjectVersionReleased:
var ev meshcatalog.VersionReleasedEvent
if err := json.Unmarshal(m.Data(), &ev); err != nil || ev.Module == "" || ev.Version == "" {
@@ -79,33 +79,23 @@ func (b *boundsKV) Delete(_ context.Context, key string, _ ...jetstream.KVDelete
return nil
}
// TestTheCatalogsWordsMoveTheReservations: design 47 G §369, §372 (test 102) — versions-filled opens the reserving and wakes
// the builds that wait; a built reservation arms its bound and its end raises version-unreleased naming the artifacts
// TestTheCatalogsWordsMoveTheReservations: design 47 G §369 (test 102) — a built reservation arms its bound and its end raises version-unreleased naming the artifacts
// missing; the catalog's version-released deletes the key and the bound and clears the finding; builder_reserved_drop drops one.
func TestTheCatalogsWordsMoveTheReservations(t *testing.T) {
ctx := context.Background()
st := &memFindings{vals: map[string][]byte{}}
found := &findings{module: builds.BuilderModule, w: st, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }}
bounds := &boundsKV{keys: map[string]bool{}}
woke := 0
call := func(addr string, body any) (json.RawMessage, error) {
if addr != "seat:mesh-catalog.versions" {
t.Errorf("the released versions were asked of %q", addr)
}
return json.Marshal(meshcatalog.VersionsAnswer{Module: "m", Versions: []meshcatalog.VersionEntry{{Module: "m", Version: "1.4.2"}}})
}
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return bounds }, found,
func(context.Context) { woke++ }, t.Logf)
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return bounds }, found, t.Logf)
var items []string // design 47 G A-457a: the end of a build asks its publish, the release ends it
rv.built = func(_ context.Context, m, v string) error { items = append(items, "asked "+m+" "+v); return nil }
rv.released = func(_ context.Context, m, v string) { items = append(items, "ended "+m+" "+v) }
if _, err := rv.Reserve(ctx, "m", "1.4", []string{"m:a"}, versions.Source{}); err == nil || rv.Filled() {
t.Fatalf("a version was reserved before versions-filled (%v)", err)
}
filled := &wakeMsg{subject: meshcatalog.SubjectVersionsFilled, data: []byte(`{"v":1}`)}
if !rv.heard(ctx, filled) || !filled.acked || !rv.Filled() || woke != 1 {
t.Fatalf("versions-filled: acked %v, filled %v, woke %d", filled.acked, rv.Filled(), woke)
}
var said []meshbuilds.PackagePublished
rv.say = func(_ context.Context, p meshbuilds.PackagePublished) error { said = append(said, p); return nil }
res, err := rv.Reserve(ctx, "m", "1.4", []string{"m:a", "m:b"}, versions.Source{Branch: "main", Revision: 41})
@@ -181,8 +171,7 @@ func TestAReleasedVersionWritesNoTag(t *testing.T) {
fw := &memFindings{vals: map[string][]byte{}}
found := &findings{module: builds.BuilderModule, w: fw, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }}
store := &memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}
rv := newReservations(store, call, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} }, found, nil, t.Logf)
rv.filled.Store(true)
rv := newReservations(store, call, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} }, found, t.Logf)
rv.names = func(_ context.Context, _, artifact string) (string, bool, error) {
return "git.example/o/r/go", artifact == "lib", nil
}
@@ -321,10 +310,9 @@ func TestAPublishedHeardBeforeTheDigestsIsSaidWhenTheBuildRecordsThem(t *testing
return json.Marshal(meshcatalog.VersionsAnswer{Module: "m"})
}
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, none, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} },
&findings{module: builds.BuilderModule, w: fs, logf: t.Logf, now: time.Now}, nil, logf)
&findings{module: builds.BuilderModule, w: fs, logf: t.Logf, now: time.Now}, logf)
var said []meshbuilds.PackagePublished
rv.say = func(_ context.Context, p meshbuilds.PackagePublished) error { said = append(said, p); return nil }
rv.filled.Store(true)
res, err := rv.Reserve(ctx, "m", "1.4", []string{"m:a", "m:b"}, versions.Source{Branch: "main", Revision: 41})
if err != nil {
t.Fatal(err)
@@ -370,9 +358,7 @@ func TestABuildTakingOverAnOlderReservationDropsItsBoundAndSaysSo(t *testing.T)
call := func(string, any) (json.RawMessage, error) {
return json.Marshal(meshcatalog.VersionsAnswer{Module: "m"})
}
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return bounds }, found,
nil, func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) })
rv.filled.Store(true)
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return bounds }, found, func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) })
var withdrawn []string
rv.withdraw = func(module, fp, why string) { withdrawn = append(withdrawn, module+" "+fp+": "+why) }
older, err := rv.Reserve(ctx, "m", "0.1", []string{"m:a"}, versions.Source{Fingerprint: "fp-old"})
@@ -499,7 +485,7 @@ func TestARegistrysRecordEndsOrMovesAPublish(t *testing.T) {
}
bounds := &boundsKV{keys: map[string]bool{}}
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, none, func() jetstream.KeyValue { return bounds },
&findings{module: builds.BuilderModule, w: fs, logf: t.Logf, now: time.Now}, nil, t.Logf)
&findings{module: builds.BuilderModule, w: fs, logf: t.Logf, now: time.Now}, t.Logf)
var said []meshbuilds.PackagePublished
rv.say = func(_ context.Context, p meshbuilds.PackagePublished) error { said = append(said, p); return nil }
var asked, ended []string
@@ -508,7 +494,6 @@ func TestARegistrysRecordEndsOrMovesAPublish(t *testing.T) {
rv.itemEnded = rv.released // a build withdrawn or superseded ends its publish item too (§793)
registry := []string{"0.1.37"}
rv.r.HeldNumbers = func(context.Context, string, string, []string) ([]string, error) { return registry, nil }
rv.filled.Store(true)
res, err := rv.Reserve(ctx, "node-tools", "0.1", []string{"node-tools:program"}, versions.Source{Fingerprint: "fp1"})
if err != nil || res.Version != "0.1.0" {
t.Fatalf("reserved %q (%v)", res.Version, err)
@@ -594,9 +579,8 @@ func TestAPublishedThatMarksNothingIsSaidFromWhatItRead(t *testing.T) {
none := func(string, any) (json.RawMessage, error) { return json.Marshal(meshcatalog.VersionsAnswer{}) }
var logs []string
rv := newReservations(store, none, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} },
&findings{module: builds.BuilderModule, w: &memFindings{vals: map[string][]byte{}}, logf: t.Logf, now: time.Now}, nil,
&findings{module: builds.BuilderModule, w: &memFindings{vals: map[string][]byte{}}, logf: t.Logf, now: time.Now},
func(f string, a ...any) { logs = append(logs, fmt.Sprintf(f, a...)) })
rv.filled.Store(true)
for i := range 14 {
m := fmt.Sprintf("m%02d", i)
res, err := rv.Reserve(ctx, m, "0.1", []string{m + ":a"}, versions.Source{Fingerprint: "fp" + m})
@@ -113,8 +113,6 @@ func (b *Builder) PackageNamed(ctx context.Context, module string) {
// Reservations reserves the version of a trunk build at its start and records each artifact's digest (design 47 G §369).
// Nil reserves nothing.
type Reservations interface {
// Filled says the catalog said versions-filled: nothing is reserved before it.
Filled() bool
// Reserve reserves module's next version in series for the artifacts (their references, <module>:<artifact>).
Reserve(ctx context.Context, module, series string, artifacts []string, src versions.Source) (versions.ReservedVersion, error)
// Built records the digests of the artifacts built under the reserved version, by reference, and what each resolved and was
@@ -151,23 +149,6 @@ func (b *Builder) reservesVersion(plan Plan) bool {
return len(plan.Tasks) > 0 && strings.Count(plan.Series, ".") == 1
}
// waitFill holds a build that would reserve until the catalog says versions-filled, saying wait-held naming the fill once
// (design 47 G §369, §372). It answers whether the build waits.
func (b *Builder) waitFill(module string, m meshcatalog.ModulesByModuleValue) bool {
if b.Reserved.Filled() {
return false
}
if _, said := b.fillWaits.LoadOrStore(module+"."+m.Fp2, true); !said {
line := module + " at " + m.Fp2 + " is not built yet: wait-held, the catalog has not said versions-filled, and nothing is reserved before it"
b.logf("%s", line)
if b.Log != nil {
b.Log(builds.BuildLogEntry{Event: builds.BuildSaidEvent, Module: module, FP: m.Fp2, Commit: m.Commit, Node: b.Node,
At: time.Now().UTC(), Line: line, Why: "wait-held"})
}
}
return true
}
// reserve reserves the version of the build that starts; a reservation that cannot be made is said and the build goes on
// unreserved: the caller fails the key, which a look takes again (A-490).
func (b *Builder) reserve(ctx context.Context, module string, m meshcatalog.ModulesByModuleValue, plan Plan, o Origin, rebuild bool) (versions.ReservedVersion, bool) {
@@ -236,9 +217,6 @@ func (b *Builder) ReserveDone(ctx context.Context, module, fp string) (versions.
} else if ok {
return versions.ReservedVersion{}, fmt.Errorf("%s at %s holds the reservation of %s already", module, fp, cur.Version)
}
if !b.Reserved.Filled() {
return versions.ReservedVersion{}, versions.ErrNotFilled
}
res, ok := b.reserve(ctx, module, m, plan, b.originOf(key), false)
if !ok {
return versions.ReservedVersion{}, fmt.Errorf("no version could be reserved for %s at %s (the builder's journal says why)", module, fp)
@@ -23,7 +23,6 @@ import (
// fakeReservations answers a fill and keeps what the builder reserved and recorded.
type fakeReservations struct {
filled bool
released map[string]bool
reserved [][]string
series []string
@@ -65,8 +64,6 @@ func (f *fakeReservations) ReleasedFor(_ context.Context, _, fp string) (bool, e
return f.released[fp], nil
}
func (f *fakeReservations) Filled() bool { return f.filled }
func (f *fakeReservations) ReservedFor(_ context.Context, _, fp string) (versions.ReservedVersion, bool, error) {
if v, ok := f.held[fp]; ok {
return v, true, nil
@@ -105,8 +102,8 @@ func (f *fakeReservations) Built(ctx context.Context, _, version string, digests
return nil
}
// TestABuildReservesItsVersionAtItsStartOnceTheCatalogFilled: design 47 G §369, §372 (test 102) — nothing is reserved before
// versions-filled and the build waits saying wait-held naming the fill; after it the build reserves one version in the
// TestABuildReservesItsVersionAtItsStartOnceTheCatalogFilled: design 47 G §369 (test 102), H2 H-A-552 — the build waits for no
// fill and says no wait-held: it reserves one version in the
// manifest's MAJOR.MINOR for its artifacts and records their digests; a done key reserves nothing again; a manifest whose
// version is no MAJOR.MINOR reserves nothing.
func TestABuildReservesItsVersionAtItsStartOnceTheCatalogFilled(t *testing.T) {
@@ -117,22 +114,6 @@ func TestABuildReservesItsVersionAtItsStartOnceTheCatalogFilled(t *testing.T) {
var said []builds.BuildLogEntry
r.b.Log = func(e builds.BuildLogEntry) { said = append(said, e) }
r.b.Module(context.Background(), "m", moduleValue(t, "modules/m"))
r.b.Wait()
if _, ok := r.st.vals[r.key]; ok || len(res.reserved) != 0 {
t.Fatalf("before versions-filled the build was claimed (%v) or reserved %v", ok, res.reserved)
}
var waits []string
for _, e := range said {
if e.Event == builds.BuildSaidEvent && e.Why == "wait-held" {
waits = append(waits, e.Line)
}
}
if len(waits) != 1 || !slices.ContainsFunc(waits, func(l string) bool { return strings.Contains(l, "versions-filled") }) {
t.Fatalf("wait-held lines = %q, want one naming versions-filled", waits)
}
res.filled = true
// Design 47 G §573: the build's ask carries the reserved version.
var askedVersions []string
r.asks.Answer = func(a buildstep.StepAsk) buildstep.Step {
@@ -146,11 +127,16 @@ func TestABuildReservesItsVersionAtItsStartOnceTheCatalogFilled(t *testing.T) {
if v.State != builds.BuildDone || len(res.reserved) != 1 || !slices.Equal(res.reserved[0], []string{"m:tool"}) || res.series[0] != "0.1" {
t.Fatalf("build %+v reserved %v in %v, want done and one reservation of m:tool in 0.1", v.State, res.reserved, res.series)
}
for _, e := range said {
if e.Event == builds.BuildSaidEvent && e.Why == "wait-held" {
t.Errorf("the build said wait-held %q, want no wait for a fill (H-A-552)", e.Line)
}
}
if res.built["m:tool"] != digest || len(res.built) != 2 {
t.Errorf("recorded %v, want the digest of m:tool under the reserved version", res.built)
}
// H-A-486: an upstream artifact is reserved for the record and named as upstream, so its publish is never awaited.
up := &fakeReservations{filled: true}
up := &fakeReservations{}
plan := Plan{Series: "0.1", Tasks: []Task{{Artifact: "server", Kind: catalogue.ArtifactUpstream}, {Artifact: "tools", Kind: catalogue.ArtifactBundle}}}
if _, ok := (&Builder{Reserved: up}).reserve(context.Background(), "nats", meshcatalog.ModulesByModuleValue{Fp2: "f"}, plan, Origin{}, false); !ok ||
!slices.Equal(up.reserved[0], []string{"nats:server", "nats:tools"}) || !slices.Equal(up.sources[0].Upstream, []string{"nats:server"}) {
@@ -163,7 +149,7 @@ func TestABuildReservesItsVersionAtItsStartOnceTheCatalogFilled(t *testing.T) {
// A manifest whose version is no MAJOR.MINOR reserves nothing and is built as before.
r2 := newRig(t, goBundle)
res2 := &fakeReservations{filled: true}
res2 := &fakeReservations{}
r2.b.Reserved = res2
var unversioned []string
r2.asks.Answer = func(a buildstep.StepAsk) buildstep.Step {
@@ -192,7 +178,7 @@ func TestAVersionsDigestsAreRecordedUnderTheBuildersOwnBound(t *testing.T) {
t.Run("a build's context cancelled at its end still records", func(t *testing.T) {
r := newRig(t, goBundle)
r.mf.byDigest[mdigest('a')] = manifest
res := &fakeReservations{filled: true}
res := &fakeReservations{}
r.b.Reserved = res
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -240,7 +226,7 @@ func TestAVersionsDigestsAreRecordedUnderTheBuildersOwnBound(t *testing.T) {
t.Run("a done key whose digests are not recorded is recorded at the next look", func(t *testing.T) {
r := newRig(t, goBundle)
r.mf.byDigest[mdigest('a')] = manifest
res := &fakeReservations{filled: true, lost: errors.New("context canceled")}
res := &fakeReservations{lost: errors.New("context canceled")}
r.b.Reserved = res
var journal []string
r.b.Logf = func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) }
@@ -309,7 +295,7 @@ func TestOnlyABuildOfTheFirstWatchedBranchReservesAndItCarriesItsCatalogRevision
t.Run(c.name, func(t *testing.T) {
r := newRig(t, goBundle)
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: "0.1", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
res := &fakeReservations{filled: true}
res := &fakeReservations{}
r.b.Reserved = res
r.b.Entry(context.Background(), c.origin, meshcatalog.CatalogEntry{Module: "m", Repository: "novox/mesh-catalog", Path: "modules/m",
Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20", Fp: fp1, ManifestDigest: mdigest('a'), Inputs: &meshcatalog.EntryInputs{Toolchains: CatalogToolchains(agreedToolchains)}})
@@ -330,7 +316,7 @@ func TestOnlyABuildOfTheFirstWatchedBranchReservesAndItCarriesItsCatalogRevision
func TestAReservedBuildKeepsWhatItsStepResolvedAndWasBuiltWith(t *testing.T) {
r := newRig(t, goBundle)
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: "0.1", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
res := &fakeReservations{filled: true}
res := &fakeReservations{}
r.b.Reserved = res
var journal []string
r.b.Logf = func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) }
@@ -378,7 +364,7 @@ func TestAModuleWhoseOnlyArtifactIsAGoPackageIsBuiltUnderItsReservedVersion(t *t
t.Run(c.name, func(t *testing.T) {
r := newRig(t, goPackage)
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: c.series, Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goPackage}}}
res := &fakeReservations{filled: true}
res := &fakeReservations{}
r.b.Reserved = res
r.bm.packages["go-overlay"] = "git.novox.be/novox/mesh-networking/go@v0.1.5" // the Go build module's published reference
var asked []buildstep.StepAsk
@@ -410,7 +396,7 @@ func TestAReservingTrunkBuildNeverEndsDoneWithoutItsVersion(t *testing.T) {
return r
}
t.Run("a reservation that cannot be made fails the key and asks nothing", func(t *testing.T) {
r := setup(t, &fakeReservations{filled: true, fail: errors.New("the catalog's versions cannot be read")})
r := setup(t, &fakeReservations{fail: errors.New("the catalog's versions cannot be read")})
v := r.consider(t, "modules/m")
if v.State != builds.BuildFailed || !strings.Contains(v.Error, "no version is reserved") || len(r.asks.Asks()) != 0 {
t.Fatalf("key %+v with %d asks; want failed saying no version is reserved, nothing asked", v, len(r.asks.Asks()))
@@ -432,7 +418,7 @@ func TestAReservingTrunkBuildNeverEndsDoneWithoutItsVersion(t *testing.T) {
if v := r.consider(t, "modules/m"); v.State != builds.BuildDone {
t.Fatalf("first build = %+v, want done", v)
}
res := &fakeReservations{filled: true, released: map[string]bool{fp1: c.released}}
res := &fakeReservations{released: map[string]bool{fp1: c.released}}
if c.standing {
res.sources, res.next = []versions.Source{{Fingerprint: fp1}}, "0.1.17" // ReservedFor answers a held reservation
}
@@ -466,7 +452,6 @@ type realReserve struct {
reservations map[string][]byte
}
func (r *realReserve) Filled() bool { return true }
func (r *realReserve) ReleasedFor(context.Context, string, string) (bool, error) {
return false, nil
}
@@ -511,7 +496,7 @@ func TestABuildAgainKeepsItsOwnStandingNumber(t *testing.T) {
t.Fatalf("first build = %+v, want done", v)
}
store := reserveMap{newMem()}
real := &realReserve{Reserver: &versions.Reserver{Store: store, Filled: func() bool { return true },
real := &realReserve{Reserver: &versions.Reserver{Store: store,
ReleasedOf: func(context.Context, string) ([]string, error) { return []string{"0.1.16"}, nil }}}
raw, _ := json.Marshal(versions.ReservedVersion{V: 1, Module: "m", Series: "0.1", Version: "0.1.30", Fingerprint: fp1, Artifacts: map[string]string{"m:tool": "d"}})
if _, err := store.Create(context.Background(), versions.ReservedKey("m", "0.1"), raw); err != nil {
@@ -19,7 +19,7 @@ func TestADoneTrunkBuildThatReservedNoneIsGivenAVersionByHand(t *testing.T) {
ctx := context.Background()
r := newRig(t, goBundle)
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: "0.1", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
res := &fakeReservations{filled: true}
res := &fakeReservations{}
r.b.Reserved = res
if _, err := r.b.ReserveDone(ctx, "m", fp1); err == nil {
t.Fatal("a version was reserved for a key that is not built")
@@ -133,12 +133,10 @@ type Builder struct {
// its single reference, and its needs. Nil: no node states anything, and the first forms are kept.
Forms func() (present, counted map[string][]string)
once sync.Once
sem chan struct{}
wg sync.WaitGroup
mu sync.Mutex
// fillWaits are the builds that said wait-held for the fill (module.fingerprint), so it is said once.
fillWaits sync.Map
once sync.Once
sem chan struct{}
wg sync.WaitGroup
mu sync.Mutex
known map[string]meshcatalog.ModulesByModuleValue // by modules key: the first watched branch's
heard map[string]meshcatalog.ModulesByModuleValue // by branch and module (take): what supersedes what
origin map[string]Origin // by build key: the catalog revision its entry came from (take)
@@ -717,10 +715,6 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
b.logf("%v", err)
}
}
if reserving && b.waitFill(module, m) {
end("is not built yet: wait-held, the catalog has not said versions-filled")
return
}
// A key built again by hand is taken over as it stands too: one left building by a look that ended without its write
// (issue 1966) is the hand tool's to finish.
// A done key a person builds again whose reserved version is not released is built whole, under a version reserved afresh (A-490b).
@@ -769,9 +763,7 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
// Reserved as A-490b amended by H-A-225 has it: this fingerprint's standing reservation is kept while it is unreleased
// and above the highest the catalog's versions answers, else the next above that highest is taken (A-455); the build's
// own publish then runs.
if b.Reserved.Filled() {
reserved, hasReserved = b.reserve(ctx, module, m, plan, b.originOf(key), true)
}
reserved, hasReserved = b.reserve(ctx, module, m, plan, b.originOf(key), true)
reserving = true
} else if reserving && cl.Build.State != builds.BuildDone {
// Looked at again just before it reserves (H-A-489): a newer entry heard since the claim is not taken over.
@@ -372,7 +372,7 @@ func TestAWithdrawnBuildEndsWithdrawn(t *testing.T) {
func TestANewerEntryHeardBeforeTheReservationIsNotTakenOver(t *testing.T) {
r := newRig(t, goBundle)
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: "0.1", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
res := &fakeReservations{filled: true}
res := &fakeReservations{}
r.b.Reserved = res
newer, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-catalog", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20",
Fp2: fp2, Manifest: mdigest('a'), Path: "modules/m", Toolchains: CatalogToolchains(agreedToolchains)})
@@ -145,7 +145,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
t.Run(c.name, func(t *testing.T) {
r := newRig(t, goBundle)
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: c.version, Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
res := &fakeReservations{filled: true, released: map[string]bool{fp1: c.released}}
res := &fakeReservations{released: map[string]bool{fp1: c.released}}
if c.takenOver {
res.tookBy = map[string]versions.ReservedVersion{fp1: {Module: "m", Series: "0.1", Version: "0.1.7", Fingerprint: fp2}}
}
@@ -395,7 +395,7 @@ func aRevisionHeldWakesTheAsk(t *testing.T) {
func revisionRig(t *testing.T, held *atomic.Int64, asked chan struct{}) (*rig, *fakeReservations, meshcatalog.CatalogEntry) {
r := newRig(t, goBundle)
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: "0.1", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
res := &fakeReservations{filled: true}
res := &fakeReservations{}
r.b.Reserved = res
entry := meshcatalog.CatalogEntry{Module: "m", Repository: "novox/mesh-catalog", Path: "modules/m", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20", Fp: fp1,
ManifestDigest: mdigest('a'), Inputs: &meshcatalog.EntryInputs{Toolchains: CatalogToolchains(agreedToolchains)}}
@@ -133,9 +133,6 @@ type Source struct {
// ReservedKey is the key of module's reservation of series (MAJOR.MINOR).
func ReservedKey(module, series string) string { return Key(module, series) }
// ErrNotFilled is what Reserve answers before the catalog says versions-filled: nothing is reserved until then (§369).
var ErrNotFilled = errors.New("versions-filled is not heard: nothing is reserved before the catalog's versions are filled")
// ReserveStore is the reservations' bucket: compare-and-set, and deletion.
type ReserveStore interface {
Store
@@ -147,8 +144,6 @@ type Reserver struct {
Store ReserveStore
// ReleasedOf are the patch versions (MAJOR.MINOR.PATCH) the catalog holds released for module, from its verb versions.
ReleasedOf func(ctx context.Context, module string) ([]string, error)
// Filled says the catalog said versions-filled.
Filled func() bool
// Took is told when a build took over the series' reservation of an older build never released (design 47 G A-455): the
// older reservation, which no want follows any more, is gone from the key, replaced by the newer's. Nil is told none.
Took func(ctx context.Context, older, newer ReservedVersion)
@@ -236,9 +231,6 @@ func SplitVersion(version string) (series string, patch int, err error) {
// alike (design 47 H H-A-225, which amends G A-490b): the run already building carries that number. A reservation another
// fingerprint takes over is withdrawn: its version is kept in Withdrawn, and Took is told so the older build is ended.
func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts []string, src Source) (ReservedVersion, error) {
if r.Filled != nil && !r.Filled() {
return ReservedVersion{}, ErrNotFilled
}
released, err := r.ReleasedOf(ctx, module)
if err != nil {
return ReservedVersion{}, fmt.Errorf("the released versions of %s cannot be read: %w", module, err)
@@ -33,27 +33,16 @@ func (m *reserveMem) Update(ctx context.Context, key string, value []byte, rev u
}
// TestReservation: design 47 G §369 (test 102): two builds close together reserve two versions, the key goes on
// version-released, a built reservation with an artifact unpublished past the bound is unreleased, and nothing is reserved
// before versions-filled.
// version-released, a built reservation with an artifact unpublished past the bound is unreleased.
func TestReservation(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 11, 11, 12, 0, 0, 0, time.UTC)
released := []string{"0.1.18", "0.1.19", "0.2.7"}
filled := true
store := &reserveMem{mem: newMem()}
r := &Reserver{Store: store, Filled: func() bool { return filled }, Now: func() time.Time { return now },
r := &Reserver{Store: store, Now: func() time.Time { return now },
ReleasedOf: func(context.Context, string) ([]string, error) { return released, nil }}
arts := []string{"m:a", "m:b"}
filled = false
if _, err := r.Reserve(ctx, "m", "0.1", arts, Source{}); !errors.Is(err, ErrNotFilled) {
t.Fatalf("before versions-filled: %v, want ErrNotFilled", err)
}
if got, _ := r.All(ctx); len(got) != 0 {
t.Fatalf("a reservation was written before the fill: %v", got)
}
filled = true
first, err := r.Reserve(ctx, "m", "0.1", arts, Source{})
if err != nil || first.Version != "0.1.20" {
t.Fatalf("first build reserves %q (%v), want 0.1.20 after the highest released 0.1.19", first.Version, err)
@@ -196,7 +185,7 @@ func TestReservationIsReadAndMarkedPublished(t *testing.T) {
func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) {
ctx := context.Background()
rel := &reserveMem{mem: newMem()}
r := &Reserver{Store: &reserveMem{mem: newMem()}, Releases: rel, ReleasedKept: 2, Filled: func() bool { return true },
r := &Reserver{Store: &reserveMem{mem: newMem()}, Releases: rel, ReleasedKept: 2,
ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
v, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "src2:aa"})
if err != nil {
@@ -279,7 +268,7 @@ func TestPublishedAnswersByTheBuildFingerprint(t *testing.T) {
ctx := context.Background()
heard := time.Date(2026, 11, 21, 19, 0, 0, 0, time.UTC)
store := &reserveMem{mem: newMem()}
r := &Reserver{Store: store, Releases: &reserveMem{mem: newMem()}, ReleasedKept: 2, Filled: func() bool { return true },
r := &Reserver{Store: store, Releases: &reserveMem{mem: newMem()}, ReleasedKept: 2,
ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }, Now: func() time.Time { return heard }}
v, err := r.Reserve(ctx, "mesh-grants", "0.1", []string{"mesh-grants:busgrants", "mesh-grants:grantsstate"}, Source{Fingerprint: "src2:aa"})
if err != nil {
@@ -360,7 +349,7 @@ func TestTheWithdrawnVersionsAreDroppedOnceReleasedPast(t *testing.T) {
ctx := context.Background()
store := &reserveMem{mem: newMem()}
highest := "0.1.3"
r := &Reserver{Store: store, Releases: &reserveMem{mem: newMem()}, Filled: func() bool { return true },
r := &Reserver{Store: store, Releases: &reserveMem{mem: newMem()},
ReleasedOf: func(context.Context, string) ([]string, error) { return []string{highest}, nil }}
for _, fp := range []string{"src2:a", "src2:b", "src2:c"} {
if _, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: fp}); err != nil {
@@ -424,7 +413,7 @@ func TestARebuildReservesAboveTheCatalogsHighestWhateverItsStandingNumberWas(t *
} {
t.Run(c.name, func(t *testing.T) {
store := &reserveMem{mem: newMem()}
r := &Reserver{Store: store, Filled: func() bool { return true },
r := &Reserver{Store: store,
ReleasedOf: func(context.Context, string) ([]string, error) { return []string{"0.1.16"}, nil }}
raw, _ := json.Marshal(ReservedVersion{V: 1, Module: "m", Series: "0.1", Version: c.standing, Fingerprint: c.standingFp, Artifacts: map[string]string{"m:a": "d"}})
if _, err := store.Create(ctx, ReservedKey("m", "0.1"), raw); err != nil {
@@ -167,7 +167,7 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
// DLV-M1: the indexer's and the assigner's views families of the states it follows.
if want := []string{"container-image-registry.kept", "container-image-registry.published", "container-image-registry.refused", "container-image-registry.removed",
"go-package-registry.kept", "go-package-registry.published", "go-package-registry.refused", "go-package-registry.removed",
"mesh-artifact-sweep.artifacts-gone", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-catalog.version-released", "mesh-catalog.versions-filled",
"mesh-artifact-sweep.artifacts-gone", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-catalog.version-released",
"mesh-conditions.findings-asked", "seat:mesh-module-assigner.views.assignments",
"seat:mesh-module-assigner.views.seat-holders", // A-298: the claimant's seat-holders view resolves the callers' seat entries
"mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-delivery.source-moved", "node-build-go.toolchain-reported", "node-build-node.toolchain-reported", "node-engine.manifest-reads-changed", "node-engine.running",
@@ -64,7 +64,6 @@
"mesh-catalog.seat-definition-changed",
"mesh-catalog.seat-definition-removed",
"mesh-catalog.version-released",
"mesh-catalog.versions-filled",
"node-build-go.toolchain-reported",
"node-build-node.toolchain-reported",
"node-engine.manifest-reads-changed",
@@ -14,13 +14,13 @@ const Seat = "mesh-catalog"
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
// a reader of a value of another form says "form N, this reader knows M".
const Form = 5
const Form = 6
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
// whose fields changed while its forms did not (design 47 H2 §780).
const (
generatedForms = "5"
generatedFieldsDigest = "ActingRule=8a83ce7e0457 Artifact=78b05c1a9ec3 ArtifactPackage=2a3a660a934d ArtifactRef=a2f06147f4b6 BuildEdge=76f0684e254a BuildEdges=d2b95000259e BuildEdgesByModuleBranchValue=4fdf7cc1e723 CandidatesByGroupValue=9ea8c6c580d2 CandidatesByGroupValuePullsItem=90fb03643258 CandidatesByGroupValuePullsItemFpsValue=4c6783201aa3 CatalogEntry=c0a4ea25d523 CatalogRevision=d1ecaaa484af CatalogRevisionDefinitionsItem=77fcff620d48 CatalogRevisionEvent=710cbc5bfff1 CatalogRevisionsByBranchRevisionValue=17e54f635d35 CatalogRevisionsByCandidateGroupHeadsValue=17e54f635d35 CatalogRevisionsByEntryDigestValue=8755036a3051 DependentsAnswer=7538f2f5e68e Edge=7242732afaef EntryAnswer=805c2ff28e1c EntryInputs=76a7f8690dd2 EntryRef=ff109e5089e1 Fill=80f442916429 FillingEvent=5bd4df78ed84 FingerprintInputs=99a6df7f991f FullEvent=5bd4df78ed84 Head=774b4bf88ba4 InputAnswer=cd41ee65565d InputsByTimeDigestValue=a2f06147f4b6 ManifestsByDigestValue=51b3822b29c6 ModuleAnswer=499a03ce9b27 ModuleAnswerModule=c0f679e09f08 ModulesAnswer=6d119571c69e ModulesAnswerModulesItem=a70f39c60b67 ModulesByModuleValue=fc7530ba893a ModulesByModuleValueInputs2=99a6df7f991f Outdated=e820214f66bc OutdatedAnswer=275fb25266b9 OutdatedDependency=dc35dca1b683 PackagesByModuleValue=2b62574b709f PackagesByModuleValuePackagesItem=a7d30558470d PackagesByPackageSeriesValue=07421d8d3411 PackagesByPackageSeriesValueNewest=aba144994370 PackagesByPackageSeriesValueNewestContents=eca2ccf56913 PackagesByPackageSeriesValueNewestContentsPackagesItem=a7d30558470d PackagesByPackageSeriesValueNumbered=c8ffc628599c PackagesByPackageSeriesValueNumberedContents=0def6c0794ee PackagesByPackageSeriesValueNumberedContentsPackagesItem=a7d30558470d Policy=719e2f460c6f PolicyAnswer=46cdf8430557 PredefinedByListValue=ec8e3febe8ac ProvidesAnswer=7538f2f5e68e RegisterAnswer=46cdf8430557 Registration=ef03d1b2e73f RegistrationAsked=b529a0e1c5ca RegistrationChangedEvent=99a3268edf41 RegistrationHistoryByModuleVersionValue=0999b5bb7dc7 RegistrationHistoryBySourceOwnerNameVersionValue=0999b5bb7dc7 RegistrationsAnswer=8849ef618cf3 RegistrationsByModuleValue=0999b5bb7dc7 RegistrationsBySourceOwnerNameValue=0999b5bb7dc7 RevisionAnswer=258ea5124931 RoomEvent=5bd4df78ed84 SeatDefinitionChangedEvent=e271d24d58f7 SeatDefinitionRemovedEvent=f7d6171111e6 SeatDefinitionsAnswer=0fd6a59fec59 SeatDefinitionsAnswerEntry=d006f68d2be5 SeatDefinitionsAnswerSeatsItem=e271d24d58f7 SeatListAnswer=04477a8044b1 SourceCheck=d1ed7cbbd579 StepStatuses=4f50aa633e61 TakeInEntry=545ec1528499 ToolchainUsed=43b6d42376fb UnwatchAnswer=46cdf8430557 VersionArtifact=438c49a392b0 VersionEdge=b0f80e83f4dc VersionEntry=33f5b00dbda9 VersionReleasedEvent=4ccf1ea90e7f VersionsAnswer=b59e6e057e7b VersionsByModuleVersionValue=e546dfadb913 VersionsFilledEvent=4cc437912dc3 WatchAnswer=46cdf8430557"
generatedForms = "6"
generatedFieldsDigest = "ActingRule=8a83ce7e0457 Artifact=78b05c1a9ec3 ArtifactPackage=2a3a660a934d ArtifactRef=a2f06147f4b6 BuildEdge=76f0684e254a BuildEdges=d2b95000259e BuildEdgesByModuleBranchValue=4fdf7cc1e723 CandidatesByGroupValue=9ea8c6c580d2 CandidatesByGroupValuePullsItem=90fb03643258 CandidatesByGroupValuePullsItemFpsValue=4c6783201aa3 CatalogEntry=c0a4ea25d523 CatalogRevision=d1ecaaa484af CatalogRevisionDefinitionsItem=77fcff620d48 CatalogRevisionEvent=710cbc5bfff1 CatalogRevisionsByBranchRevisionValue=17e54f635d35 CatalogRevisionsByCandidateGroupHeadsValue=17e54f635d35 CatalogRevisionsByEntryDigestValue=8755036a3051 DependentsAnswer=7538f2f5e68e Edge=7242732afaef EntryAnswer=805c2ff28e1c EntryInputs=76a7f8690dd2 EntryRef=ff109e5089e1 Fill=80f442916429 FillingEvent=5bd4df78ed84 FingerprintInputs=99a6df7f991f FullEvent=5bd4df78ed84 Head=774b4bf88ba4 InputAnswer=cd41ee65565d InputsByTimeDigestValue=a2f06147f4b6 ManifestsByDigestValue=51b3822b29c6 ModuleAnswer=499a03ce9b27 ModuleAnswerModule=c0f679e09f08 ModulesAnswer=6d119571c69e ModulesAnswerModulesItem=a70f39c60b67 ModulesByModuleValue=fc7530ba893a ModulesByModuleValueInputs2=99a6df7f991f Outdated=e820214f66bc OutdatedAnswer=275fb25266b9 OutdatedDependency=dc35dca1b683 PackagesByModuleValue=2b62574b709f PackagesByModuleValuePackagesItem=a7d30558470d PackagesByPackageSeriesValue=07421d8d3411 PackagesByPackageSeriesValueNewest=aba144994370 PackagesByPackageSeriesValueNewestContents=eca2ccf56913 PackagesByPackageSeriesValueNewestContentsPackagesItem=a7d30558470d PackagesByPackageSeriesValueNumbered=c8ffc628599c PackagesByPackageSeriesValueNumberedContents=0def6c0794ee PackagesByPackageSeriesValueNumberedContentsPackagesItem=a7d30558470d Policy=719e2f460c6f PolicyAnswer=46cdf8430557 PredefinedByListValue=ec8e3febe8ac ProvidesAnswer=7538f2f5e68e RegisterAnswer=46cdf8430557 Registration=ef03d1b2e73f RegistrationAsked=b529a0e1c5ca RegistrationChangedEvent=99a3268edf41 RegistrationHistoryByModuleVersionValue=0999b5bb7dc7 RegistrationHistoryBySourceOwnerNameVersionValue=0999b5bb7dc7 RegistrationsAnswer=8849ef618cf3 RegistrationsByModuleValue=0999b5bb7dc7 RegistrationsBySourceOwnerNameValue=0999b5bb7dc7 RevisionAnswer=258ea5124931 RoomEvent=5bd4df78ed84 SeatDefinitionChangedEvent=e271d24d58f7 SeatDefinitionRemovedEvent=f7d6171111e6 SeatDefinitionsAnswer=0fd6a59fec59 SeatDefinitionsAnswerEntry=d006f68d2be5 SeatDefinitionsAnswerSeatsItem=e271d24d58f7 SeatListAnswer=04477a8044b1 SourceCheck=d1ed7cbbd579 StepStatuses=4f50aa633e61 TakeInEntry=545ec1528499 ToolchainUsed=43b6d42376fb UnwatchAnswer=46cdf8430557 VersionArtifact=438c49a392b0 VersionEdge=b0f80e83f4dc VersionEntry=33f5b00dbda9 VersionReleasedEvent=4ccf1ea90e7f VersionsAnswer=b59e6e057e7b VersionsByModuleVersionValue=e546dfadb913 WatchAnswer=46cdf8430557"
)
const (
@@ -51,7 +51,6 @@ const (
EventRoom = "room"
EventRegistrationChanged = "registration-changed"
EventVersionReleased = "version-released"
EventVersionsFilled = "versions-filled"
)
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
@@ -101,7 +100,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{EventSeatDefinitionChanged, EventSeatDefinitionRemoved, EventCatalogRevision, EventFilling, EventFull, EventRoom, EventRegistrationChanged, EventVersionReleased, EventVersionsFilled}
return []string{EventSeatDefinitionChanged, EventSeatDefinitionRemoved, EventCatalogRevision, EventFilling, EventFull, EventRoom, EventRegistrationChanged, EventVersionReleased}
}
// Family is where the seat's events are kept: the shared events stream, filtered to the seat's subjects.
@@ -145,12 +144,6 @@ const StreamVersionReleased = "SEAT_mesh-catalog_version-released"
// SubjectVersionReleased is where version-released is published.
const SubjectVersionReleased = "mesh.seat.mesh-catalog.event.version-released"
// StreamVersionsFilled is the stream versions-filled is kept in.
const StreamVersionsFilled = "SEAT_mesh-catalog_versions-filled"
// SubjectVersionsFilled is where versions-filled is published.
const SubjectVersionsFilled = "mesh.seat.mesh-catalog.event.versions-filled"
const (
StateManifests = "manifests"
StateModules = "modules"
@@ -1542,16 +1535,6 @@ type VersionReleasedEvent struct {
Version string `json:"version"`
}
// VersionsFilledEvent is the body of the event versions-filled.
type VersionsFilledEvent struct {
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"`
// how many modules were filled
Modules int64 `json:"modules,omitempty"`
V int64 `json:"v"`
}
// ManifestsByDigestValue is one value of the state manifests under the key <digest>.
type ManifestsByDigestValue struct {
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
@@ -2000,15 +1983,6 @@ func DecodeVersionReleasedEvent(raw []byte) (VersionReleasedEvent, int, error) {
return v, formRead(raw), nil
}
// DecodeVersionsFilledEvent reads a VersionsFilledEvent 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 DecodeVersionsFilledEvent(raw []byte) (VersionsFilledEvent, int, error) {
var v VersionsFilledEvent
if err := json.Unmarshal(raw, &v); err != nil {
return v, 0, err
}
return v, formRead(raw), nil
}
// formRead is the form a value says on the wire: 1 when it says none, or is no object.
func formRead(raw []byte) int {
var f struct {
@@ -35,8 +35,6 @@ func TestFixtures(t *testing.T) {
}, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-catalog\\.event\\.registration-changed$")},
{name: "a version released", subject: "mesh.seat.mesh-catalog.event.version-released", given: "{\"artifacts\":[{\"artifact\":\"mesh-sdk:go\",\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\"}],\"module\":\"mesh-sdk\",\"source\":3589,\"v\":1,\"version\":\"0.1.15\"}", wire: "{\"artifacts\":[{\"artifact\":\"mesh-sdk:go\",\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\"}],\"module\":\"mesh-sdk\",\"source\":3589,\"v\":1,\"version\":\"0.1.15\"}",
decode: func(b []byte) (any, error) { var v VersionReleasedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-catalog\\.event\\.version-released$")},
{name: "the versions filled", subject: "mesh.seat.mesh-catalog.event.versions-filled", given: "{\"at\":\"2026-11-11T10:00:00Z\",\"modules\":120,\"v\":1}", wire: "{\"at\":\"2026-11-11T10:00:00Z\",\"modules\":120,\"v\":1}",
decode: func(b []byte) (any, error) { var v VersionsFilledEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-catalog\\.event\\.versions-filled$")},
{name: "a manifest (xclip, read through mesh-catalog.module)", subject: "", given: "{\"manifest\":\"{\\\"build\\\":{\\\"artifacts\\\":[{\\\"binary\\\":\\\"xclip-tools\\\",\\\"from\\\":\\\"cmd/xclip-tools\\\",\\\"kind\\\":\\\"bundle\\\",\\\"language\\\":\\\"go\\\",\\\"loads\\\":[\\\"xclip-tools\\\"],\\\"name\\\":\\\"tools\\\",\\\"system\\\":\\\"arch\\\"}]},\\\"capabilities\\\":[\\\"package-manager\\\"],\\\"module\\\":\\\"xclip\\\",\\\"resources\\\":[{\\\"id\\\":\\\"package\\\",\\\"package\\\":\\\"xclip\\\",\\\"type\\\":\\\"package\\\"}],\\\"tools\\\":[\\\"xclip_copy\\\",\\\"xclip_paste\\\",\\\"xclip_targets\\\",\\\"xclip_session\\\"],\\\"version\\\":\\\"1\\\"}\",\"module\":\"xclip\",\"v\":1}", wire: "{\"manifest\":\"{\\\"build\\\":{\\\"artifacts\\\":[{\\\"binary\\\":\\\"xclip-tools\\\",\\\"from\\\":\\\"cmd/xclip-tools\\\",\\\"kind\\\":\\\"bundle\\\",\\\"language\\\":\\\"go\\\",\\\"loads\\\":[\\\"xclip-tools\\\"],\\\"name\\\":\\\"tools\\\",\\\"system\\\":\\\"arch\\\"}]},\\\"capabilities\\\":[\\\"package-manager\\\"],\\\"module\\\":\\\"xclip\\\",\\\"resources\\\":[{\\\"id\\\":\\\"package\\\",\\\"package\\\":\\\"xclip\\\",\\\"type\\\":\\\"package\\\"}],\\\"tools\\\":[\\\"xclip_copy\\\",\\\"xclip_paste\\\",\\\"xclip_targets\\\",\\\"xclip_session\\\"],\\\"version\\\":\\\"1\\\"}\",\"module\":\"xclip\",\"v\":1}",
decode: func(b []byte) (any, error) { var v ManifestsByDigestValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
{name: "a module (xclip, read through mesh-catalog.modules; the inputs and toolchains no tool reads are not here)", subject: "", given: "{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fp2\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"v\":1}", wire: "{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fp2\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"v\":1}",
@@ -101,15 +101,5 @@
],
"source": 3589
}
},
{
"name": "the versions filled",
"of": "event:versions-filled",
"subject": "mesh.seat.mesh-catalog.event.versions-filled",
"given": {
"v": 1,
"at": "2026-11-11T10:00:00Z",
"modules": 120
}
}
]
@@ -889,34 +889,6 @@
],
"description": "a version released: every artifact of the module is published at it (design 47 G section 349)"
}
},
{
"name": "versions-filled",
"keep": {
"max-age-days": 0,
"max-mib": 1
},
"body": {
"type": "object",
"properties": {
"v": {
"type": "integer"
},
"at": {
"type": "string",
"format": "date-time"
},
"modules": {
"type": "integer",
"description": "how many modules were filled"
}
},
"required": [
"v",
"at"
],
"description": "the catalog's versions were filled once from what is published (design 47 G section 372)"
}
}
],
"states": [
@@ -2737,5 +2709,5 @@
]
}
},
"form": 5
"form": 6
}
@@ -32,7 +32,6 @@ export declare const events: {
readonly room: "room";
readonly registrationChanged: "registration-changed";
readonly versionReleased: "version-released";
readonly versionsFilled: "versions-filled";
};
export declare const family: { readonly name: "mesh-catalog.events"; readonly maxAgeDays: 7 };
@@ -59,10 +58,6 @@ export declare const versionReleasedStream: "SEAT_mesh-catalog_version-released"
export declare const versionReleasedSubject: "mesh.seat.mesh-catalog.event.version-released";
export declare const versionsFilledStream: "SEAT_mesh-catalog_versions-filled";
export declare const versionsFilledSubject: "mesh.seat.mesh-catalog.event.versions-filled";
export declare const states: {
readonly manifests: "manifests";
readonly modules: "modules";
@@ -960,16 +955,6 @@ export interface VersionReleasedEvent {
"version": string;
}
/** is the body of the event versions-filled. */
export interface VersionsFilledEvent {
"at": string;
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
"form"?: number;
/** how many modules were filled */
"modules"?: number;
"v": number;
}
/** is one value of the state manifests under the key <digest>. */
export interface ManifestsByDigestValue {
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
@@ -32,7 +32,6 @@ export const events = {
room: "room",
registrationChanged: "registration-changed",
versionReleased: "version-released",
versionsFilled: "versions-filled",
};
export const family = { name: "mesh-catalog.events", maxAgeDays: 7 };
@@ -61,10 +60,6 @@ export const versionReleasedStream = "SEAT_mesh-catalog_version-released";
export const versionReleasedSubject = "mesh.seat.mesh-catalog.event.version-released";
export const versionsFilledStream = "SEAT_mesh-catalog_versions-filled";
export const versionsFilledSubject = "mesh.seat.mesh-catalog.event.versions-filled";
export const states = {
manifests: "manifests",
modules: "modules",
@@ -395,7 +395,6 @@ func startIndexerRun(t *testing.T, put func(context.Context, buildLog), before .
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "EVENTS", Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.mesh-catalog.event.catalog-revision.*", "mesh.seat.mesh-catalog.event.filling",
"mesh.seat.mesh-catalog.event.full", "mesh.seat.mesh-catalog.event.room", "mesh.seat.mesh-catalog.event.seat-definition-changed",
"mesh.seat.mesh-catalog.event.seat-definition-removed", "mesh.seat.mesh-catalog.event.manifest-accepted", "mesh.seat.mesh-catalog.event.version-released",
"mesh.seat.mesh-catalog.event.versions-filled",
"mesh.seat.mesh-conditions.event.>", "mesh.seat.operator-channel.event.>", "mesh.seat.go-package-registry.event.>", "mesh.seat.npm-package-registry.event.>",
"mesh.seat.mesh-module-assigner.event.>", "mesh.seat.node-build-go.event.>", meshbuilds.SubjectVersionReserved}}); err != nil { // not the seats kept in streams of their own (wanted and running, above)
t.Fatal(err)
@@ -328,7 +328,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
}, seatLists)
readWhenBound(seatReader, seatDefs, marks)
keepSeatListAtStart(ctx, seatDefs, seatBus.defs, seatLists, logger.Printf)
var fillFollow atomic.Pointer[versionsFill]
// Kept while named (design 47 G §675): the want and the running build that name a fingerprint, heard below.
named := index.NewNamed(awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.NamedState), "no entry is kept for a want or a running build that names it", logger.Printf)}, logger.Printf)
pinsBucket := process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.PinsState), "no record's pin on a catalog graph revision is kept, so no revision is removed", logger.Printf)
@@ -369,7 +368,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
Revisions: revisions, EntryIndex: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.EntryIndexState), "no entry is found by its fingerprint", logger.Printf)}, // Message a kept call: a read, called again through a transport fault (ADR 0668 §1)
// Each catalog revision may bring another holder of a build seat: the build modules are found again (buildmodules.go).
// A new trunk revision that changes the modules is said on the views family of modules too (design 47 G A-360).
SayCatalogRevision: afterRevision(refreshingBuildModules(sayingModulesView(sayCatalogRevision(cred, views.JetStreamPublish(js)), cred, views.JetStreamPublish(js)), &buildFollow), &fillFollow),
SayCatalogRevision: refreshingBuildModules(sayingModulesView(sayCatalogRevision(cred, views.JetStreamPublish(js)), cred, views.JetStreamPublish(js)), &buildFollow),
SayFill: sayFill(conn, cred),
// The catalog's released versions (design 47 G §349): the state versions, bound when it appears, and the event version-released.
Versions: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.VersionsState), "no released version is kept, so no package-published makes a version", logger.Printf)},
@@ -379,8 +378,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
Imports: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.ImportsState), "no import set is kept, so every module keeps the version line", logger.Printf)},
Inputs: inputsStore,
InputObjects: inObjects,
SayVersionReleased: sayVersionReleased(conn, cred), SayVersionsFilled: sayVersionsFilled(conn, cred),
SayTakeIn: sayTakeIn(js, cred)}
SayVersionReleased: sayVersionReleased(conn, cred),
SayTakeIn: sayTakeIn(js, cred)}
// The registrations and the changes that wait for their warrant (design 47 G §2, §667): their states are bound when they
// appear; a warrant is heard on the router's decided event for this module, below.
registry := newRegistry(js, conn, cred, calls.Call,
@@ -393,10 +392,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
sources := &sourceMoved{ctx: ctx, ix: ix, branches: watchedBranches(registry), bind: bindBranch(js, cred, logger.Printf), source: sourceVia(calls.Call), logf: logger.Printf}
defer sources.stop()
named.Changed = ix.RemoveUnlisted
// The first fill of the versions (design 47 G §372): at the start, and again at each catalog revision kept until it is made.
fill := &versionsFill{ix: ix, ctx: ctx, ask: versionsVia(calls.CallKeptWhileOpen, ix.ModuleInNewestView, logger.Printf), logf: logger.Printf}
fillFollow.Store(fill)
fill.kick()
ix.SeedModules = func(ctx context.Context) ([]index.SeedModule, error) {
r := seatReader.Reader()
if r == nil {
@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"sync/atomic"
"time"
"github.com/nats-io/nats.go"
@@ -195,54 +194,3 @@ func heardImportsReported(ctx context.Context, ix *index.Indexer, m jetstream.Ms
}
_ = m.Ack()
}
// sayVersionsFilled says versions-filled (design 47 G §372) once, on the seat's stream that keeps it with no age limit.
func sayVersionsFilled(conn *nats.Conn, cred process.Account) func(context.Context, meshcatalog.VersionsFilledEvent, string) error {
return func(_ context.Context, e meshcatalog.VersionsFilledEvent, id string) error {
return saySeatEvent(conn, cred, meshcatalog.EventVersionsFilled, id, e)
}
}
// versionsVia asks the builder's tool builder_versions for one name as a kept call (ADR 0668 §1, §2) asked again while the module is in the newest view (A-190) and reads its answer.
func versionsVia(call openCaller, inView func(ctx context.Context, module string) (bool, error), logf func(string, ...any)) index.VersionsAsker {
return func(ctx context.Context, module, name string) (index.BuilderVersionsAnswer, error) {
var a index.BuilderVersionsAnswer
raw, err := keptWhileOpen(ctx, call, logf, "versions."+name, index.BuilderVersionsCall, map[string]any{"name": name},
func(ctx context.Context) (bool, error) { return inView(ctx, module) })
if err != nil {
return a, err
}
if err := json.Unmarshal(raw, &a); err != nil {
return a, fmt.Errorf("the answer of %s is not a name's versions: %w", index.BuilderVersionsCall, err)
}
return a, nil
}
}
// versionsFill is the first fill of the versions in the background (design 47 G §372): started at the start and at each
// catalog revision kept, until it is made; one runs at a time, and a fill that fails is said and made again at the next.
type versionsFill struct {
ix *index.Indexer
ctx context.Context
ask index.VersionsAsker
logf func(string, ...any)
}
func (f *versionsFill) kick() {
go func() {
if err := f.ix.FillVersions(f.ctx, f.ask); err != nil {
f.logf("versions: the first fill waits: %v", err)
}
}()
}
// afterRevision runs the fill's kick after each catalog revision kept, once the fill is set.
func afterRevision(say func(context.Context, meshcatalog.CatalogRevisionEvent) error, fill *atomic.Pointer[versionsFill]) func(context.Context, meshcatalog.CatalogRevisionEvent) error {
return func(ctx context.Context, e meshcatalog.CatalogRevisionEvent) error {
err := say(ctx, e)
if f := fill.Load(); f != nil {
f.kick()
}
return err
}
}
@@ -96,8 +96,6 @@ type Indexer struct {
BuildEdges Store
// SayVersionReleased says the seat mesh-catalog's event version-released under the duplicate id given (§349); nil says nothing.
SayVersionReleased func(ctx context.Context, e meshcatalog.VersionReleasedEvent, id string) error
// SayVersionsFilled says the seat mesh-catalog's event versions-filled, once, under the duplicate id given (§372); nil says nothing.
SayVersionsFilled func(ctx context.Context, e meshcatalog.VersionsFilledEvent, id string) error
// Inputs is the state inputs (run_inputs.go, design 47 G §354): the inputs of the indexer's run asks; nil keeps none.
Inputs Store
// InputObjects is the object store beside the state inputs (`inputs-objects`): an input too large for a key is kept there
@@ -141,21 +139,20 @@ type Indexer struct {
Contains func(ctx context.Context, repository, commit, in string) (bool, error)
Logf func(format string, args ...any)
mu sync.Mutex // guards source, toolchains and previews, which the watches and the forge messages all reach
source sourceNow
toolchains map[string]map[string]nodebuildgo.Toolchain // language, then node (toolchains.go)
buildModules map[string]BuildModule // by language: the build modules whose toolchains are taken in (buildmodules.go)
versionsFilling atomic.Bool // a FillVersions runs (versions_fill.go)
stepsSince map[string]time.Time // by build seat: since when its steps is unanswered (seed_steps.go)
moving map[string]whole // by modules key: a merge naming a module another repository holds, waiting for that trunk to drop it (moves.go)
fresh map[string]bool // modules whose import form is computed again by hand (FingerprintsAgain), "*" for every one; under freshMu
freshMu sync.Mutex
recompute sync.Mutex // one Recompute at a time
untaken map[string]string // repository to the latest merge applied while the taken state was missing (taken.go)
filling atomic.Bool // a FillTaken runs in the background (KickFill)
fillAgain atomic.Bool // a kick arrived while it ran
underSeats bool // a dry run inside judge.WithSeats: its judge passes do not hold the seat list (verdicts.go)
isDry bool // a dry run (dryrun.go): its packages are a working copy over the live state, and it drops no kept package key (packages.go)
mu sync.Mutex // guards source, toolchains and previews, which the watches and the forge messages all reach
source sourceNow
toolchains map[string]map[string]nodebuildgo.Toolchain // language, then node (toolchains.go)
buildModules map[string]BuildModule // by language: the build modules whose toolchains are taken in (buildmodules.go)
stepsSince map[string]time.Time // by build seat: since when its steps is unanswered (seed_steps.go)
moving map[string]whole // by modules key: a merge naming a module another repository holds, waiting for that trunk to drop it (moves.go)
fresh map[string]bool // modules whose import form is computed again by hand (FingerprintsAgain), "*" for every one; under freshMu
freshMu sync.Mutex
recompute sync.Mutex // one Recompute at a time
untaken map[string]string // repository to the latest merge applied while the taken state was missing (taken.go)
filling atomic.Bool // a FillTaken runs in the background (KickFill)
fillAgain atomic.Bool // a kick arrived while it ran
underSeats bool // a dry run inside judge.WithSeats: its judge passes do not hold the seat list (verdicts.go)
isDry bool // a dry run (dryrun.go): its packages are a working copy over the live state, and it drops no kept package key (packages.go)
// trunkModules is, in a dry run, the live modules state under its view: main's values, whose import form a branch takes
// with main's import set (importset.go, H-A-532 DMC-6); nil reads Modules.
trunkModules Store
@@ -173,7 +170,7 @@ type Indexer struct {
catchUpWG sync.WaitGroup // the first start's catch-up in the background (kickCatchUp), for tests to wait on
// Heard keeps what the indexer heard and compares later (A-80): the time a call is unanswered since (steps-since, call-since),
// toolchain.<language>, pending.<module>.<version>, acted.<acting part>.<dependent>, each key part escaped as a name
// (§73), and the mark versions-filled; nil keeps none. It is the state heard, whose key forge keeps the forge messages handled.
// (§73); nil keeps none. It is the state heard, whose key forge keeps the forge messages handled.
Heard Store
judgePending atomic.Bool // the start's judge pass failed: judged again at the next message (verdicts.go)
// SayTakeIn publishes a take-in event (take-in.taken, take-in.pending; design 47 H §743, §744) with its body, under the
@@ -61,7 +61,7 @@ func (ix *Indexer) dry(branch, call string) *dryRun {
Findings: nil, SeatDefinitions: nil, ReadFile: ix.ReadFile, SaySeatDefinition: nil,
Heard: nil, underSeats: true, isDry: true,
// A dry run keeps no catalog graph revision (catalog_revisions.go): its revision is the take-in's to keep.
Revisions: nil, SayCatalogRevision: nil, SayFill: nil, EntryIndex: nil, NamedSets: nil, Versions: nil, SayVersionReleased: nil, SayVersionsFilled: nil, Inputs: nil, InputObjects: nil, Pins: nil, PinsPending: nil,
Revisions: nil, SayCatalogRevision: nil, SayFill: nil, EntryIndex: nil, NamedSets: nil, Versions: nil, SayVersionReleased: nil, Inputs: nil, InputObjects: nil, Pins: nil, PinsPending: nil,
// A dry run writes no registration and asks no one.
Registry: nil, SeedModules: nil}
x.Logf = func(format string, args ...any) { ix.logf("take-in, computed and not written: "+format, args...) }
@@ -194,7 +194,7 @@ func TestFindingKindsHoldEveryKindTheCodeRaises(t *testing.T) {
return false
}
for _, id := range []string{keyID("node-build-go." + StepsVerb), keyID("node-build-image." + StepsVerb), keyID("mesh-catalog.versions-floor.mesh-tools"),
keyID(BuilderVersionsCall)} {
keyID("mesh-delivery-builder.builder_versions")} {
if !covers(mcc.ScopeCall, id) {
t.Errorf("the retired call-unanswered does not cover the indexer's id %s", id)
}
@@ -32,7 +32,7 @@ var FindingKinds = []string{TakeInWaitingKind, PinMissingKind, OutOfStepKind, Pa
// the seed's <build seat>.steps (every build seat is named node-build-<kind>), the floor's mesh-catalog.versions-floor.<module>
// and the versions fill's mesh-delivery-builder.builder_versions.
var RetiredFindingKinds = []views.RetiredKind{{Kind: "merge-untaken"}, {Kind: mcc.KindCallUnanswered, Scope: mcc.ScopeCall,
IDs: []string{keyID(BuilderVersionsCall)}, Prefixes: []string{"node-build-", keyID("mesh-catalog.versions-floor") + "."}}} // the floor went at design 47 H §756
IDs: []string{keyID("mesh-delivery-builder.builder_versions")}, Prefixes: []string{"node-build-", keyID("mesh-catalog.versions-floor") + "."}}} // the floor went at design 47 H §756
// FindingWriter is the indexer's finding writer, mesh-sdk's held writer of the seat mesh-conditions' generated finding (design
// 47 G A-29, A-38): Write raises a finding, Clear clears one, Held answers the findings it holds, so the indexer reads what
@@ -252,7 +252,7 @@ func TestTrunkViewReadsTheNewerRevisionWhenTheOneNamedIsRemovedUnderIt(t *testin
}
// A-487d: every reader of the newest revision in the indexer program reads the newest again when the revision it named is
// removed under it (ModuleInNewestView, SeedEntryHeld, entryOf, SeedModulesFrom, FillVersions, the tool indexer_catalog_revision
// removed under it (ModuleInNewestView, SeedEntryHeld, entryOf, SeedModulesFrom, the tool indexer_catalog_revision
// and the verb revision, trunk's and a watched branch's).
func TestTheNewestRevisionReadersReadAgainWhenTheRevisionIsRemovedUnderThem(t *testing.T) {
ctx := context.Background()
@@ -267,13 +267,6 @@ func TestTheNewestRevisionReadersReadAgainWhenTheRevisionIsRemovedUnderThem(t *t
return e.Fp == "fp2", err
}},
"SeedModulesFrom": {"", func(ix *Indexer) (bool, error) { _, err := ix.SeedModulesFrom(ctx, nil, nil); return err == nil, err }},
"FillVersions": {"", func(ix *Indexer) (bool, error) {
ix.Versions, ix.Heard = MemoryStore(), MemoryStore()
err := ix.FillVersions(ctx, func(context.Context, string, string) (BuilderVersionsAnswer, error) {
return BuilderVersionsAnswer{}, nil
})
return err == nil, err
}},
"indexer_catalog_revision": {"", func(ix *Indexer) (bool, error) {
var tool map[string]any
for _, tl := range CatalogRevisionTools(ix.Revisions, nil, time.Now, nil) {
@@ -3,9 +3,7 @@ package index
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
"testing"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
@@ -61,7 +59,7 @@ func TestKeptCallsOpenWhileTheirAskServesSomething(t *testing.T) {
})
}
// A-190: a call that ends with its ask closed is not said unanswered: no finding, and the fill and the seed go on.
// A-190: a call that ends with its ask closed is not said unanswered: no finding, and the seed goes on.
func TestAClosedAskIsNotUnanswered(t *testing.T) {
ctx := context.Background()
closed := fmt.Errorf("steps: %w", ErrAskClosed)
@@ -77,9 +75,4 @@ func TestAClosedAskIsNotUnanswered(t *testing.T) {
}); err != nil || len(ix.stepsSince) != 0 {
t.Errorf("a closed steps ask counted unanswered: %v %v", err, ix.stepsSince)
}
if err := ix.FillVersions(ctx, func(context.Context, string, string) (BuilderVersionsAnswer, error) {
return BuilderVersionsAnswer{}, fmt.Errorf("builder_versions: %w", ErrAskClosed)
}); errors.Is(err, ErrAskClosed) || (err != nil && strings.Contains(err.Error(), "is not answered")) {
t.Errorf("a closed versions ask is unanswered: %v", err)
}
}
@@ -1,202 +0,0 @@
package index
import (
"context"
"encoding/json"
"errors"
"fmt"
"maps"
"slices"
"strconv"
"time"
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/keys"
)
// The first fill of the versions (design 47 G §372): at the first start under G the state versions is filled once, as
// released, for each module from the highest version over every artifact of the module that the builder's state versions
// gave a number, numbered or published (A-350), read by the builder's tool builder_versions as a kept call; then
// versions-filled is said once, and the builder reserves nothing before it (§369).
const (
// BuilderVersionsCall is the tool the manifest names in its invokes (until that tool goes).
BuilderVersionsCall = "mesh-delivery-builder.builder_versions"
// VersionsFilledKey is the key of the state heard that says the fill is done, so it is not made again.
VersionsFilledKey = "versions-filled"
)
// versionsFillSince is the key of the state heard of the time builder_versions is first unanswered.
var versionsFillSince = "call-since." + keys.EscapeName(BuilderVersionsCall)
// BuilderVersion is one version of a name in the answer of builder_versions (its fields the fill reads).
type BuilderVersion struct {
Version string `json:"version"`
State string `json:"state"`
Digest string `json:"digest"`
Revision string `json:"revision"`
At time.Time `json:"at"`
}
// givenANumber says whether the builder's state versions gave the version its number: numbered, or numbered and then
// published (A-350: the builder numbers fresh versions it has not published, so a fill from published alone would number
// again below what the builder already said).
func givenANumber(state string) bool { return state == "numbered" || state == "published" }
// BuilderVersionsAnswer is what builder_versions answers for a name.
type BuilderVersionsAnswer struct {
Name string `json:"name"`
Versions []BuilderVersion `json:"versions"`
}
// VersionsAsker asks builder_versions for a name's versions (a kept call, ADR 0668 §1, §2).
type VersionsAsker func(ctx context.Context, module, name string) (BuilderVersionsAnswer, error)
// versionNameOf is the name the builder numbers an artifact under: its package's name in its ecosystem, else
// <module>/<artifact> (images, bundles and archives).
func versionNameOf(module string, a meshcatalog.Artifact) string {
if a.Package != nil && a.Package.Name != "" {
return a.Package.Name
}
return module + "/" + artifactName(a.Ref)
}
// FillVersions fills the state versions once from builder_versions and says versions-filled (§372). A fill already made
// is not made again; a builder_versions that does not answer holds the fill and, after five minutes, is the finding
// indexer-call-unanswered (scope call, id mesh-delivery-builder.builder_versions), cleared when it answers.
func (ix *Indexer) FillVersions(ctx context.Context, ask VersionsAsker) error {
if ix.Versions == nil || ix.Heard == nil {
return errors.New("the state versions is not kept here")
}
if !ix.versionsFilling.CompareAndSwap(false, true) {
return nil // one fill runs at a time
}
defer ix.versionsFilling.Store(false)
if _, _, done, err := ix.Heard.Get(ctx, VersionsFilledKey); err != nil || done {
return err
}
if ix.Revisions == nil {
return errors.New("the catalog graph is not kept here: no entry names the modules' artifacts")
}
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil {
return err
}
if !found {
return errors.New("the indexer keeps no trunk revision yet: the first fill of the versions waits for its first")
}
type found1 struct {
v BuilderVersion
name string
ref string
}
best := map[string][]found1{} // by module: each artifact's highest numbered or published version (A-350)
var unanswered error
for _, e := range entries {
var top string // the module's highest version the builder gave a number, numbered or published (A-350)
per := []found1{}
for _, a := range e.Artifacts {
name := versionNameOf(e.Module, a)
ans, err := ask(ctx, e.Module, name)
if errors.Is(err, ErrAskClosed) {
continue // the module left the view: nothing waits on its versions (A-190)
}
if err != nil {
unanswered = err
continue
}
for _, v := range ans.Versions {
if _, ok := versionParts(v.Version); !ok || !givenANumber(v.State) {
continue
}
per = append(per, found1{v: v, name: name, ref: a.Ref})
if top == "" || compareVersions(v.Version, top) > 0 {
top = v.Version
}
}
}
for _, f := range per {
if f.v.Version == top {
best[e.Module] = append(best[e.Module], f)
}
}
}
if unanswered != nil {
ix.fillUnanswered(ctx, unanswered)
return fmt.Errorf("builder_versions is not answered: %w", unanswered)
}
ix.answered(ctx, versionsFillSince)
if ix.Findings != nil {
if err := ix.clearFinding(ctx, mcc.ScopeCall, BuilderVersionsCall, CallUnansweredKind, "builder_versions answers"); err != nil {
ix.logf("versions fill: the finding %s is not cleared: %v", BuilderVersionsCall, err)
}
}
now := ix.now().UTC()
filled := 0
built := map[string]meshcatalog.VersionEntry{}
claimed := map[string]time.Time{}
trunk := map[string]meshcatalog.CatalogEntry{}
for _, e := range entries {
trunk[e.Module] = e
}
for module, fs := range best {
v := meshcatalog.VersionEntry{V: int64(keys.Version), Module: module, Version: fs[0].v.Version, At: &now}
for _, f := range fs {
v.Artifacts = append(v.Artifacts, meshcatalog.VersionArtifact{Artifact: f.ref, Digest: f.v.Digest})
if n, err := strconv.ParseInt(f.v.Revision, 10, 64); err == nil && n > v.Source {
v.Source = n
}
if f.v.At.After(claimed[module]) {
claimed[module] = f.v.At
}
}
built[module] = v
}
// The edge entries (§377), each marked filled; those of kinds 2, 4 and 6 read "not yet delivered", as at a release.
answers := map[string]BuilderVersionsAnswer{}
for _, module := range slices.Sorted(maps.Keys(built)) {
v := built[module]
v.Edges = ix.filledEdges(ctx, trunk[module], claimed[module], ask, trunk, built, answers)
built[module] = v
}
for _, module := range slices.Sorted(maps.Keys(built)) {
v := built[module]
data, err := json.Marshal(v)
if err != nil {
return err
}
if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey(module, v.Version), data); err != nil && !errors.Is(err, ErrConflict) {
return fmt.Errorf("the version %s %s is not kept: %w", module, v.Version, err)
}
ix.keepFilledFacts(ctx, v, trunk[module], built, now)
filled++
}
if ix.SayVersionsFilled != nil {
ev := meshcatalog.VersionsFilledEvent{V: int64(keys.Version), At: now, Modules: int64(filled)}
if err := ix.SayVersionsFilled(ctx, ev, meshcatalog.EventVersionsFilled); err != nil {
return fmt.Errorf("versions-filled is not said: %w", err)
}
}
if err := ix.Heard.Create(ctx, VersionsFilledKey, []byte(now.Format(time.RFC3339Nano))); err != nil && !errors.Is(err, ErrConflict) {
return err
}
ix.logf("versions: filled for %d modules from builder_versions, versions-filled said", filled)
return nil
}
// fillUnanswered writes indexer-call-unanswered once builder_versions is unanswered five minutes (the time kept in the own state).
func (ix *Indexer) fillUnanswered(ctx context.Context, cause error) {
now := ix.now()
since := ix.unansweredSince(ctx, versionsFillSince, now)
if ix.Findings == nil || now.Sub(since) < mcc.CallUnansweredAfter {
return
}
f := ix.observed(mcc.ScopeCall, BuilderVersionsCall, CallUnansweredKind,
fmt.Sprintf("the call %s is unanswered since %s", BuilderVersionsCall, since.UTC().Format(time.RFC3339)),
"A call whose answer is kept is not answered",
fmt.Sprintf("The first fill of the catalog's versions asks %s of every artifact; it is not answered since %s (%v), so no version is released and the builder reserves nothing.", BuilderVersionsCall, since.UTC().Format(time.RFC3339), cause),
"indexer."+CallUnansweredKind)
if err := ix.Findings.Write(ctx, f); err != nil {
ix.logf("versions fill: the finding %s is not written: %v", BuilderVersionsCall, err)
}
}
@@ -1,99 +0,0 @@
package index
import (
"cmp"
"context"
"encoding/json"
"slices"
"strings"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
)
// The edge entries of the first fill (design 47 G §377, A-78 c): each module's newest version gets its entries once, each marked
// filled. Kinds 1 and 3 come from the dependency version published latest before the version's build was claimed, read with
// the times of builder_versions, and its part's digest; kinds 2, 4 and 6 are declarations and read "not yet delivered" (design 47 H
// H-A-82: no delivered version is kept); kind 5 as done for every acting part's running build.
// filledEdges are the edge entries of the entry's newest version, which was filled as built; claimed is when its build was claimed.
func (ix *Indexer) filledEdges(ctx context.Context, entry meshcatalog.CatalogEntry, claimed time.Time, ask VersionsAsker, trunk map[string]meshcatalog.CatalogEntry,
built map[string]meshcatalog.VersionEntry, answers map[string]BuilderVersionsAnswer) []meshcatalog.VersionEdge {
var out []meshcatalog.VersionEdge
seen := func(e meshcatalog.VersionEdge) bool {
return slices.ContainsFunc(out, func(x meshcatalog.VersionEdge) bool { return x.Kind == e.Kind && x.Part == e.Part && x.Word == e.Word })
}
for _, g := range entry.Edges {
part := cmp.Or(g.Part, g.From)
module := strings.SplitN(part, ":", 2)[0]
if part == "" || module == entry.Module {
continue
}
e := meshcatalog.VersionEdge{Kind: g.Kind, Part: part, Word: g.Word, Filled: true}
switch g.Kind {
case 1, 3:
dep, ok := trunk[module]
if !ok {
continue
}
var name string
for _, a := range dep.Artifacts {
if a.Ref == part {
name = versionNameOf(module, a)
}
}
if name == "" {
continue
}
ans, ok := answers[name]
if !ok {
a, err := ask(ctx, module, name)
if err != nil {
continue
}
ans, answers[name] = a, a
}
var best *BuilderVersion
for i, v := range ans.Versions {
if _, ok := versionParts(v.Version); !ok || !givenANumber(v.State) || v.At.After(claimed) {
continue
}
if best == nil || v.At.After(best.At) {
best = &ans.Versions[i]
}
}
if best == nil {
continue
}
e.Version, e.Digest, e.Stale = best.Version, best.Digest, true
case 2, 4, 6:
e.Version = notYetDelivered // a declaration: no delivered version is kept for it (design 47 H H-A-82)
case 5:
e.Fact = "acted for the running build " + entry.Fp
default:
continue
}
if !seen(e) {
out = append(out, e)
}
}
return out
}
// keepFilledFacts keeps what the first fill derived of a version as heard: for each kind-5 edge the act for the running build (A-78 a).
func (ix *Indexer) keepFilledFacts(ctx context.Context, v meshcatalog.VersionEntry, entry meshcatalog.CatalogEntry, built map[string]meshcatalog.VersionEntry, at time.Time) {
for _, e := range v.Edges {
switch e.Kind {
case 5:
data, _ := json.Marshal(Acted{V: 1, Part: e.Part, Build: entry.Fp, How: "filled", At: at})
if err := write(ctx, ix.Heard, ActedKey(e.Part, v.Module), func(_ []byte, found bool) ([]byte, bool, error) {
if found {
return nil, false, nil
}
return data, false, nil
}); err != nil {
ix.logf("versions fill: the act for %s is not kept: %v", v.Module, err)
}
}
}
}
@@ -3,7 +3,6 @@ package index
import (
"context"
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
@@ -115,88 +114,6 @@ func TestAVersionIsReleasedOnceEveryArtifactIsPublished(t *testing.T) {
}
}
// Design 47 G §372, A-350: the first fill records, once, each module's highest version the builder gave a number, numbered or
// published, over its artifacts as released and says versions-filled once; a builder_versions that does not answer holds it and, after five minutes, is the finding
// indexer-call-unanswered; a fill made is not made again.
func TestTheFirstFillOfTheVersionsComesFromTheBuildersNumbers(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC)
w := newFindings()
var filledSaid []meshcatalog.VersionsFilledEvent
ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Findings: w, Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now },
SayVersionsFilled: func(_ context.Context, e meshcatalog.VersionsFilledEvent, id string) error {
filledSaid = append(filledSaid, e)
return nil
}}
entries := map[string]meshcatalog.CatalogEntry{
"mesh-sdk": {Module: "mesh-sdk", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{
{Ref: "mesh-sdk:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mesh-sdk/go"}},
{Ref: "mesh-sdk:ts", Package: &meshcatalog.ArtifactPackage{Ecosystem: "npm", Name: "@novox/mesh-sdk"}}}},
"avahi": {Module: "avahi", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "avahi:image", Kind: "image"}}},
"fresh": {Module: "fresh", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "fresh:image", Kind: "image"}}},
}
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 3, Kind: "trunk"}, entries)
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
up := false
ask := func(_ context.Context, _, name string) (BuilderVersionsAnswer, error) {
if !up {
return BuilderVersionsAnswer{}, errors.New("no responders")
}
pub := func(v, d string) BuilderVersion {
return BuilderVersion{Version: v, State: "published", Digest: d, Revision: "9"}
}
switch name {
case "git.novox.be/novox/mesh-sdk/go":
return BuilderVersionsAnswer{Name: name, Versions: []BuilderVersion{pub("0.1.14", "sha256:go14"), {Version: "0.1.15", State: "refused"}}}, nil
case "@novox/mesh-sdk":
return BuilderVersionsAnswer{Name: name, Versions: []BuilderVersion{pub("0.1.18", "sha256:ts18")}}, nil
case "avahi/image":
// published 0.1.0, numbered up to 0.1.14 and never published (A-350): the fill starts above 0.1.14
return BuilderVersionsAnswer{Name: name, Versions: []BuilderVersion{pub("0.1.0", "sha256:av"), {Version: "0.1.14", State: "numbered", Revision: "9"}}}, nil
}
return BuilderVersionsAnswer{Name: name}, nil
}
if err := ix.FillVersions(ctx, ask); err == nil || len(filledSaid) != 0 {
t.Fatalf("a builder_versions unanswered filled: %v", err)
}
if len(w.Held()) != 0 {
t.Fatal("a call unanswered for no time wrote its finding")
}
now = now.Add(5 * time.Minute)
_ = ix.FillVersions(ctx, ask)
if h := w.Held(); len(h) != 1 || h[0].ID != BuilderVersionsCall {
t.Fatalf("the findings after five minutes: %+v", h)
}
up = true
if err := ix.FillVersions(ctx, ask); err != nil {
t.Fatal(err)
}
if len(w.Held()) != 0 {
t.Errorf("the finding stands after builder_versions answered: %+v", w.Held())
}
if len(filledSaid) != 1 || filledSaid[0].Modules != 2 {
t.Fatalf("versions-filled said %+v", filledSaid)
}
sdk, _ := ModuleVersions(ctx, ix.Versions, "mesh-sdk")
if len(sdk) != 1 || sdk[0].Version != "0.1.18" || len(sdk[0].Artifacts) != 1 || sdk[0].Artifacts[0].Artifact != "mesh-sdk:ts" || sdk[0].Source != 9 {
t.Errorf("mesh-sdk's filled version: %+v (the higher of Go's 0.1.14 and npm's 0.1.18)", sdk)
}
if avahi, _ := ModuleVersions(ctx, ix.Versions, "avahi"); len(avahi) != 1 || avahi[0].Version != "0.1.14" || len(avahi[0].Artifacts) != 1 || avahi[0].Artifacts[0].Digest != "" {
t.Errorf("avahi's filled version: %+v (numbered 0.1.14 above published 0.1.0, so the first G build of 0.1 is 0.1.15, with no digest where the builder kept none, A-351)", avahi)
}
if fresh, _ := ModuleVersions(ctx, ix.Versions, "fresh"); len(fresh) != 0 {
t.Errorf("a module with none published is filled: %+v", fresh)
}
if err := ix.FillVersions(ctx, ask); err != nil || len(filledSaid) != 1 {
t.Errorf("filled again: %v, said %d", err, len(filledSaid))
}
}
// Design 47 G §374, §375, A-68: a release records, per edge, the part it was built against (kind 1, from package-published's
// dependencies) or, once delivered, the delivered version it was ordered after (kinds 2 and 4); outdated answers an edge behind
// by the part's digest alone, with the act rebuild only for a stale edge; a newer version that left the digest as it was
@@ -432,69 +349,6 @@ func TestOutdatedAnswersKinds3And5And6(t *testing.T) {
}
}
// Design 47 G §377, A-78 c: the first fill gives each module's newest version its edge entries, each marked filled: kind 1 from the
// dependency version published latest before the build was claimed, kinds 2, 4 and 6 not yet delivered (H-A-82), kind 5 as acted for the running build; so the first outdated says only what is truly behind.
func TestTheFirstFillGivesTheNewestVersionsTheirFilledEdges(t *testing.T) {
ctx := context.Background()
t0 := time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC)
ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Revisions: newMemObjects(1 << 20), Now: func() time.Time { return t0 }}
entries := map[string]meshcatalog.CatalogEntry{
"lib": {Module: "lib", Manifest: map[string]any{}, Fp: "fp-lib", Artifacts: []meshcatalog.Artifact{{Ref: "lib:pkg", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "x/lib"}}}},
"actor": {Module: "actor", Manifest: map[string]any{}, Fp: "fp-actor", Artifacts: []meshcatalog.Artifact{{Ref: "actor:program"}}},
"prov": {Module: "prov", Manifest: map[string]any{}, Fp: "fp-prov", Artifacts: []meshcatalog.Artifact{{Ref: "prov:program"}}},
"app": {Module: "app", Manifest: map[string]any{}, Fp: "fp-app", Artifacts: []meshcatalog.Artifact{{Ref: "app:program"}},
Edges: []meshcatalog.Edge{{Kind: 1, From: "lib:pkg", To: "app:program", Part: "lib:pkg", Stale: true},
{Kind: 4, From: "prov:program", To: "app:program", Part: "prov:program"},
{Kind: 5, From: "actor:program", To: "app:program", Part: "actor:program"}}},
}
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 3, Kind: "trunk"}, entries)
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
ask := func(_ context.Context, _, name string) (BuilderVersionsAnswer, error) {
pub := func(v, d string, at time.Time) BuilderVersion {
return BuilderVersion{Version: v, State: "published", Digest: d, Revision: "9", At: at}
}
switch name {
case "x/lib":
// 0.1.1 numbered and not published still counts (A-350)
return BuilderVersionsAnswer{Versions: []BuilderVersion{{Version: "0.1.1", State: "numbered", Digest: "sha256:l1", Revision: "9", At: t0}, pub("0.1.2", "sha256:l2", t0.Add(2*time.Hour))}}, nil
case "app/program":
return BuilderVersionsAnswer{Versions: []BuilderVersion{pub("0.3.1", "sha256:a1", t0.Add(time.Hour))}}, nil
}
return BuilderVersionsAnswer{Versions: []BuilderVersion{pub("0.9.1", "sha256:"+name, t0)}}, nil
}
if err := ix.FillVersions(ctx, ask); err != nil {
t.Fatal(err)
}
app, _ := ModuleVersions(ctx, ix.Versions, "app")
if len(app) != 1 || len(app[0].Edges) != 3 {
t.Fatalf("app's filled version: %+v", app)
}
for _, e := range app[0].Edges {
if !e.Filled {
t.Errorf("a filled entry is not marked: %+v", e)
}
switch e.Kind {
case 1:
if e.Version != "0.1.1" || e.Digest != "sha256:l1" || !e.Stale {
t.Errorf("kind 1 is the version numbered or published before the build was claimed: %+v", e)
}
case 4:
if e.Version != notYetDelivered || e.Digest != "" { // H-A-82: a declaration, filled with no delivered version
t.Errorf("kind 4 is not yet delivered: %+v", e)
}
}
}
// lib's 0.1.2 was published after app's build was claimed: that is behind, and nothing else (the delivered kind 4 and the act of kind 5 are not)
if a, err := ix.Outdated(ctx, meshcatalog.OutdatedInput{}); err != nil || len(a.Behind) != 1 || a.Behind[0].Kind != 1 {
t.Errorf("outdated after the first fill: %+v, %v", a.Behind, err)
}
}
// Design 47 G §354, A-78 d: an input is also keyed by its run ask's id, so the build seat's step-ended of that ask deletes it, and
// the key by ask no other read counts as an input.
func TestAnInputIsDeletedAtTheStepEndedOfItsAsk(t *testing.T) {
@@ -200,7 +200,7 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
// ADR 0499 clauses 2 and 3, ADR 0495 clause 1; and the module directories of the trunk, issue 1900) and whether a
// commit is in another (issue 1900).
if want := []string{"seat:git.trees", "seat:git.file", "seat:git.contains", "seat:git.branch", "seat:mesh-delivery.source", "seat:mesh-module-assigner.assignments", "seat:mesh-module-assigner.placement", "seat:mesh-hand-acts.hand-act", "seat:mesh-watchdogs.presence", "seat:node-build-go.steps",
"seat:node-build-node.steps", "seat:node-build-image.steps", "mesh-delivery-builder.builder_versions"}; !reflect.DeepEqual(m.Invokes, want) {
"seat:node-build-node.steps", "seat:node-build-image.steps"}; !reflect.DeepEqual(m.Invokes, want) {
t.Errorf("invokes = %v, want %v", m.Invokes, want)
}
// 1945: the hand acts are served by its tools bundle through the takeins state; the process serves none. 1966/AC11: indexer_old_sections reads the count of the old sections (state oldsections).
+1 -2
View File
@@ -213,8 +213,7 @@
"seat:mesh-watchdogs.presence",
"seat:node-build-go.steps",
"seat:node-build-node.steps",
"seat:node-build-image.steps",
"mesh-delivery-builder.builder_versions"
"seat:node-build-image.steps"
],
"uses": [
"operator-channel"