Grants: a watched seat event takes its definition's subject parts as * for any scope
mesh-catalog's seat.json gives catalog-revision the subject catalog-revision.<branch> (likewise source-moved.<branch>, group-ended.<branch>.<group>, owed.<repository>.<number>). watchedEvents widened only a node seat the node-engine holds (machineEvent), so the consumer and subscribe grant of a module consuming mesh-catalog.catalog-revision (node-tools, builder, teller, pipeline) stayed on the bare subject and never took the branch-form event. One rule now (watchedEventSubject, used by the grants and the bus module's consumer): each part is *. A held consumer gains the filter through AddFilters (grants/consumers.go). Builds: design 47 G (seat definition subjects with parts) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -1641,3 +1641,38 @@ func aRuntimeWithholdsTheMarks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A watched seat event whose definition gives a subject with parts (mesh-catalog's `catalog-revision.<branch>`) is heard on
|
||||
// each part as `*`, for a seat of any scope: the consumer's filter and the subscribe grant both, since the bare subject
|
||||
// matches no event the holder says.
|
||||
func TestWatchedEventSubjectTakesTheDefinitionsParts(t *testing.T) {
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
seat Seat
|
||||
event string
|
||||
want string
|
||||
}{
|
||||
{"mesh seat, bare name", Seat{Name: "mesh-catalog", Scope: "mesh", EventSubjects: map[string]string{"catalog-revision.*": "catalog-revision.<branch>"}},
|
||||
"catalog-revision", "mesh.seat.mesh-catalog.event.catalog-revision.*"},
|
||||
{"mesh seat, local name", Seat{Name: "mesh-catalog", Scope: "mesh", EventSubjects: map[string]string{"catalog-revision.*": "catalog-revision.<branch>"}},
|
||||
"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.*.*"},
|
||||
{"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>"}},
|
||||
"catalog", "mesh.seat.mesh-catalog.event.catalog"},
|
||||
} {
|
||||
p := Principal{Kind: KindModule, Node: "novox", Module: "node-tools"}
|
||||
row.seat.Emits = []string{row.event}
|
||||
p.Watches = []Seat{row.seat}
|
||||
consumer, ok := ConsumerFor(p)
|
||||
if !ok || !slices.Contains(consumer.Filters, row.want) {
|
||||
t.Errorf("%s: consumer filters %v (%v), want %s", row.name, consumer.Filters, ok, row.want)
|
||||
}
|
||||
perms, err := PermissionsFor(p)
|
||||
if err != nil || !MaySubscribe(perms, strings.Replace(row.want, "*", "main", 1)) {
|
||||
t.Errorf("%s: the watcher may not subscribe %s (%v)", row.name, row.want, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,10 +101,7 @@ func keeperConsumer(p Principal) (Consumer, bool) {
|
||||
continue
|
||||
}
|
||||
for _, e := range w.Emits {
|
||||
if pattern, ok := machineEvent(w, e); ok {
|
||||
e = anyMachine(pattern)
|
||||
}
|
||||
filters = append(filters, seatSubject(w, "event", e))
|
||||
filters = append(filters, watchedEventSubject(w, e))
|
||||
}
|
||||
}
|
||||
// And the events of the seats its module uses that are said to it by name, the operator channel's `decided` for its own
|
||||
|
||||
@@ -1837,15 +1837,47 @@ func watchedEvents(watches []Seat) []string {
|
||||
continue
|
||||
}
|
||||
for _, e := range w.Emits {
|
||||
if pattern, ok := machineEvent(w, e); ok {
|
||||
e = anyMachine(pattern)
|
||||
}
|
||||
out = append(out, seatSubject(w, "event", e))
|
||||
out = append(out, watchedEventSubject(w, e))
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// watchedEventSubject is the subject a watcher of the seat w hears its event e on: an event naming its holder's machine from
|
||||
// every machine (machineEvent), and any other event whose definition gives a subject with parts (`catalog-revision.<branch>`
|
||||
// of mesh-catalog's seat.json) on that subject with each part as `*`, whatever the seat's scope, since a consume names the
|
||||
// event by its bare name and the bare subject matches no event the holder says (the same rule as mesh-sdk's
|
||||
// buscompose EventSubjects).
|
||||
func watchedEventSubject(w Seat, e string) string {
|
||||
if pattern, ok := machineEvent(w, e); ok {
|
||||
return seatSubject(w, "event", anyMachine(pattern))
|
||||
}
|
||||
for local, subject := range w.EventSubjects {
|
||||
rest, longer := strings.CutPrefix(local, e+".")
|
||||
if local != e && !(longer && onlyParts(rest)) {
|
||||
continue
|
||||
}
|
||||
toks := strings.Split(subject, ".")
|
||||
for i, t := range toks {
|
||||
if len(t) > 2 && t[0] == '<' && t[len(t)-1] == '>' {
|
||||
toks[i] = "*"
|
||||
}
|
||||
}
|
||||
return seatSubject(w, "event", strings.Join(toks, "."))
|
||||
}
|
||||
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, ".") {
|
||||
if t != "*" {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// invokedSubjects is the publish side of a grant to call tools: one subject per `<module>.<tool>`,
|
||||
// or the whole tool namespace for `*`. A person's authority and a module's `invokes` are both this
|
||||
// (novox/hq ADR 0152), so a malformed entry is refused in one place, before it could be widened into
|
||||
|
||||
Reference in New Issue
Block a user