The grants part takes a first view of every binding from the seat mesh-broker's list

At each start and on grants_first_view_again with state bindings, the part asks
list, writes the bindings the answer carries that it holds none of or another of,
keeps and raises binding-unlisted for those the answer omits, never writes over
an event heard since the ask, holds the seat's events until the answer or the
bound, and raises first-view-unanswered naming mesh-broker and list past two
minutes while composing as before. grants_first_views shows the first view
beside the others. Cases are rows and subtests of the existing tests.

Builds: design 25 bindings-first-view §1, §3, §4, §5, §6, §7, §8 (hq d0760629, PR 543)

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
2026-11-11 10:30:22 +01:00
parent 532e4d740f
commit fcfaa41348
10 changed files with 948 additions and 19 deletions
@@ -24,6 +24,7 @@ import (
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
"git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-grants/grantsstate"
@@ -216,6 +217,50 @@ func TestTheGrantsPartWhole(t *testing.T) {
t.Fatal(err)
}
}
// Design 25 bindings-first-view §8: the bus module answers the seat mesh-broker's list with an entry whose created was never
// said, once it is answering; until then the ask is refused as of a holder not yet connected.
var listing atomic.Bool
for _, subject := range []string{"mesh.seat.mesh-broker.call.list.>", "mesh.seat.mesh-broker.tool.list"} {
if _, err := nc.Subscribe(subject, func(m *nats.Msg) {
if !listing.Load() {
_ = m.Respond([]byte(`{"error":"not connected yet","node":"a"}`))
return
}
answer(m, map[string]any{"entries": []any{
map[string]any{"module": "mod-c", "local-name": "late", "storage-type": "key-value", "template": "state", "bus-name": "mod-c_late",
"settings": map[string]any{"mod-c_late": map[string]any{}},
"binding": map[string]any{"local": "late", "storage": "key-value", "template": "state", "bucket": "mod-c_late"}},
map[string]any{"module": "mod-c", "local-name": "waiting", "storage-type": "key-value", "template": "state", "bus-name": "mod-c_waiting",
"state": "waiting"},
}})
}); err != nil {
t.Fatal(err)
}
}
// The conditions the part said, by key, as last said.
conditionsSaid := func() map[string]string {
out := map[string]string{}
st, err := js.Stream(ctx, "CONDITIONS")
if err != nil {
return out
}
info, _ := st.Info(ctx)
for seq := info.State.FirstSeq; seq != 0 && seq <= info.State.LastSeq; seq++ {
raw, err := st.GetMsg(ctx, seq)
if err != nil {
continue
}
if c, err := occ.DecodeCondition(raw.Data); err == nil {
out[c.Key] = string(c.State)
}
}
return out
}
bindingsBoundAndWaits := func() {
bindingsTiming.bound, bindingsTiming.wait, bindingsTiming.max = 300*time.Millisecond, 50*time.Millisecond, 100*time.Millisecond
}
bindingsBoundAndWaits()
t.Cleanup(func() { bindingsTiming.bound, bindingsTiming.wait, bindingsTiming.max = 0, 0, 0 })
// A membership is never said on its subject any more (issue 1126).
var said atomic.Int32
if _, err := nc.Subscribe("mesh.assignment.>", func(*nats.Msg) { said.Add(1) }); err != nil {
@@ -241,7 +286,7 @@ func TestTheGrantsPartWhole(t *testing.T) {
return
}
}
t.Fatalf("never saw: %s", what)
t.Fatalf("never saw: %s\n%s", what, logged.tail("binding"))
}
until("every first view asked and refused once", func() bool { return refusedAsks.Load() >= int32(len(grants.FirstViews)) })
until("the part saying it waits on the indexer and the assigner", func() bool {
@@ -310,13 +355,42 @@ func TestTheGrantsPartWhole(t *testing.T) {
t.Fatal(err)
}
}
// With list unanswered the part has composed every account (mod-c's membership is above), says past its bound that the
// bindings' first view is unanswered, naming the seat and the verb, and applies the created heard meanwhile.
sayBroker("created", membership.BusBinding{Local: "kept", Storage: "key-value", Template: "state", Bucket: "mod-c_kept"})
until("mod-c's binding in its membership after created", func() bool {
until("mod-c's binding in its membership after created, list unanswered", func() bool {
b := bindingOf()
return len(b) == 1 && b[0].Bucket == "mod-c_kept"
})
until("first-view-unanswered raised for mesh-broker's list", func() bool {
return conditionsSaid()[grants.FirstViewUnanswered+".mesh-broker.bindings"] == "raised"
})
// The bus module answers: the entry whose created was never said gets its binding; the one the answer does not list (kept)
// stays and raises binding-unlisted; an entry listed without a binding changes nothing; the answer clears the first
// view's condition.
listing.Store(true)
until("the binding of the entry created never said, kept beside the one the answer does not list", func() bool {
b := bindingOf()
return len(b) == 2 && b[0].Bucket == "mod-c_kept" && b[1].Bucket == "mod-c_late"
})
until("binding-unlisted raised for the kept binding and first-view-unanswered cleared", func() bool {
said := conditionsSaid()
return said[grants.BindingUnlisted+".mod-c.kept"] == "raised" && said[grants.FirstViewUnanswered+".mesh-broker.bindings"] == "cleared" &&
said[grants.BindingUnlisted+".mod-c.late"] == "" && said[grants.BindingUnlisted+".mod-c.waiting"] == ""
})
// A person asks again by hand (state bindings): asked once more, the same answer changes nothing it holds.
askedAgain, _ := json.Marshal(grants.Ask{By: "jochen@shanks", At: time.Now(), FirstView: grants.FirstViewBindings})
if _, err := kvs[grants.Module+"."+grants.StateUserList].Put(ctx, grants.KeyAsked, askedAgain); err != nil {
t.Fatal(err)
}
until("the bindings asked once more by hand", func() bool {
return logged.has("the first view of the bindings (" + grants.CallBrokerList + ") once more by hand")
})
sayBroker("dropped", membership.BusBinding{Local: "kept"})
until("mod-c's binding gone after dropped", func() bool { return len(bindingOf()) == 0 })
until("mod-c's kept binding gone after dropped, its unlisted condition cleared", func() bool {
b := bindingOf()
return len(b) == 1 && b[0].Bucket == "mod-c_late" && conditionsSaid()[grants.BindingUnlisted+".mod-c.kept"] == "cleared"
})
for _, bucket := range []string{"mesh-controller_lease", grants.Module + "_lease", grants.Module + "_takeover"} {
if _, err := js.KeyValue(ctx, bucket); !errors.Is(err, jetstream.ErrBucketNotFound) {
t.Errorf("the bucket %s: %v, want none", bucket, err)
@@ -424,3 +498,16 @@ func (l *lockedLog) has(s string) bool {
defer l.mu.Unlock()
return strings.Contains(l.buf.String(), s)
}
// tail is the lines of the log that contain s, for a failure to name what the part said of it.
func (l *lockedLog) tail(s string) string {
l.mu.Lock()
defer l.mu.Unlock()
var out []string
for _, line := range strings.Split(l.buf.String(), "\n") {
if strings.Contains(line, s) {
out = append(out, line)
}
}
return strings.Join(out, "\n")
}
@@ -20,6 +20,7 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
@@ -60,6 +61,10 @@ func main() {
}
}
// bindingsTiming is the bound and the waits of the first view of the bindings; zero is the design's (two minutes; from ten
// seconds, doubling, at most five minutes: design 25 bindings-first-view §5). The whole-module test sets small ones.
var bindingsTiming struct{ bound, wait, max time.Duration }
// keptStates is what the part keeps (ADR 0495 §2-§3): each readable, for the view and a session, but the wanted accounts,
// by the vault alone (ADR 0561 §2).
func keptStates() []announce.State { return grants.Announced() }
@@ -131,6 +136,14 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
Objects: sealedObjects{ctx: ctx, js: js}, Purging: ownPurging{ctx: ctx, js: js, module: account.Module}, Logf: logger.Printf,
Bus: grants.BusAddress{URL: account.URL, Fingerprint: account.Fingerprint}}
f.Watch = fv
// The first view of the bindings (design 25 bindings-first-view): the seat mesh-broker's list, asked at each start and by
// hand, with the seat's events held until its answer is applied or its bound passes.
f.Part.Bindings = &grants.BindingsView{Say: sayCond, Changed: f.Wake, Logf: logger.Printf,
Bound: bindingsTiming.bound, Wait: bindingsTiming.wait, MaxWait: bindingsTiming.max,
Ask: func(context.Context) (json.RawMessage, error) {
return grants.Unwrapped(conn.Call)(grants.CallBrokerList, map[string]any{})
}}
f.Part.Bindings.Start(ctx, f.Part)
// The seat list: read over the connection and the hub, given to catalogue at every change, and a pass composes again then.
gate := &seatGate{}
gate.follow(seatlist.ProcessBus(conn.Call, hub), f.Wake, logger.Printf)
+5 -3
View File
@@ -236,13 +236,15 @@ func toolsOf(p *grants.Part) []stdio.Tool {
{Name: grants.ToolFirstViews, Description: "The grants part's first views of the owners' states (novox/hq ADR 0615 §4 to §6, " +
"ADR 0622): the assigner's assignments and wants, the indexer's manifests, modules and verdicts, each with its owner, tool " +
"and the revision its picture holds, when it asked and when it was answered, how many asks and hand acts, and whether " +
"its condition is raised, as the part's process last kept them. Read-only.",
"its condition is raised, as the part's process last kept them; and the first view of the bindings, asked of the seat " +
"mesh-broker's list: how many entries it listed, how many bindings it wrote and rewrote, and the bindings it found " +
"unlisted (design 25 bindings-first-view). Read-only.",
Run: func(map[string]any) (any, error) { return p.FirstViewsOf() }},
{Name: grants.ToolFirstViewAgain, Description: "Ask one of the grants part's first views once more now (assignments, wants, " +
"manifests, modules or verdicts; none for all), by a person's act with why, recorded as a hand act: the step after an " +
"manifests, modules, verdicts or bindings, the bus module's list of every entry's binding; none for all), by a person's act with why, recorded as a hand act: the step after an " +
"owner's state was written again from its sources (an empty answer at revision 0, condition " +
"mesh-grants.first-view-empty). Asks the part's process, which alone follows them; grants_first_views shows the answer.",
Input: schema(map[string]string{"state": "assignments, wants, manifests, modules or verdicts; none for all", "why": "why, kept in the hand act"}, "why"),
Input: schema(map[string]string{"state": "assignments, wants, manifests, modules, verdicts or bindings; none for all", "why": "why, kept in the hand act"}, "why"),
Run: func(a map[string]any) (any, error) {
return p.AskFirstViewAgain(stdio.CallerOf(a), grants.Answer(a, "state"), grants.Answer(a, "why"), recordHandAct)
}},