G1 (in progress): the grants part reads no callers and no verdicts

Every account may call every verb: the grants part reads no definition's
callers (callerOf, the verb and accept callers, admits) and grants every
module's account every verb of every seat (mesh.seat.*.tool.> and its
caller-named form), a sent store to every module invoking a verb of its
claimant's seat, and every queue's named ask to every asker. grants_callers
goes; grants_why_refused answers the bus's own verdict. The indexer keeps
no verdicts: their first view, events, invoke and the engine's read go, and
a want names its build alone (no newest). internal/... and cmd/... tests are
green; the root package's grants_test.go still reads the verdicts (rows at
grants_test.go:303-307, 741, 1184, 3700-3870, 4560-4615) and does not compile.

Builds: design 47 H §745, §750, §752, §764 (every seat contract: the callers lists); lead answers H-A-37, H-A-66, H-A-79, H-A-113 (hq f599b761)

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-20 04:28:04 +01:00
parent f8eea0000a
commit 6b43adafca
24 changed files with 114 additions and 536 deletions
+3 -21
View File
@@ -39,7 +39,6 @@ import (
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/announce"
@@ -123,7 +122,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
}
bus := newBusReader(ctx, js)
// The module has one durable consumer of EVENTS: one hub pulls it and hands each message to the part that hears it (the
// owners' views events, the seat mesh-catalog's verdicts and seat list events, the other seats' events the follower hears),
// owners' views events, the seat mesh-catalog's seat list events, the other seats' events the follower hears),
// started once all are registered.
hub := process.NewEventHub(logger.Printf)
defer hub.Stop()
@@ -233,19 +232,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
f.ConsumerMade(ctx, created)
}
})
// The seat mesh-catalog's verdict events go to the verdicts' first view (ADR 0622 §2), which takes each at its revision.
for _, event := range []string{meshcatalog.EventManifestAccepted, meshcatalog.EventManifestRefused} {
if err := hub.Handle("mesh.seat."+meshcatalog.Seat+".event."+event, func(m jetstream.Msg) {
if err := fv.HearVerdict(ctx, strings.TrimPrefix(m.Subject(), "mesh.seat."+meshcatalog.Seat+".event."), m.Data(), logger.Printf); err != nil {
logger.Printf("views: %s is not a verdict event, dropped: %v", m.Subject(), err)
_ = m.Term()
return
}
_ = m.Ack()
}); err != nil {
return err
}
}
// The other seats' events the part follows its passes by (Consumes).
for _, subject := range grants.SeatEventSubjects() {
if err := hub.Handle(subject, func(m jetstream.Msg) {
@@ -369,13 +355,9 @@ func hearRunning(ctx context.Context, account process.Account, js jetstream.JetS
// list holds, which the part makes each kept event's stream from.
type seatGate struct{ *seatlist.Part }
// seatListAgainCallers may read the seat list again (ADR 0636 §7): every operator's session and the healers. A call through
// the mesh MCP server is proved only as its machine's tool runner (<node>.node-tools, issue 627), so node-tools stands for an
// operator's session until a session is proved (issue 1966).
var seatListAgainCallers = []string{stdio.AnyPerson, "node-tools", "mesh-healers"}
// newSeatGate's seat-list tools are open to every caller (design 47 H §752, H-A-66).
func newSeatGate() *seatGate {
return &seatGate{seatlist.NewPart("grants", seatListAgainCallers)}
return &seatGate{seatlist.NewPart("grants")}
}
// Definitions are the seat definitions the reader holds; none before it has started.
+4 -10
View File
@@ -240,17 +240,17 @@ func toolsOf(p *grants.Part) []stdio.Tool {
return p.AcceptHashes(stdio.CallerOf(a), users, grants.Answer(a, "why"))
}},
{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 " +
"ADR 0622): the assigner's assignments and wants, the indexer's manifests and modules, 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; 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, 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 " +
"manifests, modules 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, verdicts or bindings; none for all", "why": "why, kept in the hand act"}, "why"),
Input: schema(map[string]string{"state": "assignments, wants, manifests, modules 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)
}},
@@ -258,14 +258,8 @@ func toolsOf(p *grants.Part) []stdio.Tool {
"composed yet by this version of the part, with its step, the acting part, its version, since when, its bound (10 minutes) and " +
"clock-from (the start of this version's first pass), and which have passed their bound. Read-only.",
Run: func(map[string]any) (any, error) { return p.WaitsOf() }},
{Name: grants.ToolCallers, Description: "The callers each verb and each accepted kind of the seat definitions admits (design 47 G §83): " +
"the list the definition names, or the default of the verb's class. Name a seat, or a seat and a verb, or neither for every one. Read-only.",
Input: schema(map[string]string{"seat": "a seat's name (default: every seat)", "verb": "a verb or accepted kind (default: every one)"}),
Run: func(a map[string]any) (any, error) {
return p.Callers(grants.Answer(a, "seat"), grants.Answer(a, "verb"))
}},
{Name: grants.ToolWhyRefused, Description: "Why an account's call of a seat's verb is refused (design 47 G §83): the call subject the account " +
"lacks a grant for (the bus's own answer, nats_user_can) and the definition's callers that leave it out. Read-only.",
"lacks a grant for, the bus's own answer (nats_user_can); every account may call every verb (design 47 H §752). Read-only.",
Input: schema(map[string]string{"account": "the bus user, e.g. g14.node-tools", "verb": "the verb as <seat>.<verb>", "node": "the node, for a node seat"}, "account", "verb"),
Run: func(a map[string]any) (any, error) {
return p.WhyRefused(grants.Answer(a, "account"), grants.Answer(a, "verb"), grants.Answer(a, "node"))
@@ -27,10 +27,10 @@ func ComposedReads(node string) ([]string, error) {
return append(out, CandidateReads...), nil
}
// CandidateReads is what a node's engine is granted of the indexer's candidates and manifest verdicts to answer
// `compose-candidate` (ADR 0593 §7, ADR 0578 §3): each bucket read whole as the builder's builds are (a key is read
// through a short consumer), never written.
var CandidateReads = append(readGrants(CandidatesBucket, ""), readGrants(VerdictsBucket, "")...)
// CandidateReads is what a node's engine is granted of the indexer's candidates to answer `compose-candidate` (ADR 0593
// §7): the bucket read whole as the builder's builds are (a key is read through a short consumer), never written. The
// indexer keeps no verdicts (design 47 H-A-79).
var CandidateReads = readGrants(CandidatesBucket, "")
// EngineComposedBuckets are the composition buckets of every node, as the node-engine's state (ADR 0593 §6): the grants
// part creates each, create-only, with the history ADR 0539 clause 4 keeps (ComposedHistory), as it creates a
@@ -8,12 +8,7 @@ import (
// Design 47 G §543, §544, §600: a build seat's ask names its asker and each queue has a named worker beside main's; any module may
// put any ask (principle 6, the operator 2026-11-15).
func TestNamedAsks(t *testing.T) {
build := Seat{Name: "node-build-go", Scope: "node", Accepts: []string{"delivery", "check", "recheck"}, PulledByKind: true,
AcceptCallers: map[string][]string{
"delivery": {"mesh-builds"},
"check": {"mesh-pipeline-runner", "mesh-catalog", "mesh-delivery-checker"},
"recheck": {"mesh-delivery-checker"},
}}
build := Seat{Name: "node-build-go", Scope: "node", Accepts: []string{"delivery", "check", "recheck"}, PulledByKind: true}
asker := func(module string, held ...string) Principal {
p := Principal{Kind: KindModule, Node: "one", Module: module, Uses: []Seat{build}}
for _, h := range held {
@@ -70,47 +65,26 @@ func TestNamedAsks(t *testing.T) {
}
}
// Design 47 G §610, A-179 (test 60's case of §271): a user of a seat is granted a verb's call subject only where the verb's
// effective callers name it, so a kept-artifact call is composed for the module that invokes it and for no other user of
// the build seat; `module:` and `seat:` entries name theirs, and a seat whose definition is unread grants its users no verb.
func TestAVerbIsGrantedToItsEffectiveCallersAlone(t *testing.T) {
build := Seat{Name: "node-build-go", Scope: "node", Serves: []string{"kept-artifact", "freed", "run"},
VerbCallers: map[string][]string{
"kept-artifact": {"invokers", "persons", "sessions"},
"freed": {"module:a-checker"},
"run": {"seat:mesh-pipeline-runner"},
}}
user := func(module string, invokes []string, held ...string) Principal {
p := Principal{Kind: KindModule, Node: "one", Module: module, Uses: []Seat{build}, Invokes: invokes}
for _, h := range held {
p.Holds = append(p.Holds, Seat{Name: h})
}
return p
}
unread := build
unread.VerbCallers = nil
const base = "mesh.seat.node-build-go.tool."
for _, c := range []struct {
who Principal
want map[string]bool
}{
{user("an-invoker", []string{"seat:node-build-go.kept-artifact"}), map[string]bool{
base + "kept-artifact.ace": true, base + "freed.ace": false, base + "run.ace": false}},
{user("a-runner", nil, "mesh-pipeline-runner"), map[string]bool{
base + "kept-artifact.ace": false, base + "freed.ace": false, base + "run.ace": true}},
{user("a-checker", nil), map[string]bool{base + "kept-artifact.ace": false, base + "freed.ace": true}},
{Principal{Kind: KindModule, Node: "one", Module: "a-checker", Uses: []Seat{unread}}, map[string]bool{
base + "freed.ace": false, base + "kept-artifact.ace": false}},
} {
perms, err := PermissionsFor(c.who)
// Design 47 H §752, H-A-113 (2): every module's account may call every verb of every seat, invoked or not, in its own name,
// so no definition's callers withhold one; another account's name it may not take.
func TestEveryModuleMayCallEveryVerb(t *testing.T) {
build := Seat{Name: "node-build-go", Scope: "node", Serves: []string{"kept-artifact", "freed", "run"}}
invoker := Principal{Kind: KindModule, Node: "one", Module: "an-invoker", Uses: []Seat{build}, Invokes: []string{"seat:node-build-go.kept-artifact"}}
stranger := Principal{Kind: KindModule, Node: "one", Module: "a-stranger"}
for _, who := range []Principal{invoker, stranger} {
perms, err := PermissionsFor(who)
if err != nil {
t.Fatal(err)
}
for subject, want := range c.want {
if got := MayPublish(perms, subject); got != want {
t.Errorf("%s may publish %s: %v, want %v", c.who.Module, subject, got, want)
for _, subject := range []string{"mesh.seat.node-build-go.tool.freed.ace", "mesh.seat.node-build-go.tool.run",
"mesh.seat.mesh-wants.tool.upgrade", "mesh.seat.mesh-wants.call.upgrade." + CallerToken(who.Username())} {
if !MayPublish(perms, subject) {
t.Errorf("%s may not publish %s", who.Module, subject)
}
}
if MayPublish(perms, "mesh.seat.mesh-wants.call.upgrade.someone~else") {
t.Errorf("%s may call in another's name", who.Module)
}
}
}
@@ -144,8 +118,7 @@ func TestTheGrantsPartAlonePurgesTheNamedAsks(t *testing.T) {
// holder is granted the verb's subject without the machine (tool and call forms) beside its machine's, and a caller of the
// verb may publish on it; a verb of a seat held once for the mesh gains nothing, and a stranger is granted nothing.
func TestANodeSeatVerbIsAlsoGrantedWithoutTheMachine(t *testing.T) {
build := Seat{Name: "node-build-go", Scope: "node", Serves: []string{"steps"},
VerbCallers: map[string][]string{"steps": {"invokers"}}}
build := Seat{Name: "node-build-go", Scope: "node", Serves: []string{"steps"}}
holder := Principal{Kind: KindModule, Node: "shanks", Module: "mesh-build-go", Holds: []Seat{build}}
caller := Principal{Kind: KindModule, Node: "shanks", Module: "an-indexer", Uses: []Seat{build},
Invokes: []string{"seat:node-build-go.steps"}}
@@ -165,7 +138,7 @@ func TestANodeSeatVerbIsAlsoGrantedWithoutTheMachine(t *testing.T) {
{"caller asks the node-less tool", caller, tool, false, true},
{"caller asks a machine's", caller, tool + ".shanks", false, true},
{"caller asks the node-less call in its name", caller, call + CallerToken(caller.Username()), false, true},
{"stranger asks the node-less tool", stranger, tool, false, false},
{"stranger asks the node-less tool: every account may call every verb (design 47 H §752)", stranger, tool, false, true},
} {
perms, err := PermissionsFor(c.who)
if err != nil {
@@ -28,7 +28,6 @@ const (
CandidatesBucket = IndexerModule + "_candidates"
ModulesBucket = IndexerModule + "_modules"
ManifestsBucket = IndexerModule + "_manifests"
VerdictsBucket = IndexerModule + "_verdicts"
EnrolmentsState = "enrolments"
EnrolmentsBucket = EnrolmentModule + "_" + EnrolmentsState
@@ -36,7 +36,6 @@ func namesAreTheManifests(t *testing.T) {
{"invokes", AssignerModule + ".wants", AssignerWantsBucket},
{"invokes", IndexerModule + ".modules", ModulesBucket},
{"invokes", IndexerModule + ".manifests", ManifestsBucket},
{"invokes", IndexerModule + ".verdicts", VerdictsBucket},
} {
list := m.Reads
if c.list == "invokes" {
@@ -28,7 +28,6 @@ import (
sdkbc "git.novox.be/novox/mesh-sdk/go/buscompose"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/membership"
"git.novox.be/novox/mesh-sdk/go/seatdef"
)
// A Kind is what a principal is, which decides the shape of its authority rather than its
@@ -107,15 +106,6 @@ type Seat struct {
// PulledByKind says each accepted kind is a worker of its own on the seat's queue, filtered to that kind, which
// every holder pulls in the order Accepts lists them: the build seats' (novox/hq ADR 0525 §2, ADR 0536 §4).
PulledByKind bool
// AcceptCallers are, for a seat pulled by kind, the seats that may ask each of its queues, by queue: the `seat:<seat>`
// entries of the callers of the accepted kinds the definition puts on that queue (design 47 G §543, §600). The asker
// in a named ask's subject is the asking seat's name (A-163). Empty where the seat list is unread.
AcceptCallers map[string][]string
// VerbCallers are, by verb, the callers each verb the seat serves admits: its definition's effective list
// (seatdef.Verb.EffectiveCallers, the class defaults of design 47 G §610). A user of the seat is granted a verb's call
// subject only where that list names it (A-179), so the bus holds every other caller out. Empty where the seat list is
// unread, and then no verb of the seat is granted to its users.
VerbCallers map[string][]string
// NoNamedAsks says no entry of the revision invokes a queue of a build seat (`seat:<seat>.accept.<queue>`), so its queues
// have no named worker: the grants part purges their named asks and deletes those workers (design 47 G §544, A-231).
NoNamedAsks bool
@@ -804,6 +794,10 @@ const StreamNamesSubject = "$JS.API.STREAM.NAMES"
// G on dropping fine-grained permissions decides the whole shape). A seat's events and its verbs keep their own rules.
const AnySeatSubject = "mesh.seat.*.accept.>"
// anySeatVerbSubject is every verb of every seat, in each of its subjects (with a machine and without): every account may call
// every verb (design 47 H §752, H-A-113 (2)).
const anySeatVerbSubject = "mesh.seat.*.tool.>"
func permissionsFor(p Principal) (Permissions, error) {
for _, part := range []struct{ what, value string }{
{"node", p.Node}, {"module", p.Module}, {"process", p.Process},
@@ -1211,12 +1205,13 @@ func permissionsFor(p Principal) (Permissions, error) {
pub = append(pub, seatSubject(s, "accept", a))
}
for _, t := range s.Serves {
// Only a verb whose effective callers name this module (design 47 G A-179, §610).
if callerOf(p, s, t) {
pub = append(pub, seatToolSubjects(s, t, "*")...)
}
// Every verb the seat serves: every account may call every verb (design 47 H §752, H-A-66).
pub = append(pub, seatToolSubjects(s, t, "*")...)
}
}
// And every verb of every seat, invoked or not: every module's account may call every verb (design 47 H §752, H-A-113
// (2)); its caller-named form is derived below with the others.
pub = append(pub, anySeatVerbSubject)
// 4a. The ends of its calls of a marked verb, on the seat's gated-ended, its own alone (design 47 G §677, A-264).
gp, gs := gatedEndedGrants(p.Username(), p.MarkedVerbs, p.Invokes, p.AnswersSeat)
pub, sub = append(pub, gp...), append(sub, gs...)
@@ -1518,27 +1513,6 @@ func seatSubject(s Seat, kind, verb string) string {
return "mesh.seat." + s.Name + "." + kind + "." + verb
}
// callerOf says whether a verb's effective callers (Seat.VerbCallers) name the module principal p: `invokers` where its
// manifest invokes the verb (`seat:<seat>.<verb>`, or every tool by `*`), `module:<module>` naming it, or `seat:<seat>`
// naming a seat it holds (design 47 G §336, §610, A-179). `operator`, `persons` and `sessions` name no module.
func callerOf(p Principal, s Seat, verb string) bool {
for _, c := range s.VerbCallers[verb] {
switch {
case c == seatdef.CallerInvokers:
if slices.Contains(p.Invokes, "*") || slices.Contains(p.Invokes, "seat:"+s.Name+"."+verb) {
return true
}
case c == seatdef.CallerModulePrefix+p.Module:
return true
}
if seat, ok := strings.CutPrefix(c, seatdef.CallerSeatPrefix); ok &&
slices.ContainsFunc(p.Holds, func(h Seat) bool { return h.Name == seat }) {
return true
}
}
return false
}
// seatToolSubject is where a role's tool is asked. Mesh-wide for a mesh-scoped seat; a node-scoped
// seat carries the node it is asked of, because a flat subject would reach every machine's holder
// and the queue group would silently pick a winner (novox/hq ADR 0132, design 33 §4). A holder
@@ -222,14 +222,12 @@ func SeatTrafficOf(module string, holds, uses, watches []Seat) SeatTraffic {
continue
}
if s.PulledByKind {
// **An ask names its asker** (§543, §600): each asker is granted `accept.<queue>.<asker>` for the queues whose
// kinds it is a caller of, its name the seat it holds, and main's `accept.<queue>` is the checker's and the
// builder's alone.
// **An ask names its asker** (§543, §600): each asker is granted `accept.<queue>.<asker>` for every queue, its
// name the seat it holds (every account may call every verb, design 47 H §752, H-A-66), and main's
// `accept.<queue>` is the checker's and the builder's alone.
for _, q := range s.Accepts {
for _, h := range holds {
if namesVerb(s.AcceptCallers[q], h.Name) {
t.Publish = append(t.Publish, seatSubject(s, "accept", q+"."+h.Name))
}
t.Publish = append(t.Publish, seatSubject(s, "accept", q+"."+h.Name))
if namesVerb(MainAskers, h.Name) {
t.Publish = append(t.Publish, seatSubject(s, "accept", q))
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+11 -77
View File
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"slices"
"sort"
"strings"
"git.novox.be/novox/mesh-sdk/go/seatdef"
@@ -13,31 +12,15 @@ import (
"mesh-grants/internal/buscompose"
)
// The tools that say who may call and why a call is refused (design 47 G §83, GR2).
const (
ToolCallers = "grants_callers"
ToolWhyRefused = "grants_why_refused"
)
// CallerLine is one verb's, or one accepted kind's, callers as a seat definition gives them.
type CallerLine struct {
Seat string `json:"seat"`
// Verb is the verb's name, or the accepted kind's.
Verb string `json:"verb"`
// Kind is `verb` or `accepts`.
Kind string `json:"kind"`
Class string `json:"class,omitempty"`
// Callers are the entries the verb admits: the list the definition names, or its class's default.
Callers []string `json:"callers"`
// Named says the definition names the list; false is the class's default (§391).
Named bool `json:"named"`
}
// The tool that says why a call is refused at the bus (design 47 G §83): every account may call every verb, so no
// definition names callers and the bus's own verdict is the answer (design 47 H §752, H-A-113).
const ToolWhyRefused = "grants_why_refused"
// definitions are the seat definitions the part composes from, or why it has none.
func (p *Part) definitions() (map[string]seatdef.Definition, error) {
d, ok := p.SeatList.(SeatDefinitions)
if !ok {
return nil, errors.New("the seat list is not read here: the definitions' callers are unknown")
return nil, errors.New("the seat list is not read here: the seats' verbs are unknown")
}
defs := d.Definitions()
if len(defs) == 0 {
@@ -46,53 +29,8 @@ func (p *Part) definitions() (map[string]seatdef.Definition, error) {
return defs, nil
}
// CallerLines are the callers each verb and each accepted kind admits, from the definitions, of the seat named (every seat
// when empty) and the verb named (every verb when empty).
func CallerLines(defs map[string]seatdef.Definition, seat, verb string) []CallerLine {
var out []CallerLine
for _, d := range defs {
if seat != "" && d.Seat != seat {
continue
}
for _, v := range d.Verbs {
if verb == "" || v.Name == verb {
out = append(out, CallerLine{Seat: d.Seat, Verb: v.Name, Kind: "verb", Class: v.Class,
Callers: v.EffectiveCallers(), Named: v.Callers != nil && !v.Callers.IsText()})
}
}
for _, a := range d.Accepts {
if verb == "" || a.Name == verb {
l := CallerLine{Seat: d.Seat, Verb: a.Name, Kind: "accepts"}
if a.Callers != nil && !a.Callers.IsText() {
l.Callers, l.Named = a.Callers.List, true
}
out = append(out, l)
}
}
}
sort.Slice(out, func(i, j int) bool {
a, b := out[i], out[j]
return a.Seat+"\x00"+a.Kind+"\x00"+a.Verb < b.Seat+"\x00"+b.Kind+"\x00"+b.Verb
})
return out
}
// Callers answers the tool grants_callers.
func (p *Part) Callers(seat, verb string) (any, error) {
defs, err := p.definitions()
if err != nil {
return nil, err
}
lines := CallerLines(defs, seat, verb)
if len(lines) == 0 {
return nil, fmt.Errorf("no seat definition names a verb or an accepted kind matching seat %q verb %q", seat, verb)
}
return map[string]any{"callers": lines, "count": len(lines)}, nil
}
// WhyRefused answers the tool grants_why_refused: the grant an account lacks to call address (`<seat>.<verb>`), and the
// definition's line that leaves it out. The bus answers whether the account may publish the verb's call subject
// (nats.nats_user_can, the account's grants as the server holds them); the definition's callers say who was meant to.
// WhyRefused answers the tool grants_why_refused: whether the bus grants an account the call subject of address
// (`<seat>.<verb>`), the bus's own answer (nats.nats_user_can, the account's grants as the server holds them).
func (p *Part) WhyRefused(account, address, node string) (any, error) {
seat, verb, ok := strings.Cut(address, ".")
if account == "" || !ok || seat == "" || verb == "" {
@@ -102,17 +40,16 @@ func (p *Part) WhyRefused(account, address, node string) (any, error) {
if err != nil {
return nil, err
}
lines := CallerLines(defs, seat, verb)
if len(lines) == 0 {
def, defined := defs[seat]
if !defined || !slices.ContainsFunc(def.Verbs, func(v seatdef.Verb) bool { return v.Name == verb }) {
return nil, fmt.Errorf("no seat definition names the verb %s", address)
}
def := defs[seat]
s := buscompose.Seat{Name: seat, Scope: def.Scope}
subject := buscompose.CalledSubject(buscompose.SeatToolSubject(s, verb, node), account)
if subject == "" {
return nil, fmt.Errorf("%s is not the name of a bus user", account)
}
out := map[string]any{"account": account, "verb": address, "subject": subject, "definition": lines}
out := map[string]any{"account": account, "verb": address, "subject": subject}
raw, err := p.Call.Call(CallUserCan, map[string]any{"user": account, "action": "publish", "subject": subject})
if err != nil {
out["bus"] = "not read: " + err.Error()
@@ -125,15 +62,12 @@ func (p *Part) WhyRefused(account, address, node string) (any, error) {
out["bus"] = json.RawMessage(raw)
switch {
case can.Allowed == nil:
out["says"] = "the bus's answer names no verdict; read it beside the definition's line"
out["says"] = "the bus's answer names no verdict"
case *can.Allowed:
out["says"] = "not refused at the bus: the account holds the grant to publish " + subject
default:
callers := lines[0].Callers
out["says"] = fmt.Sprintf("the account lacks the grant to publish %s; the definition admits %s (%s), and the grants part grants a call only to a caller one of those entries names",
subject, strings.Join(callers, ", "), map[bool]string{true: "named by the definition", false: "the class's default"}[lines[0].Named])
out["says"] = "the account lacks the grant to publish " + subject
out["lacks"] = subject
out["admitted_by"] = slices.Clone(callers)
}
return out, nil
}
@@ -2,6 +2,7 @@ package grants
import (
"encoding/json"
"slices"
"strings"
"testing"
@@ -23,20 +24,13 @@ func (c *canCall) Call(key string, body any) (json.RawMessage, error) {
return json.Marshal(map[string]any{"allowed": c.allowed})
}
// grants_callers and grants_why_refused read the definitions' callers (design 47 G §83): every verb takes its class's
// default (§610: no verb names its callers; an act's are the operator, sessions and invokers, a read's invokers, persons
// and sessions), and a refused account is told the call subject it lacks and the callers the definition admits.
func TestCallersAndWhyRefused(t *testing.T) {
// grants_why_refused answers the bus's own verdict on an account's call subject, naming no callers (design 47 H §752,
// H-A-113): a refused account is told the subject it lacks; grants_callers is gone.
func TestWhyRefusedIsTheBussVerdict(t *testing.T) {
defs := map[string]seatdef.Definition{"mesh-wants": {Seat: "mesh-wants", Scope: "mesh", Verbs: []seatdef.Verb{
{Name: "upgrade", Class: seatdef.ClassAct},
{Name: "entry", Class: seatdef.ClassRead},
}}}
lines := CallerLines(defs, "mesh-wants", "")
if len(lines) != 2 || lines[0].Verb != "entry" || lines[0].Named || lines[1].Named ||
strings.Join(lines[0].Callers, ",") != "invokers,persons,sessions" ||
strings.Join(lines[1].Callers, ",") != "operator,sessions,invokers" {
t.Fatalf("lines: %+v", lines)
}
can := &canCall{}
p := &Part{SeatList: defsGate{defs}, Call: can}
got, err := p.WhyRefused("one.shop", "mesh-wants.upgrade", "")
@@ -44,8 +38,8 @@ func TestCallersAndWhyRefused(t *testing.T) {
t.Fatal(err)
}
out := got.(map[string]any)
if out["lacks"] != "mesh.seat.mesh-wants.call.upgrade.one~shop" || can.asked["subject"] != out["lacks"] ||
!strings.Contains(out["says"].(string), "operator, sessions, invokers") {
if out["lacks"] != "mesh.seat.mesh-wants.call.upgrade.one~shop" || can.asked["subject"] != out["lacks"] || out["definition"] != nil ||
out["admitted_by"] != nil || strings.Contains(out["says"].(string), "definition") {
t.Errorf("a refused caller: %+v", out)
}
can.allowed = true
@@ -56,4 +50,7 @@ func TestCallersAndWhyRefused(t *testing.T) {
if _, err := p.WhyRefused("one.shop", "mesh-wants.nothing", ""); err == nil {
t.Error("a verb no definition names was explained")
}
if slices.Contains(Tools, "grants_callers") {
t.Error("the tool grants_callers is still listed")
}
}
@@ -14,18 +14,14 @@ import (
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/keys"
"git.novox.be/novox/mesh-sdk/go/views"
)
// **The grants part's first views** (novox/hq ADR 0615 §1, §4 to §6, ADR 0621, ADR 0622; design 25 § 12.2; DLV-F4r,
// DLV-R1). The part reads the assigner's assignments and wants and the indexer's manifests, modules and verdicts no longer
// DLV-R1). The part reads the assigner's assignments and wants and the indexer's manifests and modules no longer
// from their buckets, but by each owner's first-view tool, asked once at its start, then from the owner's views family
// alone (each event one changed key with its revision), asking once more only on a gap in revisions, never on a timer.
// The verdicts alone are followed on the seat mesh-catalog's manifest-accepted and manifest-refused, which carry the revision
// (ADR 0622 §2), not on its views family (HearVerdict).
// The indexer keeps no verdicts (design 47 H §745, H-A-79): a manifest is validated by its pipeline's step.
// Started while an owner is down it keeps asking and never reads the owner's state; past the bound (two minutes) it
// raises FirstViewUnanswered naming the owner and the tool, cleared by the answer.
//
@@ -48,14 +44,13 @@ const (
IndexerModule = "mesh-delivery-indexer"
)
// FirstViews are the five (ADR 0615 §3 as ADR 0622 §1 amends it: the grants part's assignments, wants, manifests,
// modules and verdicts).
// FirstViews are the four (ADR 0615 §3 as ADR 0622 §1 amends it: the grants part's assignments, wants, manifests and
// modules; the verdicts go with the indexer's state, design 47 H-A-79).
var FirstViews = []FirstView{
{Owner: AssignerModule, Tool: AssignerModule + ".assignments", State: "assignments", Read: ReadAssignments},
{Owner: AssignerModule, Tool: AssignerModule + ".wants", State: "wants", Read: ReadWants},
{Owner: IndexerModule, Tool: IndexerModule + ".manifests", State: "manifests", Read: ReadManifests},
{Owner: IndexerModule, Tool: IndexerModule + ".modules", State: "modules", Read: ReadModules},
{Owner: IndexerModule, Tool: IndexerModule + ".verdicts", State: "verdicts", Read: ReadVerdicts},
}
// The conditions of the first views, each naming the owner and its state.
@@ -261,91 +256,11 @@ func (v *Views) Again(ctx context.Context, state, why string) ([]string, error)
asked = append(asked, fv.Tool)
}
if len(asked) == 0 {
return nil, fmt.Errorf("%q is no first view of the grants part: one of assignments, wants, manifests, modules, verdicts, bindings, or none for all", state)
return nil, fmt.Errorf("%q is no first view of the grants part: one of assignments, wants, manifests, modules, bindings, or none for all", state)
}
return asked, nil
}
// VerdictEvents are the seat mesh-catalog's two events the part follows the verdicts on after their first view (ADR 0622 §2), as its
// manifest's consumes name them.
var VerdictEvents = []string{meshcatalog.Seat + "." + meshcatalog.EventManifestAccepted, meshcatalog.Seat + "." + meshcatalog.EventManifestRefused}
// HearVerdict takes one of the seat mesh-catalog's manifest-accepted or manifest-refused (event, its name) into the verdicts' first
// view, as one change of the verdicts state at the revision it carries (ADR 0622 §2): the manifest's digest its key, the
// verdict it says its value. A revision past the one after the picture's is a gap, and so is an event carrying no
// revision (an indexer that does not say it) or one saying no manifest above the picture's revision (the empty accepted
// verdict of a module leaving the trunk): the first view is asked once more on its own goroutine, said in the log. A
// revision already in the picture is passed over. Data that does not read is answered as an error, and nothing is asked.
func (v *Views) HearVerdict(ctx context.Context, event string, data []byte, logf func(string, ...any)) error {
f := v.Followers[ReadVerdicts]
if f == nil {
return nil
}
var verdict meshcatalog.VerdictsByDigestValue
var digest string
var revision uint64
switch event {
case meshcatalog.EventManifestAccepted:
var a meshcatalog.ManifestAcceptedEvent
if err := json.Unmarshal(data, &a); err != nil {
return fmt.Errorf("%s does not read: %w", event, err)
}
verdict = meshcatalog.VerdictsByDigestValue{V: keys.Version, Module: a.Module, State: meshcatalogclient.VerdictAccepted, Judge: a.Judge}
digest, revision = a.Digest, uint64(a.Revision)
case meshcatalog.EventManifestRefused:
var r meshcatalog.ManifestRefusedEvent
if err := json.Unmarshal(data, &r); err != nil {
return fmt.Errorf("%s does not read: %w", event, err)
}
verdict = meshcatalog.VerdictsByDigestValue{V: keys.Version, Module: r.Module, State: meshcatalogclient.VerdictRefused, Judge: r.Judge, Problems: r.Problems}
digest, revision = r.Digest, uint64(r.Revision)
default:
return fmt.Errorf("%q is not a verdict event of the indexer", event)
}
held := f.Status()
gap := func(why string) error {
logf("views: a gap in %s (%s): its first view %s is asked once more", f.State, why, f.Tool)
go func() { _ = f.Gap(ctx, why) }()
return nil
}
if revision == 0 {
return gap(fmt.Sprintf("the indexer's %s of %s carries no revision", event, verdict.Module))
}
key, err := meshcatalogclient.VerdictsKey(digest)
if err != nil {
if revision <= held.Revision {
return nil
}
return gap(fmt.Sprintf("the indexer's %s of %s at revision %d names no manifest", event, verdict.Module, revision))
}
// A revision below the picture's is a gap (ADR 0615 §5): the verdict events carry no mark of when the indexer's verdicts
// were made, so one made again shows only as revisions starting low. A redelivery of a verdict the picture already
// holds for its manifest is passed over, so a consumer's backlog after a restart asks nothing.
if revision < held.Revision {
if raw, found := f.Get(key); found {
if was, err := meshcatalogclient.DecodeVerdict(raw); err == nil && sameVerdict(was, verdict) {
return nil
}
}
return gap(fmt.Sprintf("the indexer's %s of %s at revision %d, below the picture's %d: its verdicts were made again, or this verdict was missed",
event, verdict.Module, revision, held.Revision))
}
value, err := json.Marshal(verdict)
if err != nil {
return err
}
if g, why := f.Apply(views.Event{V: 1, Owner: f.Owner, State: f.State, Key: key, Revision: revision, Created: held.Created,
Value: value, At: time.Now().UTC()}); g {
return gap(why)
}
return nil
}
// sameVerdict says two verdicts of one manifest say the same: its module, accepted or refused, the judge and the problems.
func sameVerdict(a, b meshcatalog.VerdictsByDigestValue) bool {
return a.Module == b.Module && a.State == b.State && a.Judge == b.Judge && slices.Equal(a.Problems, b.Problems)
}
// unansweredCondition is FirstViewUnanswered for one first view, raised or cleared.
func unansweredCondition(fv FirstView, s views.Status, raised bool) oc.Condition {
c := oc.Condition{Key: FirstViewUnanswered + "." + fv.Owner + "." + fv.State, Subject: oc.ConditionSubject{Scope: "module", ID: Module}}
@@ -515,7 +430,7 @@ func (p *Part) AskFirstViewAgain(caller, state, why string, record func(what, wh
}
}
if which == "" {
return nil, fmt.Errorf("%q is no first view of the grants part: one of assignments, wants, manifests, modules, verdicts, bindings, or none for all", state)
return nil, fmt.Errorf("%q is no first view of the grants part: one of assignments, wants, manifests, modules, bindings, or none for all", state)
}
}
if strings.TrimSpace(why) == "" {
@@ -21,7 +21,7 @@ type Watcher interface {
//
// And the seat mesh-enrolment's keys (ADR 0587 §4, §5): a key at live composes enrol.<node>, and its end, by the holder or by
// the bus's expiry, is a change of the key that takes the user out; no event is needed beside the watch.
var Followed = []string{ReadModules, ReadVerdicts, ReadResolved, ReadHave, ReadWants, ReadAccounts, ReadAssignments, ReadEnrolments,
var Followed = []string{ReadModules, ReadResolved, ReadHave, ReadWants, ReadAccounts, ReadAssignments, ReadEnrolments,
ReadNodeLogins}
// Follower composes again on every change it hears, never on a timer. It never stops for a refusal: a watch it cannot
+15 -72
View File
@@ -40,12 +40,9 @@ import (
const (
ReadModules = "mesh-delivery-indexer.modules"
ReadManifests = "mesh-delivery-indexer.manifests"
// ReadVerdicts is the indexer's verdicts, one key per manifest digest: a manifest it has not judged yet has none, and is
// held like a refused one (ADR 0614 §8).
ReadVerdicts = "mesh-delivery-indexer.verdicts"
ReadHave = "node-engine.have"
ReadResolved = "mesh-config.resolved"
ReadWants = "mesh-delivery-assigner.wants"
ReadHave = "node-engine.have"
ReadResolved = "mesh-config.resolved"
ReadWants = "mesh-delivery-assigner.wants"
// ReadAccounts is the vault's bcrypt hashes of the bus accounts it holds, by bus user (ADR 0547 clause 9).
ReadAccounts = "mesh-vault.bus-accounts"
// ReadAssignments is the seat mesh-module-assigner's assignments (ADR 0567 §1, §9): each node's modules and the seats
@@ -65,7 +62,7 @@ var Reads = []string{ReadResolved, ReadHave, ReadAccounts, ReadEnrolments, ReadN
// ViewReads are the owners' states the part reads by their first views and views families, never their buckets
// (firstviews.go, ADR 0615): each read in Reads' place.
var ViewReads = []string{ReadModules, ReadManifests, ReadVerdicts, ReadWants, ReadAssignments}
var ViewReads = []string{ReadModules, ReadManifests, ReadWants, ReadAssignments}
// The bus module's tools the part calls, as its manifest's invokes name them: read-only, each.
const (
@@ -201,10 +198,6 @@ type Inputs struct {
// EventSubjects are, by seat, the subjects of its events that carry parts, by the event's local name, as the definitions
// give them: where a node-scoped seat's event names its machine (buscompose.Seat.EventSubjects).
EventSubjects map[string]map[string]string
// AcceptCallers are, by pulled-by-kind seat and queue, the seats that may ask it (acceptCallersOf).
AcceptCallers map[string]map[string][]string
// VerbCallers are, by seat and verb, the callers each verb of the definitions admits (verbCallersOf).
VerbCallers map[string]map[string][]string
// Defined are the events a seat definition of the seat list defines, by local name, and mesh-sdk's finding events: the
// events a `*` emitter before them reaches each declaring module's own stream for (design 47 G §386, §474, §644).
Defined map[string]bool
@@ -395,8 +388,6 @@ func ReadInputs(r Reader, cache *Manifests) Inputs {
in.AskStreams = buscompose.AskStreamsOf(d.Definitions())
in.Chunked = buscompose.ChunkVerbsOf(d.Definitions())
in.EventSubjects = eventSubjectsOf(d.Definitions())
in.AcceptCallers = acceptCallersOf(d.Definitions())
in.VerbCallers = verbCallersOf(d.Definitions())
in.Defined = definedEventsOf(d.Definitions())
}
nodes := map[string]bool{}
@@ -527,17 +518,8 @@ func ReadInputs(r Reader, cache *Manifests) Inputs {
}
in.NoFingerprint[module] = why
}
// No verdict holds a manifest here: it is validated by its pipeline's step validate (design 47 H §745, H-A-79).
var m catalogue.Manifest
if err == nil {
// The indexer's refusal, or its wait for a judge that knows a field, carried in its value (ADR 0578 §3): held and named as a refused manifest.
if verdict := meshcatalogclient.ModuleVerdict(module, v); verdict != nil && meshcatalogclient.VerdictHeld(*verdict) {
err = errors.New(meshcatalogclient.VerdictWhy(*verdict))
} else if verdict == nil {
// The indexer writes a changed manifest's value before it judges it, and a new digest has no verdict: until
// the verdict is written the manifest is held (ADR 0614 §8).
err = noVerdictYet(r, v.Manifest)
}
}
if err == nil {
m, err = cache.get(r, v.Manifest)
}
@@ -606,7 +588,7 @@ func ReadInputs(r Reader, cache *Manifests) Inputs {
in.Gaps = append(in.Gaps, Gap{Input: ReadWants, Why: "not read: the modules are placed by the node-engines' haves this pass, so what runs is composed from each have's fingerprint"})
fromTrunk = runningByHaves(r, &in, cache, in.Running)
}
var viaNewest, noNewest []string
var noEntry []string
for key, raw := range wants {
node, module, err := meshwantsclient.ParseWantKey(key)
if err != nil || !slices.Contains(in.Assigned[node], module) {
@@ -620,36 +602,21 @@ func ReadInputs(r Reader, cache *Manifests) Inputs {
if w.Removed || w.Fp == "" {
continue
}
// The manifest of the build the want names is the catalog graph's entry of its fingerprint (design 47 G §444, §614).
// The manifest of the build the want names is the catalog graph's entry of its fingerprint (design 47 G §444, §614);
// a want names that build alone (design 47 H §750, H-A-37), so one with no entry is composed from the trunk's.
m, _, err := cache.entryManifest(r, w.Fp)
switch {
case err == nil:
in.Running[node+"."+module] = m
continue
case w.Newest == "" || w.Newest == w.Fp:
if err != nil {
fromTrunk = append(fromTrunk, node+"."+module)
noNewest = append(noNewest, node+"."+module+" (its want names no newer build; "+err.Error()+")")
noEntry = append(noEntry, node+"."+module+" ("+err.Error()+")")
continue
}
// A running build with no catalog entry (from before the catalog graph) is composed from the entry of the build its want
// says is being built, for its account's grants, membership and seat traffic alone (A-414, as A-407 does for the node).
nm, _, nerr := cache.entryManifest(r, w.Newest)
if nerr != nil {
fromTrunk = append(fromTrunk, node+"."+module)
noNewest = append(noNewest, node+"."+module+" (the entry of its want's newest build is not held: "+nerr.Error()+"; "+err.Error()+")")
continue
}
in.Running[node+"."+module] = nm
viaNewest = append(viaNewest, node+"."+module)
in.Running[node+"."+module] = m
}
if len(noNewest) > 0 {
sort.Strings(noNewest)
in.Gaps = append(in.Gaps, Gap{Input: "wanted manifests", Why: "the running build has no catalog entry and its want's newest build gave none: " + strings.Join(noNewest, ", ")})
}
if len(viaNewest) > 0 {
sort.Strings(viaNewest)
in.Gaps = append(in.Gaps, Gap{Input: "wanted manifests", Why: "no catalog entry holds the running build, so its account is composed from the entry of the build its want says is being built: " + strings.Join(viaNewest, ", ")})
if len(noEntry) > 0 {
sort.Strings(noEntry)
in.Gaps = append(in.Gaps, Gap{Input: "wanted manifests", Why: "the running build has no catalog entry: " + strings.Join(noEntry, ", ")})
}
if len(fromTrunk) > 0 {
sort.Strings(fromTrunk)
in.Gaps = append(in.Gaps, Gap{Input: "wanted manifests", Why: "no build record names the manifest at the wanted fingerprint, so the trunk's is used: " + strings.Join(fromTrunk, ", ")})
@@ -928,27 +895,3 @@ func (in Inputs) declared() map[string]catalogue.Manifest {
}
return out
}
// noVerdictYet is nil when the indexer's verdicts state holds an accepted verdict on the manifest, and the reason it is held
// when it holds none yet, cannot be read, or refuses it.
func noVerdictYet(r Reader, digest string) error {
key, err := meshcatalogclient.VerdictsKey(digest)
if err != nil {
return nil
}
raw, found, err := r.Get(ReadVerdicts, key)
if err != nil {
return fmt.Errorf("its verdict cannot be read: %w", err)
}
if !found {
return errors.New("the indexer has written no verdict on this manifest yet")
}
v, err := meshcatalogclient.DecodeVerdict(raw)
if err != nil {
return fmt.Errorf("its verdict does not read: %w", err)
}
if meshcatalogclient.VerdictHeld(v) {
return errors.New(meshcatalogclient.VerdictWhy(v))
}
return nil
}
@@ -138,58 +138,6 @@ func withEventSubjects(subjects map[string]map[string]string, d *buscompose.Decl
}
}
// acceptCallersOf is, by pulled-by-kind seat and then by queue, the seats that may ask the queue: the `seat:<seat>` entries
// of the callers of every accepted kind the definition puts on it (a kind's `stream` is its queue, else its name is). Never a
// name of the grants part's own: it reads the definitions' lists (design 47 G §543, §600, A-163).
func acceptCallersOf(defs map[string]seatdef.Definition) map[string]map[string][]string {
out := map[string]map[string][]string{}
for _, d := range defs {
if !d.PulledByKind {
continue
}
for _, a := range d.Accepts {
if a.Callers == nil || a.Callers.IsText() {
continue
}
queue := a.Name
if a.Stream != "" {
queue = a.Stream
}
for _, e := range a.Callers.List {
if seat, ok := strings.CutPrefix(e, seatdef.CallerSeatPrefix); ok && !slices.Contains(out[d.Seat][queue], seat) {
if out[d.Seat] == nil {
out[d.Seat] = map[string][]string{}
}
out[d.Seat][queue] = append(out[d.Seat][queue], seat)
}
}
}
}
return out
}
// withAcceptCallers gives each pulled-by-kind seat a declaration holds or uses the askers of its queues (Seat.AcceptCallers).
func withAcceptCallers(askers map[string]map[string][]string, d *buscompose.Declared) {
if len(askers) == 0 {
return
}
for _, list := range []*[]buscompose.Seat{&d.Holds, &d.Uses, &d.Watches} {
for i := range *list {
(*list)[i].AcceptCallers = askers[(*list)[i].Name]
}
}
}
// withVerbCallers gives each seat a declaration holds, uses or watches the effective callers of its verbs
// (Seat.VerbCallers, design 47 G §610, A-179), as withAcceptCallers gives the askers of its queues.
func withVerbCallers(callers map[string]map[string][]string, d *buscompose.Declared) {
for _, list := range []*[]buscompose.Seat{&d.Holds, &d.Uses, &d.Watches} {
for i := range *list {
(*list)[i].VerbCallers = callers[(*list)[i].Name]
}
}
}
// createAskStreams makes each seat's ask stream the bus lacks (buscompose.AskStreamsOf), as createKept makes a kept event's: only
// where the bus was read and holds no stream of that name, never changed where it holds one.
func createAskStreams(c Creator, done *creations, asks []jetstream.StreamConfig, held map[string]Limits, force bool) (made, notMade []string) {
@@ -8,32 +8,9 @@ import (
"git.novox.be/novox/mesh-sdk/go/seatdef"
)
// The askers of a build seat's queue are read from the definition's callers lists (design 47 G §543, §600, A-163): a kind's
// `stream` is its queue, a text callers names none, and only `seat:` entries are askers.
// A build seat's queues (A-170, A-184): every account may ask each one (design 47 H §752), so no callers list names askers.
func TestAcceptCallersOf(t *testing.T) {
msg := func(name, stream string, callers ...string) seatdef.Message {
m := seatdef.Message{Name: name, Stream: stream}
if callers != nil {
m.Callers = &seatdef.Callers{List: callers}
}
return m
}
got := acceptCallersOf(map[string]seatdef.Definition{
"node-build-go": {Seat: "node-build-go", PulledByKind: true, Accepts: []seatdef.Message{
msg("check", "", "seat:mesh-catalog", "operator"),
msg("step", "check", "seat:mesh-pipeline-runner"),
msg("delivery", "", "seat:mesh-builds"),
{Name: "recheck", Callers: &seatdef.Callers{Text: "the checker"}},
}},
"other": {Seat: "other", Accepts: []seatdef.Message{msg("go", "", "seat:x")}},
})
if len(got) != 1 {
t.Fatalf("seats: %v, want node-build-go alone", got)
}
q := got["node-build-go"]
if !slices.Equal(q["check"], []string{"mesh-catalog", "mesh-pipeline-runner"}) || !slices.Equal(q["delivery"], []string{"mesh-builds"}) || len(q) != 2 {
t.Errorf("queues: %v", q)
}
msg := func(name, stream string) seatdef.Message { return seatdef.Message{Name: name, Stream: stream} }
// A-170, A-184: the seat's workers are per queue, never per kind: step and run ride check or delivery.
build := catalogue.SeatFromDefinition(seatdef.Definition{Seat: "node-build-go", PulledByKind: true, Accepts: []seatdef.Message{
msg("delivery", ""), msg("check", ""), msg("step", "check"), msg("step", "delivery"), msg("recheck", ""), msg("run", "check")}})
@@ -92,11 +92,11 @@ func TestTheNamedAsksArePurgedAtTheFirstRevisionThatLeavesThem(t *testing.T) {
t.Errorf("a named worker composed %v, want %v (%v)", has, c.named, c.in.Manifests["runner"].Invokes)
}
}
// A-413: an account granted a named ask (it uses the seat's queue and holds a seat its AcceptCallers name) keeps the named
// A-413: an account granted a named ask (it uses the seat's queue and holds a seat: every account may ask every queue, design 47 H §752) keeps the named
// workers though no entry invokes the queue; with neither, they go out and the purge runs.
asker := buscompose.Declared{Module: "asker",
Holds: []buscompose.Seat{{Name: "node-delivery", Scope: "node"}},
Uses: []buscompose.Seat{{Name: "node-build-go", Scope: "node", Accepts: []string{"check"}, PulledByKind: true, AcceptCallers: map[string][]string{"check": {"node-delivery"}}}}}
Uses: []buscompose.Seat{{Name: "node-build-go", Scope: "node", Accepts: []string{"check"}, PulledByKind: true}}}
granted := buscompose.Records{Nodes: []string{"one"}, Assigned: map[string][]buscompose.Declared{"one": {recs.Assigned["one"][0], asker}}}
for _, c := range []struct {
r buscompose.Records
@@ -127,15 +127,12 @@ func records(in Inputs, union bool) (buscompose.Records, []Gap) {
d.Watches, d.Consumes, d.Hears, keptHeard = keptOutOfHearing(in.Kept, d.Watches, d.Consumes, d.Hears)
d.HearsAStream = d.HearsAStream || keptHeard
d.Reads, d.ReadsObjects, d.ReadsRefused = readsOfObjects(m.Module, node, d.Reads, d.ReadsRefused, declared, values)
// The sent stores of the modules it is for (design 47 G §59, §124), read from the catalog graph's manifests and the
// definitions' callers.
d.ReadsObjects = append(d.ReadsObjects, sentStoresRead(m, in.Manifests, in.VerbCallers)...)
// The sent stores of the modules it is for (design 47 G §59, §124), read from the catalog graph's manifests.
d.ReadsObjects = append(d.ReadsObjects, sentStoresRead(m, in.Manifests)...)
// Its bindings as kept (bindings.go): the same source its membership's `bindings` is written from in this pass,
// so a grant and its binding are written together, never one before the other (issue 1966, the kind of issue 249).
d.Bindings = in.Bindings[m.Module]
withEventSubjects(in.EventSubjects, &d)
withAcceptCallers(in.AcceptCallers, &d)
withVerbCallers(in.VerbCallers, &d)
return d
}
d := declare(m)
@@ -175,8 +172,6 @@ func records(in Inputs, union bool) (buscompose.Records, []Gap) {
out.Engine = &buscompose.Declared{Module: m.Module, Consumes: m.Consumes, Watches: watches, Invokes: m.Invokes,
State: bucketsFor(m, in.Nodes), Logs: logsOf(m), Streams: streamsOf(m)}
withEventSubjects(in.EventSubjects, out.Engine)
withAcceptCallers(in.AcceptCallers, out.Engine)
withVerbCallers(in.VerbCallers, out.Engine)
}
return out, gaps
}
@@ -63,8 +63,7 @@ var seatEvents = []string{EventKeeperRaised, EventKeeperCleared, EventAccountIss
meshbroker.Seat + "." + BrokerDropped, meshbroker.Seat + "." + BrokerRecreated,
meshrecovery.Seat + "." + meshrecovery.EventEnded, meshrecovery.Seat + "." + meshrecovery.EventPointRemoved, meshrecovery.Seat + "." + meshrecovery.EventExpiryEnded}
// SeatEventSubjects are the subjects of the seats' events the part follows its passes by besides the verdicts' and the
// views': the keeper's condition events, the vault's account-issued and the seat mesh-broker's, each `<seat>.<event>` of
// SeatEventSubjects are the subjects of the seats' events the part follows its passes by besides the views': the keeper's condition events, the vault's account-issued and the seat mesh-broker's, each `<seat>.<event>` of
// Consumes on the seat's own subject.
func SeatEventSubjects() []string {
var out []string
@@ -75,15 +74,10 @@ func SeatEventSubjects() []string {
return out
}
// viewsEvents are the owners' events the part follows its first views by: `<owner>.views.<state>`, but the verdicts by
// the indexer's manifest-accepted and manifest-refused (VerdictEvents, ADR 0622 §2).
// viewsEvents are the owners' events the part follows its first views by: `<owner>.views.<state>`.
func viewsEvents() []string {
var out []string
for _, fv := range FirstViews {
if fv.Read == ReadVerdicts {
out = append(out, VerdictEvents...)
continue
}
out = append(out, fv.Owner+".views."+fv.State)
}
return out
@@ -5,48 +5,17 @@ import (
"strings"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/seatdef"
)
// **A module's sent store is read by the modules it is for** (design 47 G §59, §124): the grants part derives, from the
// catalog graph and the seat definitions, never from a manifest field, a standing read of `<module>_sent-objects` for the
// callers the module's seat definition names for the verbs it serves, and for the consumers whose `consumes` declare its
// events. The grant follows the catalog graph, so it is composed with each module's declaration at every pass.
// verbCallersOf is, by seat and verb, the callers each verb of the definitions admits (a verb naming none takes its class's
// default).
func verbCallersOf(defs map[string]seatdef.Definition) map[string]map[string][]string {
out := map[string]map[string][]string{}
for _, d := range defs {
for _, v := range d.Verbs {
if out[d.Seat] == nil {
out[d.Seat] = map[string][]string{}
}
out[d.Seat][v.Name] = v.EffectiveCallers()
}
}
return out
}
// admits says whether a verb's callers name the module: `invokers` (every module whose manifest invokes the verb), the module
// itself, or a seat it claims.
func admits(callers []string, m catalogue.Manifest) bool {
for _, c := range callers {
switch {
case c == seatdef.CallerInvokers, c == seatdef.CallerModulePrefix+m.Module:
return true
}
if seat, ok := strings.CutPrefix(c, seatdef.CallerSeatPrefix); ok && slices.ContainsFunc(m.Claims, func(x catalogue.Claim) bool { return x.Name == seat }) {
return true
}
}
return false
}
// catalog graph, never from a manifest field, a standing read of `<module>_sent-objects` for every module invoking a verb of a
// seat it claims (every account may call every verb, design 47 H §752, H-A-66), and for the consumers whose `consumes` declare
// its events. The grant follows the catalog graph, so it is composed with each module's declaration at every pass.
// sentStoresRead are the bus names of the sent stores the module m reads: of each module whose event it consumes (the module's
// own, or the seat a module claims), and of each module claiming a seat whose verb m invokes where the verb's callers admit m.
// own, or the seat a module claims), and of each module claiming a seat whose verb m invokes.
// Never m's own store, which its binding grants it.
func sentStoresRead(m catalogue.Manifest, all map[string]catalogue.Manifest, callers map[string]map[string][]string) []string {
func sentStoresRead(m catalogue.Manifest, all map[string]catalogue.Manifest) []string {
claimants := func(name string) []string {
var out []string
if _, ok := all[name]; ok {
@@ -70,8 +39,8 @@ func sentStoresRead(m catalogue.Manifest, all map[string]catalogue.Manifest, cal
}
}
for _, in := range m.Invokes {
seat, verb, ok := catalogue.SeatInvoke(in)
if !ok || !admits(callers[seat][verb], m) {
seat, _, ok := catalogue.SeatInvoke(in)
if !ok {
continue
}
for module, x := range all {
@@ -5,7 +5,6 @@ import (
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/seatdef"
"mesh-grants/internal/buscompose"
)
@@ -23,8 +22,6 @@ func TestSentStoresRead(t *testing.T) {
}
holder := catalogue.Manifest{Module: "shop", Claims: []catalogue.Claim{{Name: "orders-seat"}}}
all := map[string]catalogue.Manifest{"shop": holder, "bank": {Module: "bank"}, "plain": {Module: "plain"}}
callers := map[string]map[string][]string{"orders-seat": {
"place": {"seat:billing", "module:plain"}, "list": seatdef.DefaultCallers(seatdef.ClassRead), "wipe": seatdef.DefaultCallers(seatdef.ClassAct)}}
for _, c := range []struct {
name string
m catalogue.Manifest
@@ -35,21 +32,15 @@ func TestSentStoresRead(t *testing.T) {
{"invokes a verb that names its seat", catalogue.Manifest{Module: "bank", Claims: []catalogue.Claim{{Name: "billing"}},
Invokes: []string{"seat:orders-seat.place"}}, []string{"shop_sent-objects"}},
{"invokes a verb that names it", catalogue.Manifest{Module: "plain", Invokes: []string{"seat:orders-seat.place"}}, []string{"shop_sent-objects"}},
{"invokes a read, its callers include invokers", catalogue.Manifest{Module: "bank", Invokes: []string{"seat:orders-seat.list"}}, []string{"shop_sent-objects"}},
{"invokes an act, its callers include invokers (§610)", catalogue.Manifest{Module: "bank", Invokes: []string{"seat:orders-seat.wipe"}}, []string{"shop_sent-objects"}},
{"invokes a verb that names others", catalogue.Manifest{Module: "bank", Invokes: []string{"seat:orders-seat.place"}}, nil},
{"invokes a read", catalogue.Manifest{Module: "bank", Invokes: []string{"seat:orders-seat.list"}}, []string{"shop_sent-objects"}},
{"invokes an act", catalogue.Manifest{Module: "bank", Invokes: []string{"seat:orders-seat.wipe"}}, []string{"shop_sent-objects"}},
{"invokes a verb no callers list names: every account may call every verb (design 47 H §752)", catalogue.Manifest{Module: "bank", Invokes: []string{"seat:orders-seat.place"}}, []string{"shop_sent-objects"}},
{"declares neither", catalogue.Manifest{Module: "bank"}, nil},
{"its own store is its binding's", holder, nil},
} {
if got := sentStoresRead(c.m, all, callers); !slices.Equal(got, c.want) {
if got := sentStoresRead(c.m, all); !slices.Equal(got, c.want) {
t.Errorf("%s: %v, want %v", c.name, got, c.want)
}
} // The same callers reach each seat a declaration holds, uses or watches, from which its users' call subjects are
// composed (design 47 G A-179).
d := buscompose.Declared{Module: "bank", Uses: []buscompose.Seat{{Name: "orders-seat"}}, Holds: []buscompose.Seat{{Name: "billing"}}}
withVerbCallers(callers, &d)
if !slices.Equal(d.Uses[0].VerbCallers["place"], callers["orders-seat"]["place"]) || d.Holds[0].VerbCallers != nil {
t.Errorf("a used seat's verbs carry %v, a held seat no definition names %v", d.Uses[0].VerbCallers, d.Holds[0].VerbCallers)
}
}
+1 -1
View File
@@ -40,7 +40,7 @@ const (
// Tools is every tool, in the manifest's order.
var Tools = []string{ToolGrants, ToolMembership, ToolUserList, ToolComposeNow, ToolAssert, ToolAccounts, ToolConsumerMatch,
ToolAcceptHashes, ToolFirstViews, ToolFirstViewAgain, ToolRunning, ToolWaits, ToolRelease, ToolSeatList, ToolSeatListAgain, ToolCallers, ToolWhyRefused, ToolNamedPurge}
ToolAcceptHashes, ToolFirstViews, ToolFirstViewAgain, ToolRunning, ToolWaits, ToolRelease, ToolSeatList, ToolSeatListAgain, ToolWhyRefused, ToolNamedPurge}
// WritesGrants is what grants says of the part's own grants: written once the list the bus loaded carries a build's
// accounts, and the one key the assigner reads (ADR 0571 clause 9, which changes ADR 0547 clause 5).
-4
View File
@@ -35,8 +35,6 @@
"mesh-delivery-indexer.views.manifests",
"mesh-delivery-indexer.views.modules",
"mesh-catalog.catalog-revision",
"mesh-catalog.manifest-accepted",
"mesh-catalog.manifest-refused",
"mesh-catalog.registration-changed",
"mesh-catalog.seat-definition-changed",
"mesh-catalog.seat-definition-removed",
@@ -56,7 +54,6 @@
"mesh-delivery-assigner.wants",
"mesh-delivery-indexer.manifests",
"mesh-delivery-indexer.modules",
"mesh-delivery-indexer.verdicts",
"seat:mesh-catalog.entry",
"seat:mesh-catalog.registrations",
"seat:mesh-catalog.revision",
@@ -90,7 +87,6 @@
"grants_release",
"grants_seat_list",
"grants_seat_list_again",
"grants_callers",
"grants_why_refused",
"grants_named_purge"
],