Files
mesh-delivery/modules/mesh-grants/internal/grants/sentobjects_test.go
T
jschoubben cdc6e1f521 Item 5, area 8 (join 11): the grants part lets a caller of a marked verb hear its own calls' ends
A holder says a held call's end on its seat's gated-ended, kept last per subject for a day in SEAT_<seat>_gated-ended,
which the grants part makes from the definition seatdef.Resolve gives (A-264). The caller is granted hearing
gated-ended.<caller>.> under its own escaped account name, and an ordered consumer on that stream filtered to it, from its
invokes of the marked verb by name; a module or process that answers a marked verb is granted saying the event to any
caller. No process of mesh-delivery holds a marked verb, so no holder here takes NewGateChannel.

Builds: design 47 G §677, §700, A-264, A-273

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 12:24:48 +01:00

63 lines
3.7 KiB
Go

package grants
import (
"slices"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/seatdef"
"mesh-grants/internal/buscompose"
)
// The sent stores a module reads follow the catalog graph (design 47 G §59, §124): the consumers of a module's events and the
// callers a seat's verb admits, and no other module.
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
want []string
}{
{"consumes a module's event", catalogue.Manifest{Module: "bank", Consumes: []string{"shop.sold"}}, []string{"shop_sent-objects"}},
{"consumes a seat's event", catalogue.Manifest{Module: "bank", Consumes: []string{"orders-seat.sold"}}, []string{"shop_sent-objects"}},
{"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},
{"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) {
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)
}
}
// The marked verbs a declaration names (design 47 G §677): a definition-marked verb its module invokes or a process answers,
// and no unmarked verb.
func TestTheMarkedVerbsADeclarationNames(t *testing.T) {
seats := map[string]catalogue.SeatDeclaration{"node-login-shell": {Name: "node-login-shell",
Serves: []catalogue.Verb{{Name: "execute", NeedsApproval: true}, {Name: "list"}}}}
d := buscompose.Declared{Invokes: []string{"seat:node-login-shell.execute", "seat:node-login-shell.list", "shop.tool"},
Processes: []buscompose.ProcessPrincipal{{Serves: []string{"seat:node-login-shell.execute"}}}}
if got := markedNamed(d, seats); !slices.Equal(got, []string{"seat:node-login-shell.execute"}) {
t.Errorf("marked = %v", got)
}
m := catalogue.Manifest{Module: "shop", Invokes: []string{"seat:node-login-shell.execute"}}
if got := declaredFor(m, seats, nil).MarkedVerbs; !slices.Equal(got, []string{"seat:node-login-shell.execute"}) {
t.Errorf("the declaration carries %v, want the marked verb it invokes", got)
}
}