Area 7 part 1 (join 11): the assigner's bed takes every seat's events on EVENTS and answers the seat list
The bed's kept streams (running, machine-away, machine-back, version-delivered) took subjects of their own, so a test that widened EVENTS met "subjects overlap". They now source EVENTS' messages of their subject, as the grants part makes them (KeptEvent.StreamConfig), and EVENTS takes mesh.seat.*.event.>. The bed answers the seat mesh-catalog's seat-definitions from mesh-sdk's seatlisttest copy and its verb entry from the catalog half, so the seat server admits a caller once the list is read (A-278). The composition step test calls input on its subject naming the caller (A-179) and waits for the seat list read and the sourced running messages. TestTheCompositionStepComposesEachMachineThroughTheBuildSeat passes; TestWantsAreWrittenAndNoDifferenceIs still fails (rule 7: web on ace held on an unread catalog entry). Builds: design 47 G §354, §610, A-179, A-278 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
+9
-21
@@ -38,38 +38,20 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T)
|
||||
}
|
||||
t.Cleanup(nc.Close)
|
||||
const engineCommit = "1111111111111111111111111111111111111111"
|
||||
// What each node runs is the node-engine seat's own stream, kept last per subject (§199): the bed's EVENTS takes every seat's
|
||||
// events, so here it takes those of the seats this case hears and says, the node-engine's reads changed among them, and not
|
||||
// what each node runs.
|
||||
if err := b.js.DeleteStream(b.ctx, "EVENTS"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var seatEvents []string
|
||||
for _, seat := range []string{"mesh-catalog", "mesh-wants", "mesh-module-assigner", "node-build-go", "mesh-watchdogs", "mesh-delivery", "mesh-pipeline-runner", "mesh-conditions", "operator-channel"} {
|
||||
seatEvents = append(seatEvents, "mesh.seat."+seat+".event.>")
|
||||
}
|
||||
if _, err := b.js.CreateStream(b.ctx, jetstream.StreamConfig{Name: "EVENTS", Subjects: append([]string{"mesh.mod.*.event.>", enginereads.SubjectPrefix + "*"}, seatEvents...)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The assigner's durable on EVENTS hears, beside the bed's, the build seat's step-ended and the watchman's machine-away and
|
||||
// machine-back, as the grants part derives them from its consumes; and what each node runs, kept last per subject.
|
||||
// machine-back, as the grants part derives them from its consumes; what each node runs it hears on its kept stream (the bed's).
|
||||
if _, err := b.js.CreateOrUpdateConsumer(b.ctx, "EVENTS", jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-assigner",
|
||||
FilterSubjects: []string{enginereads.SubjectPrefix + "*", "mesh.mod." + buckets.IndexerModule + ".event.views.>", meshcatalog.SubjectCatalogRevisionAll,
|
||||
nodebuildgo.SubjectStepEndedAll, meshwatchdogs.SubjectMachineAwayAll, meshwatchdogs.SubjectMachineBackAll}, AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := b.js.CreateStream(b.ctx, jetstream.StreamConfig{Name: nodeengine.StreamRunning, Subjects: []string{nodeengine.SubjectRunningAll}, MaxMsgsPerSubject: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := b.js.CreateOrUpdateConsumer(b.ctx, nodeengine.StreamRunning, jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-assigner", AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, node := range []string{"n1", "n2"} {
|
||||
raw, _ := json.Marshal(nodeengine.Running{V: 1, Node: node, Module: "engine", Fingerprint: "src2:e1", At: time.Now().UTC()})
|
||||
if _, err := b.js.Publish(b.ctx, nodeengine.SubjectRunning(node, "engine"), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
awaitKept(t, b, nodeengine.StreamRunning, 2)
|
||||
away, _ := json.Marshal(meshwatchdogs.MachineAwayEvent{V: 1, Machine: "n3", At: time.Now().UTC(), LastHeard: time.Now().UTC()})
|
||||
if _, err := b.js.Publish(b.ctx, meshwatchdogs.SubjectMachineAway("n3"), away); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -126,6 +108,11 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T)
|
||||
b.journal.await(t, from, "the composition step is heard on", "the composition step served", 30*time.Second)
|
||||
b.journal.await(t, from, "n3 is away (machine-away)", "the machine-away of n3 heard", 30*time.Second)
|
||||
|
||||
select {
|
||||
case <-b.seatListRead: // the seat server admits a caller of input once the seat list is read (A-278)
|
||||
case <-time.After(30 * time.Second):
|
||||
t.Fatal("the assigner did not read the seat list within 30 s")
|
||||
}
|
||||
step, _ := json.Marshal(meshwants.StepRun{Pipeline: "main.3.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch,
|
||||
Revision: 3, Commit: engineCommit, Fingerprint: "src2:m1"})
|
||||
msg := nats.NewMsg(meshwants.AcceptSubjectStep)
|
||||
@@ -207,7 +194,8 @@ func readInput(t *testing.T, nc *nats.Conn, in buildstep.RunInput) []byte {
|
||||
}
|
||||
defer sub.Unsubscribe()
|
||||
body, _ := json.Marshal(meshwants.InputInput{Digest: in.Digest, Call: call})
|
||||
reply, err := nc.Request("mesh.seat.mesh-wants.tool.input", body, 10*time.Second)
|
||||
// On the call's subject naming its caller, the stand-in build seat's account: the seat server admits no unproven caller (A-179).
|
||||
reply, err := nc.Request("mesh.seat.mesh-wants.call.input.n1~mesh-build-go", body, 10*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist/seatlisttest"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient/enginereads"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
@@ -65,11 +67,13 @@ import (
|
||||
// bed is an embedded bus with JetStream, every bucket the assigner reads and keeps, and the stream the mesh's events
|
||||
// are kept in, as the controller's broker raises them.
|
||||
type bed struct {
|
||||
srv *server.Server
|
||||
js jetstream.JetStream
|
||||
ctx context.Context
|
||||
dir string
|
||||
buckets map[string]jetstream.KeyValue
|
||||
// seatListRead is closed once the assigner read the seat list (serveSeatList).
|
||||
seatListRead <-chan struct{}
|
||||
srv *server.Server
|
||||
js jetstream.JetStream
|
||||
ctx context.Context
|
||||
dir string
|
||||
buckets map[string]jetstream.KeyValue
|
||||
// placed is, by node, the modules the bed's assignments names on it (place).
|
||||
placed map[string][]string
|
||||
// journal is what the programs the bed starts write in their journal.
|
||||
@@ -179,11 +183,13 @@ func startBed(t *testing.T, leaveOut string) *bed {
|
||||
Subjects: []string{buscompose.LogSubject(builds.BuilderModule, builds.BuilderLog) + ".>"}, AllowDirect: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "EVENTS", Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.mesh-catalog.event.>", "mesh.seat.mesh-conditions.event.>", "mesh.seat.mesh-module-assigner.event.>", enginereads.SubjectPrefix + "*"}}); err != nil {
|
||||
// EVENTS takes every module's and every seat's events, as the mesh's shared stream does; a seat's kept event has a stream of
|
||||
// its own that takes no subject but sources EVENTS' messages of it (keptStream), so no two streams take one subject.
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "EVENTS", Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.*.event.>"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The node-engine seat's stream of `running`, kept last per subject, which the assigner hears the health of what runs from (§520).
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: nodeengine.StreamRunning, Subjects: []string{nodeengine.SubjectRunningAll}, MaxMsgsPerSubject: 1}); err != nil {
|
||||
if _, err := js.CreateStream(ctx, keptStream(nodeengine.StreamRunning, nodeengine.SubjectRunningAll, jetstream.StreamConfig{MaxMsgsPerSubject: 1})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, nodeengine.StreamRunning, jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-assigner", AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
@@ -193,7 +199,7 @@ func startBed(t *testing.T, leaveOut string) *bed {
|
||||
// first message at its start and then follows through its durable (design 47 G §376, §389, A-189, A-233).
|
||||
for _, k := range []struct{ stream, subject string }{{wd.StreamMachineAway, wd.SubjectMachineAwayAll}, {wd.StreamMachineBack, wd.SubjectMachineBackAll},
|
||||
{meshwants.StreamVersionDelivered, meshwants.SubjectVersionDelivered}} {
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: k.stream, Subjects: []string{k.subject}, MaxAge: 90 * 24 * time.Hour}); err != nil {
|
||||
if _, err := js.CreateStream(ctx, keptStream(k.stream, k.subject, jetstream.StreamConfig{MaxAge: 90 * 24 * time.Hour})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, k.stream, jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-assigner", AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
@@ -231,6 +237,8 @@ func startBed(t *testing.T, leaveOut string) *bed {
|
||||
serveTeller(t, b, nc)
|
||||
// The seat mesh-catalog's catalog half (design 47 G §194), which the assigner follows per branch.
|
||||
serveCatalog(t, b, nc)
|
||||
// The seat list (ADR 0636), which the assigner's seat server checks its verbs' callers against (A-278).
|
||||
b.seatListRead = serveSeatList(t, nc)
|
||||
// The assigner's views family is its ordinary events on EVENTS (ADR 0635 §5); its marks are its state.
|
||||
if kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: marksBucket, History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -2016,6 +2024,31 @@ func serveCatalog(t *testing.T, b *bed, nc *nats.Conn) {
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
}
|
||||
// The verb entry answers an entry by its fingerprint from every branch's half, and a fingerprint no half holds as not found,
|
||||
// as the seat's holder does: an entry the assigner asks for a form change is answered, never left asked (orderwaits.go).
|
||||
entry := func(m *nats.Msg) {
|
||||
var in meshcatalog.EntryInput
|
||||
_ = json.Unmarshal(m.Data, &in)
|
||||
b.cat.mu.Lock()
|
||||
defer b.cat.mu.Unlock()
|
||||
for _, half := range b.cat.entries {
|
||||
for _, e := range half {
|
||||
if e.Fp == in.Fingerprint {
|
||||
raw, _ := json.Marshal(map[string]any{"result": meshcatalog.EntryAnswer{Entry: e}, "node": "n0"})
|
||||
_ = m.Respond(raw)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
_ = m.Respond([]byte(`{"error":"no catalog entry has the fingerprint ` + in.Fingerprint + `","node":"n0"}`))
|
||||
}
|
||||
for _, subject := range []string{"mesh.seat.mesh-catalog.tool.entry", "mesh.seat.mesh-catalog.call.entry.*"} {
|
||||
sub, err := nc.Subscribe(subject, entry)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
}
|
||||
subscribed(t, nc)
|
||||
}
|
||||
|
||||
@@ -2067,3 +2100,76 @@ func mustEncodeBuild(t *testing.T, b builds.BuilderBuild) []byte {
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
// keptStream is a seat's kept event's stream as the grants part makes it (mesh-grants buscompose KeptEvent.StreamConfig): no
|
||||
// subject of its own, sourcing the shared EVENTS' messages of the event's subject, with cfg's limits.
|
||||
func keptStream(name, subject string, cfg jetstream.StreamConfig) jetstream.StreamConfig {
|
||||
cfg.Name = name
|
||||
cfg.Sources = []*jetstream.StreamSource{{Name: "EVENTS", FilterSubject: subject}}
|
||||
return cfg
|
||||
}
|
||||
|
||||
// awaitKept returns once the kept stream holds n messages, which it sources from EVENTS a moment after they are said.
|
||||
func awaitKept(t *testing.T, b *bed, stream string, n uint64) {
|
||||
t.Helper()
|
||||
st, err := b.js.Stream(b.ctx, stream)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for deadline := time.Now().Add(20 * time.Second); ; time.Sleep(20 * time.Millisecond) {
|
||||
if i, err := st.Info(b.ctx); err == nil && i.State.Msgs >= n {
|
||||
return
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("%s holds fewer than %d messages after 20 s", stream, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// serveSeatList answers the seat mesh-catalog's verb seat-definitions as the indexer does (ADR 0636 §4): with no seat, every
|
||||
// trunk seat with its digest; with one, its definition resolved, from the mesh-sdk test copy of every definition. The channel
|
||||
// it answers is closed once every listed seat's definition was asked, the end of a reader's first read.
|
||||
func serveSeatList(t *testing.T, nc *nats.Conn) <-chan struct{} {
|
||||
t.Helper()
|
||||
var mu sync.Mutex
|
||||
asked, read := map[string]bool{}, make(chan struct{})
|
||||
defs := map[string]json.RawMessage{}
|
||||
var listing seatlist.Listing
|
||||
for _, d := range seatlisttest.Definitions() {
|
||||
raw, _ := json.Marshal(d)
|
||||
defs[d.Seat] = raw
|
||||
listing.Seats = append(listing.Seats, seatlist.Entry{Seat: d.Seat, Source: seatlist.SourceTrunk, Digest: fmt.Sprintf("%x", len(raw))})
|
||||
}
|
||||
listing.Revision = 1
|
||||
answer := func(m *nats.Msg) {
|
||||
var in struct {
|
||||
Seat string `json:"seat"`
|
||||
}
|
||||
_ = json.Unmarshal(m.Data, &in)
|
||||
var result any = listing
|
||||
if in.Seat != "" {
|
||||
mu.Lock()
|
||||
if !asked[in.Seat] {
|
||||
if asked[in.Seat] = true; len(asked) == len(defs) {
|
||||
close(read)
|
||||
}
|
||||
}
|
||||
mu.Unlock()
|
||||
a := seatlist.Answer{Seat: in.Seat, Revision: 1}
|
||||
if raw, ok := defs[in.Seat]; ok {
|
||||
a.Found, a.Entry = true, &seatlist.Entry{Seat: in.Seat, Source: seatlist.SourceTrunk, Digest: fmt.Sprintf("%x", len(raw)), Definition: raw}
|
||||
}
|
||||
result = a
|
||||
}
|
||||
raw, _ := json.Marshal(map[string]any{"result": result, "node": "n0"})
|
||||
_ = m.Respond(raw)
|
||||
}
|
||||
for _, subject := range []string{"mesh.seat." + seatlist.Seat + ".tool." + seatlist.Verb, "mesh.seat." + seatlist.Seat + ".call." + seatlist.Verb + ".*"} {
|
||||
sub, err := nc.Subscribe(subject, answer)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
}
|
||||
return read
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user