Grants: a seat-named view also grants asking its holder's first-view tool, so a reader's first view is not refused by the bus (design 47 G §616; live start: the indexer's seat-holders view)

This commit is contained in:
2026-11-14 16:26:59 +01:00
parent b0d263c336
commit 5255ffa0c4
2 changed files with 31 additions and 5 deletions
+11 -5
View File
@@ -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)
}
}
})
}
}
@@ -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:<seat>.views.<state>` of a module's consumes whose seat has a holder on record, the
// holder's first-view tool `<holder>.<state>`: 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:<seat>.<state>` of a module's reads to `<holder>.<state>`, 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.