§616: the grants part resolves a consumed seat view to the seat's holder on record

Builds: design 47 G §616

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
2026-11-11 21:32:42 +01:00
parent f0d041b8dc
commit 0b81504139
2 changed files with 77 additions and 0 deletions
+43
View File
@@ -4830,3 +4830,46 @@ func TestTheGrantsPartKeepsWhatEachNodeRuns(t *testing.T) {
t.Errorf("grants_running = %+v, want the last word of ace.mod-c: stopped", said)
}
}
// A module naming a seat's view, `seat:<seat>.views.<state>`, is granted the view of the module holding the seat on record, so a
// new holder is granted with no change of its manifest (design 47 G §616).
func TestASeatNamedViewIsResolvedToItsHolder(t *testing.T) {
consumer := func(consumes ...string) catalogue.Manifest {
return catalogue.Manifest{Module: "mod-t", Version: "1", RunsAs: "mod-t", Consumes: consumes,
OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mod-t/broker"}}}
}
holder := func(node string) grants.Inputs {
return grants.Inputs{Nodes: []string{"a"}, Assigned: map[string][]string{"a": {"mod-t"}},
Placed: map[string]meshmoduleassigner.Assignments{"a": {Node: "a",
Holds: []meshmoduleassigner.Holding{{Claim: "mesh-module-assigner", Scope: "mesh", Module: node}}}}}
}
for _, row := range []struct {
name string
holder string
consumes []string
want []string
}{
{"resolved to the holder on record", "mesh-delivery-assigner", []string{"seat:mesh-module-assigner.views.assignments", "mesh-vault.node-logins"},
[]string{"mesh-delivery-assigner.views.assignments", "mesh-vault.node-logins"}},
{"a new holder is granted with no change of the manifest", "assigner-two", []string{"seat:mesh-module-assigner.views.seat-holders"},
[]string{"assigner-two.views.seat-holders"}},
{"no holder on record stays as written", "", []string{"seat:mesh-module-assigner.views.assignments"},
[]string{"seat:mesh-module-assigner.views.assignments"}},
} {
t.Run(row.name, func(t *testing.T) {
in := holder(row.holder)
if row.holder == "" {
in.Placed = nil
}
in.Manifests = map[string]catalogue.Manifest{"mod-t": consumer(row.consumes...)}
recs, _ := grants.ListRecords(in)
var got []string
for _, d := range recs.Assigned["a"] {
got = d.Consumes
}
if !slices.Equal(got, row.want) {
t.Errorf("consumes = %v, want %v", got, row.want)
}
})
}
}
@@ -87,6 +87,7 @@ func records(in Inputs, union bool) (buscompose.Records, []Gap) {
continue
}
declare := func(m catalogue.Manifest) buscompose.Declared {
m.Consumes = resolveSeatViews(m.Consumes, holders)
d := declaredFor(m, seats, declarers)
if len(in.Placed) > 0 {
d.Holds = heldWherePlaced(d.Holds, holders, node, m.Module)
@@ -178,6 +179,39 @@ func declaredFor(m catalogue.Manifest, seats map[string]catalogue.SeatDeclaratio
return d
}
// seatViewConsume is a `consumes` entry naming a seat's view as `seat:<seat>.views.<state>` (design 47 G §616).
const seatViewConsume = "seat:"
// resolveSeatViews resolves each `seat:<seat>.views.<state>` of a module's consumes to `<holder>.views.<state>`, the module
// holding the seat on record, as it resolves a seat's events: a new holder is granted with no change of the manifest (design
// 47 G §616). An entry whose seat has no holder on record stays as written, and grants nothing. Pure.
func resolveSeatViews(consumes []string, holders []catalogue.Held) []string {
var out []string
for i, c := range consumes {
rest, isSeat := strings.CutPrefix(c, seatViewConsume)
seatName, view, named := strings.Cut(rest, ".views.")
if !isSeat || !named || view == "" {
if out != nil {
out = append(out, c)
}
continue
}
if out == nil {
out = slices.Clone(consumes[:i])
}
holder := slices.IndexFunc(holders, func(h catalogue.Held) bool { return sameSeat(h.Claim, seatName) })
if holder < 0 {
out = append(out, c)
continue
}
out = append(out, holders[holder].Module+".views."+view)
}
if out == nil {
return consumes
}
return out
}
// consumedOf splits what a manifest consumes as the composer grants it: a seat's event on the seat's own subject (its
// watches), every other by its emitter's (novox/hq ADR 0118). A placed module and the node-engine's own manifest are split
// alike.