diff --git a/modules/mesh-grants/internal/buscompose/nats.go b/modules/mesh-grants/internal/buscompose/nats.go index 814e6eed..a325a871 100644 --- a/modules/mesh-grants/internal/buscompose/nats.go +++ b/modules/mesh-grants/internal/buscompose/nats.go @@ -500,7 +500,9 @@ func machineEvent(s Seat, e string) (string, bool) { return "", false case perMachineEvents[e]: return strings.TrimSuffix(e, "*") + nodeToken, true - case s.HeldByTheEngine: + case s.HeldByTheEngine || strings.Contains(s.EventSubjects[e], nodeToken): + // The node-engine's seats, and any node seat whose definition names `` in an event's subject (a build seat's + // `step-ended.`, `toolchain-reported.`; lead answer A-399). if subject, ok := s.EventSubjects[e]; ok { toks := strings.Split(subject, ".") found := false @@ -522,6 +524,30 @@ func machineEvent(s Seat, e string) (string, bool) { return "", false } +// pulledSeatEvents are the events a holder of a seat pulled by kind (and not kinded) says: each the seat emits and no caller +// names, on its own machine where the event names one (machineEvent), node "" giving any machine's (the membership's form). +func pulledSeatEvents(s Seat, node string) []string { + if !s.PulledByKind || s.Kinded { + return nil + } + var out []string + for _, e := range s.Emits { + if namesVerb(s.ByCaller, e) { + continue + } + if pattern, ok := machineEvent(s, e); ok { + if node == "" { + out = append(out, seatSubject(s, "event", anyMachine(pattern))) + } else { + out = append(out, seatSubject(s, "event", onMachine(pattern, node))) + } + continue + } + out = append(out, seatSubject(s, "event", e)) + } + return out +} + // anyMachine is a machineEvent pattern a watcher hears: every machine's. func anyMachine(pattern string) string { return strings.ReplaceAll(pattern, nodeToken, "*") } @@ -1114,6 +1140,9 @@ func permissionsFor(p Principal) (Permissions, error) { for _, t := range s.Serves { sub = append(sub, seatToolSubjects(s, t, p.Node)...) } + // And a seat pulled by kind says its own events, as any held seat does, its machine's alone (lead answer A-399: + // a build seat's step-ended and toolchain-reported were granted to nobody). + pub = append(pub, pulledSeatEvents(s, p.Node)...) continue } // Taking work from the role's queue: the worker consumer every holder shares (asked diff --git a/modules/mesh-grants/internal/buscompose/pulledevents_test.go b/modules/mesh-grants/internal/buscompose/pulledevents_test.go new file mode 100644 index 00000000..dd3b7891 --- /dev/null +++ b/modules/mesh-grants/internal/buscompose/pulledevents_test.go @@ -0,0 +1,27 @@ +package buscompose + +import ( + "slices" + "testing" +) + +// A-399: the holder of a seat pulled by kind says the seat's own events on its machine (a build seat's step-ended and +// toolchain-reported, `.`); on 2026-11-14 they were granted to nobody, so the builder never heard a toolchain. +func TestAPulledSeatsHolderSaysItsEvents(t *testing.T) { + held := Seat{Name: "node-build-go", Scope: "node", Accepts: []string{"delivery"}, PulledByKind: true, + Emits: []string{"step-ended", "toolchain-reported"}, + EventSubjects: map[string]string{"step-ended": "step-ended.", "toolchain-reported": "toolchain-reported."}} + perms, err := PermissionsFor(Principal{Kind: KindModule, Node: "shanks", Module: "mesh-build-go", Holds: []Seat{held}}) + if err != nil { + t.Fatal(err) + } + for _, want := range []string{"mesh.seat.node-build-go.event.step-ended.shanks", "mesh.seat.node-build-go.event.toolchain-reported.shanks"} { + if !slices.Contains(perms.Publish, want) { + t.Errorf("the holder's account is not granted %s", want) + } + } + tr := SeatTrafficOf("mesh-build-go", []Seat{held}, nil, nil) + if !slices.Contains(tr.Publish, "mesh.seat.node-build-go.event.toolchain-reported.*") { + t.Errorf("the membership does not list toolchain-reported: %v", tr.Publish) + } +} diff --git a/modules/mesh-grants/internal/buscompose/seattraffic.go b/modules/mesh-grants/internal/buscompose/seattraffic.go index fc34cfe9..7e73a016 100644 --- a/modules/mesh-grants/internal/buscompose/seattraffic.go +++ b/modules/mesh-grants/internal/buscompose/seattraffic.go @@ -184,6 +184,8 @@ func SeatTrafficOf(module string, holds, uses, watches []Seat) SeatTraffic { t.Publish = append(t.Publish, seatSubject(s, "event", e+".*")) } } + // A seat pulled by kind: its own events, so the runtime carrying the holder may say them (A-399). + t.Publish = append(t.Publish, pulledSeatEvents(s, "")...) if kind != "" { for _, v := range s.Proofs { t.Publish = append(t.Publish, seatSubject(s, "proof", v+"."+kind))