diff --git a/modules/mesh-grants/grants_test.go b/modules/mesh-grants/grants_test.go index 8cbc1be8..ac07b86b 100644 --- a/modules/mesh-grants/grants_test.go +++ b/modules/mesh-grants/grants_test.go @@ -5082,13 +5082,14 @@ func TestASeatNamedViewIsResolvedToItsHolder(t *testing.T) { holder string consumes []string want []string + asks []string // the holder's first-view tools the view grants beside its events }{ {"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"}}, + []string{"mesh-delivery-assigner.views.assignments", "mesh-vault.node-logins"}, []string{"mesh-delivery-assigner.assignments"}}, {"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"}}, + []string{"assigner-two.views.seat-holders"}, []string{"assigner-two.seat-holders"}}, {"no holder on record stays as written", "", []string{"seat:mesh-module-assigner.views.assignments"}, - []string{"seat:mesh-module-assigner.views.assignments"}}, + []string{"seat:mesh-module-assigner.views.assignments"}, nil}, } { t.Run(row.name, func(t *testing.T) { in := holder(row.holder) @@ -5097,13 +5098,18 @@ func TestASeatNamedViewIsResolvedToItsHolder(t *testing.T) { } in.Manifests = map[string]catalogue.Manifest{"mod-t": consumer(row.consumes...)} recs, _ := grants.ListRecords(in) - var got []string + var got, asks []string for _, d := range recs.Assigned["a"] { - got = d.Consumes + got, asks = d.Consumes, d.Invokes } if !slices.Equal(got, row.want) { t.Errorf("consumes = %v, want %v", got, row.want) } + for _, a := range row.asks { + if !slices.Contains(asks, a) { + t.Errorf("invokes = %v, want %s among them: the reader's first view is asked of the holder's tool", asks, a) + } + } }) } } diff --git a/modules/mesh-grants/internal/grants/records.go b/modules/mesh-grants/internal/grants/records.go index 20b00004..11253873 100644 --- a/modules/mesh-grants/internal/grants/records.go +++ b/modules/mesh-grants/internal/grants/records.go @@ -104,6 +104,7 @@ func records(in Inputs, union bool) (buscompose.Records, []Gap) { continue } declare := func(m catalogue.Manifest) buscompose.Declared { + m.Invokes = slices.Concat(m.Invokes, seatViewTools(m.Consumes, holders)) m.Consumes = resolveSeatViews(m.Consumes, holders) m.Reads = resolveSeatReads(m.Reads, holders) d := declaredFor(m, seats, declarers) @@ -250,6 +251,25 @@ func resolveSeatViews(consumes []string, holders []catalogue.Held) []string { return out } +// seatViewTools is, for each `seat:.views.` of a module's consumes whose seat has a holder on record, the +// holder's first-view tool `.`: a reader takes its first view by asking that tool and then follows the +// events, so the view grants both (design 47 G ยง616); the events alone left the reader's first view refused by the bus. +// Pure. +func seatViewTools(consumes []string, holders []catalogue.Held) []string { + var out []string + for _, c := range consumes { + rest, isSeat := strings.CutPrefix(c, seatViewConsume) + seatName, view, named := strings.Cut(rest, ".views.") + if !isSeat || !named || view == "" { + continue + } + if h := slices.IndexFunc(holders, func(h catalogue.Held) bool { return sameSeat(h.Claim, seatName) }); h >= 0 { + out = append(out, holders[h].Module+"."+view) + } + } + return out +} + // resolveSeatReads resolves each `seat:.` of a module's reads to `.`, the module holding the seat // on record, as resolveSeatViews does a view: a new holder is read with no change of the manifest (design 47 G A-116). An entry // whose seat has no holder on record stays as written, and grants nothing. Pure.