A-376: the bus keeper makes the catalog half's own holder before the first views
Before the catalog half's first views are in (a read refused, or none-yet), the keeper reads the manifest on the trunk of the holder of the seat mesh-catalog from the seat's states modules and manifests (the holder from the seat that places modules) and makes its kept data as any module's, each entry said as ever; every other module waits as A-367 says. Builds: design 47 G A-376 (G-22-lead-answers-2.md) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
|
||||
"nats-tools/internal/keeper"
|
||||
)
|
||||
|
||||
// The keeper makes the kept data of the holder of the seat mesh-catalog before the catalog half's first views are in (design
|
||||
// 47 G A-376, completing A-367): that holder is the catalog half's own source and needs its kept data to answer them. Its
|
||||
// manifest on the trunk is read as the holder's first views `modules` (the manifest's digest by module) and `manifests` (the
|
||||
// manifest by digest) give it, both followed as the seat's states (views.ProcessReader.FollowSeat), and the holder is the
|
||||
// module the seat that places modules answers for the seat (seatlist.HolderOf): no module is named here.
|
||||
|
||||
// holderAccepted is what the holder's manifest on the trunk asks of the bus: the holder's entry of `modules` names its
|
||||
// manifest's digest, and `manifests` holds that manifest. An error says what is not yet in.
|
||||
func holderAccepted(holder string, modules, manifests map[string]json.RawMessage) (keeper.Accepted, error) {
|
||||
raw, ok := modules[holder]
|
||||
if !ok {
|
||||
return keeper.Accepted{}, fmt.Errorf("the first view `modules` holds no entry of %s yet", holder)
|
||||
}
|
||||
// Only the manifest's digest is read of the entry, so an entry whose fingerprint is not (yet) there still names it.
|
||||
var v struct {
|
||||
Manifest string `json:"manifest"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &v); err != nil {
|
||||
return keeper.Accepted{}, fmt.Errorf("the entry of %s in `modules` does not read: %w", holder, err)
|
||||
}
|
||||
if v.Manifest == "" {
|
||||
return keeper.Accepted{}, fmt.Errorf("the entry of %s in `modules` names no manifest", holder)
|
||||
}
|
||||
m, ok := manifests[v.Manifest]
|
||||
if !ok {
|
||||
return keeper.Accepted{}, fmt.Errorf("the first view `manifests` holds no manifest %s of %s yet", v.Manifest, holder)
|
||||
}
|
||||
var by catalog.ManifestsByDigestValue
|
||||
if err := json.Unmarshal(m, &by); err != nil {
|
||||
return keeper.Accepted{}, fmt.Errorf("the manifest %s of %s does not read: %w", v.Manifest, holder, err)
|
||||
}
|
||||
var manifest map[string]any
|
||||
if err := json.Unmarshal([]byte(by.Manifest), &manifest); err != nil {
|
||||
return keeper.Accepted{}, fmt.Errorf("the manifest %s of %s does not read: %w", v.Manifest, holder, err)
|
||||
}
|
||||
a, err := AsksOf(catalog.CatalogEntry{Module: holder, Manifest: manifest})
|
||||
if err != nil {
|
||||
return keeper.Accepted{}, err
|
||||
}
|
||||
return a.Accepted, nil
|
||||
}
|
||||
|
||||
// holder is the keeper's Holder: the seat's holder through the seat that places modules, its two states followed as the
|
||||
// seat's, nothing asked on a timer (the follows read the holder again at each change of a view the reader follows).
|
||||
func (f *catalogFollow) holder() (keeper.Accepted, error) {
|
||||
if f.holderModules == nil || f.holderManifests == nil {
|
||||
return keeper.Accepted{}, fmt.Errorf("the seat %s's states are not followed", catalog.Seat)
|
||||
}
|
||||
who, err := seatlist.HolderOf(f.call, catalog.Seat)
|
||||
if err != nil {
|
||||
return keeper.Accepted{}, err
|
||||
}
|
||||
return holderAccepted(who, f.holderModules.Follower().Values(), f.holderManifests.Follower().Values())
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
)
|
||||
|
||||
// TestHolderAcceptedReadsTheHoldersManifestFromItsFirstViews is design 47 G A-376: the entry the keeper makes before the catalog
|
||||
// half's first views are in is the bus state of the holder's manifest, read through `modules` (its digest) and `manifests`.
|
||||
func TestHolderAcceptedReadsTheHoldersManifestFromItsFirstViews(t *testing.T) {
|
||||
digest := meshcatalogclient.ManifestDigest([]byte(`{"module":"idx","bus-state":[{"name":"revisions","storage":"object-store","template":"objects","options":{"max-mib":8}}]}`))
|
||||
mod := func(d string) json.RawMessage { return json.RawMessage(`{"v":1,"manifest":"` + d + `"}`) }
|
||||
man := func(text string) json.RawMessage {
|
||||
b, _ := json.Marshal(map[string]any{"v": 1, "module": "idx", "manifest": text})
|
||||
return b
|
||||
}
|
||||
rows := []struct {
|
||||
name string
|
||||
modules, manifests map[string]json.RawMessage
|
||||
err string
|
||||
module string
|
||||
}{
|
||||
{"read", map[string]json.RawMessage{"idx": mod(digest)}, map[string]json.RawMessage{digest: man(`{"module":"idx","bus-state":[{"name":"revisions","storage":"object-store","template":"objects","options":{"max-mib":8}}]}`)}, "", "idx"},
|
||||
{"no entry of the holder yet", map[string]json.RawMessage{}, nil, "holds no entry of idx", ""},
|
||||
{"its manifest is not in yet", map[string]json.RawMessage{"idx": mod(digest)}, map[string]json.RawMessage{}, "holds no manifest", ""},
|
||||
{"an entry that names no manifest", map[string]json.RawMessage{"idx": mod("")}, nil, "names no manifest", ""},
|
||||
}
|
||||
for _, row := range rows {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
a, err := holderAccepted("idx", row.modules, row.manifests)
|
||||
if row.err != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), row.err) {
|
||||
t.Fatalf("err %v, want it to contain %q", err, row.err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil || a.Module != row.module || len(a.BusState) != 1 || a.BusState[0].Name != "revisions" {
|
||||
t.Fatalf("got %+v, %v", a, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func runKeeper(ctx context.Context, getenv func(string) string, logOut io.Writer
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
k.Catalog, k.Seats, k.Again = follow.view, follow.seats, follow.again
|
||||
k.Catalog, k.Seats, k.Again, k.Holder = follow.view, follow.seats, follow.again, follow.holder
|
||||
// The process answers the seat mesh-broker's snapshot verbs itself (design 47 G §681, A-107), with the caller the bus proved.
|
||||
stopAnswers, err := conn.AnswerSeat(meshbroker.Seat, seatlist.Definition(func() *seatlist.Reader { return follow.seatList }, meshbroker.Seat), snapshotAnswers(k, heldRequest(k.Store), keeperSnapshots(nc, logger.Printf)))
|
||||
if err != nil {
|
||||
@@ -259,11 +259,15 @@ type catalogFollow struct {
|
||||
branches *meshcatalogclient.Branches
|
||||
seatList *seatlist.Reader
|
||||
routes *eventRoutes
|
||||
// call asks a seat verb or a module tool as the keeper's account; holderModules and holderManifests are the seat
|
||||
// mesh-catalog's states `modules` and `manifests` (design 47 G A-376).
|
||||
call seatlist.HolderCaller
|
||||
holderModules, holderManifests *views.Picture
|
||||
}
|
||||
|
||||
// followCatalog wires the branch follower and the seat list, and asks their first views; moved is told of each change.
|
||||
func followCatalog(ctx context.Context, conn *process.Conn, writer views.WireWriter, moved func(), logf func(string, ...any)) (*catalogFollow, error) {
|
||||
f := &catalogFollow{ctx: ctx, routes: &eventRoutes{by: map[string]func(jetstream.Msg){}}}
|
||||
f := &catalogFollow{ctx: ctx, routes: &eventRoutes{by: map[string]func(jetstream.Msg){}}, call: conn.Call}
|
||||
f.reader = &views.ProcessReader{Module: keeper.Module, Call: conn.Call, Logf: logf, Findings: func() views.WireWriter { return writer }}
|
||||
branches, err := meshcatalogclient.FollowBranchesProcess(f.reader, conn.Call)
|
||||
if err != nil {
|
||||
@@ -283,6 +287,18 @@ func followCatalog(ctx context.Context, conn *process.Conn, writer views.WireWri
|
||||
if err != nil {
|
||||
logf("the seat list cannot be followed (%v): a module's sent store waits for it", err)
|
||||
}
|
||||
// The catalog half's own holder (design 47 G A-376): its states `modules` and `manifests`, whichever module holds the seat.
|
||||
holders := func(seat string) []string {
|
||||
if who, err := seatlist.HolderOf(f.call, seat); err == nil {
|
||||
return []string{who}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
for state, into := range map[string]**views.Picture{"modules": &f.holderModules, "manifests": &f.holderManifests} {
|
||||
if *into, err = f.reader.FollowSeat(catalog.Seat, state, holders); err != nil {
|
||||
logf("the seat %s's state %s cannot be followed (%v): its holder's kept data waits for the catalog half", catalog.Seat, state, err)
|
||||
}
|
||||
}
|
||||
f.reader.Ask(ctx, nil)
|
||||
return f, nil
|
||||
}
|
||||
|
||||
@@ -195,14 +195,16 @@ func TestTheBussManifestMountsItsProgramsIntoTheUpstreamImage(t *testing.T) {
|
||||
t.Errorf("claims are %+v: mesh-broker, serving its reading verbs %v and its snapshot verbs %v alone", nm.Claims, ReadingVerbs, SnapshotVerbs)
|
||||
}
|
||||
// The catalog half replaces manifest-accepted and indexer_bus_state (design 47 G §433, §614), and the seat list is read
|
||||
// through the seat mesh-catalog (§537).
|
||||
// through the seat mesh-catalog (§537); its holder's states modules and manifests, and the seat that places modules, are
|
||||
// read before the first views (A-376).
|
||||
catalogHalf := []string{"mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-delivery.source-moved",
|
||||
"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed"}
|
||||
"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "seat:mesh-catalog.views.modules", "seat:mesh-catalog.views.manifests"}
|
||||
if !slices.Equal(nm.Consumes, append(slices.Clone(catalogHalf), "mesh-conditions.findings-asked")) {
|
||||
t.Errorf("consumes %v: the catalog half's and the seat list's events %v, and the finding writer's findings-asked (design 47 G A-17)", nm.Consumes, catalogHalf)
|
||||
}
|
||||
for _, want := range []string{"seat:mesh-catalog.revision", "seat:mesh-catalog.registrations", "seat:mesh-delivery.source",
|
||||
"seat:mesh-catalog.seat-definitions", "seat:mesh-hand-acts.hand-act"} {
|
||||
"seat:mesh-catalog.seat-definitions", "seat:mesh-hand-acts.hand-act", "seat:mesh-catalog.modules", "seat:mesh-catalog.manifests",
|
||||
"seat:mesh-module-assigner.assignments"} {
|
||||
if !slices.Contains(nm.Invokes, want) {
|
||||
t.Errorf("invokes %v lack %s", nm.Invokes, want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user