From 0b815041396852733182ea56f0e2e77bf8c11614 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 11 Nov 2026 21:32:42 +0100 Subject: [PATCH] =?UTF-8?q?=C2=A7616:=20the=20grants=20part=20resolves=20a?= =?UTF-8?q?=20consumed=20seat=20view=20to=20the=20seat's=20holder=20on=20r?= =?UTF-8?q?ecord?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 G §616 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ --- modules/mesh-grants/grants_test.go | 43 +++++++++++++++++++ .../mesh-grants/internal/grants/records.go | 34 +++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/modules/mesh-grants/grants_test.go b/modules/mesh-grants/grants_test.go index 380e99ae..07a8c718 100644 --- a/modules/mesh-grants/grants_test.go +++ b/modules/mesh-grants/grants_test.go @@ -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:.views.`, 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) + } + }) + } +} diff --git a/modules/mesh-grants/internal/grants/records.go b/modules/mesh-grants/internal/grants/records.go index bb06a96b..1b1e6bef 100644 --- a/modules/mesh-grants/internal/grants/records.go +++ b/modules/mesh-grants/internal/grants/records.go @@ -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:.views.` (design 47 G §616). +const seatViewConsume = "seat:" + +// resolveSeatViews resolves each `seat:.views.` of a module's consumes to `.views.`, 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.