Grants: a consumed seat event matches the seat's event of that name whatever parts its subject has; a consume of a seat that says no such event is refused aloud, never a module's event

Builds: design 47 G A-409
This commit is contained in:
2026-11-14 22:55:59 +01:00
parent 0071181fb1
commit da82c2cf80
7 changed files with 166 additions and 24 deletions
@@ -1658,6 +1658,8 @@ func TestWatchedEventSubjectTakesTheDefinitionsParts(t *testing.T) {
"catalog-revision.*", "mesh.seat.mesh-catalog.event.catalog-revision.*"},
{"several parts", Seat{Name: "mesh-pipeline-runner", Scope: "mesh", EventSubjects: map[string]string{"group-ended.*.*": "group-ended.<branch>.<group>"}},
"group-ended", "mesh.seat.mesh-pipeline-runner.event.group-ended.*.*"},
{"a part between words", Seat{Name: "mesh-pipeline-runner", Scope: "mesh", EventSubjects: map[string]string{"milestone.*.asked": "milestone.<milestone>.asked"}},
"milestone.asked", "mesh.seat.mesh-pipeline-runner.event.milestone.*.asked"},
{"event without parts", Seat{Name: "mesh-catalog", Scope: "mesh", EventSubjects: map[string]string{"catalog-revision.*": "catalog-revision.<branch>"}},
"registration-changed", "mesh.seat.mesh-catalog.event.registration-changed"},
{"another event sharing a prefix", Seat{Name: "mesh-catalog", Scope: "mesh", EventSubjects: map[string]string{"catalog-revision.*": "catalog-revision.<branch>"}},
@@ -1887,8 +1887,7 @@ func watchedEventSubject(w Seat, e string) string {
return seatSubject(w, "event", anyMachine(pattern))
}
for local, subject := range w.EventSubjects {
rest, longer := strings.CutPrefix(local, e+".")
if local != e && !(longer && onlyParts(rest)) {
if local != e && localName(local) != e {
continue
}
toks := strings.Split(subject, ".")
@@ -1902,14 +1901,16 @@ func watchedEventSubject(w Seat, e string) string {
return seatSubject(w, "event", e)
}
// onlyParts says every token of rest is `*`: what a definition's local name adds to the event's bare name.
func onlyParts(rest string) bool {
for _, t := range strings.Split(rest, ".") {
// localName is an event's name from its local form: the tokens that are not a part (`*`), so `milestone.*.asked` is
// `milestone.asked` and `catalog-revision.*` is `catalog-revision`.
func localName(local string) string {
var words []string
for _, t := range strings.Split(local, ".") {
if t != "*" {
return false
words = append(words, t)
}
}
return true
return strings.Join(words, ".")
}
// invokedSubjects is the publish side of a grant to call tools: one subject per `<module>.<tool>`,