G4 hub-grants: the grants part grants a module with a program the stream info of EVENTS and its kept streams, and its own durables-composed

Builds: design 47 H2b §836 2., H-A-870 (hq 71803fa7)
This commit is contained in:
2026-11-27 03:12:57 +01:00
parent 0c3c930979
commit 016e2e94d7
3 changed files with 55 additions and 0 deletions
+34
View File
@@ -4228,6 +4228,40 @@ func TestGrants(t *testing.T) {
}
})
// H-A-870 (design 47 H2b §836 2.): a module with a program may ask the stream info of EVENTS and of each kept stream it
// consumes, and hears the grants part's durables-composed for its own node and module alone; one with no program neither.
t.Run("the event hub of a program: stream info and its wake", func(t *testing.T) {
const stream = "SEAT_mesh-conditions_findings-asked"
heard := []buscompose.Heard{{Stream: stream, Emitter: "mesh-conditions", Filters: []string{"mesh.seat.mesh-conditions.event.findings-asked"}}}
users, err := buscompose.Users(buscompose.Records{Nodes: []string{"b"},
Assigned: map[string][]buscompose.Declared{"b": {{Module: "mod-c", HasProgram: true, Hears: heard}, {Module: "mod-d", Hears: heard}}}})
if err != nil {
t.Fatal(err)
}
woke := map[string]bool{}
for _, u := range users {
if u.Kind != buscompose.KindModule {
continue
}
perms, err := buscompose.PermissionsFor(u)
if err != nil {
t.Fatal(err)
}
own := "mesh.seat.mesh-grants.event.durables-composed.b." + u.Module
woke[u.Module] = buscompose.MaySubscribe(perms, own)
want := u.Module == "mod-c"
if got := buscompose.MayPublish(perms, "$JS.API.STREAM.INFO.EVENTS") && buscompose.MayPublish(perms, "$JS.API.STREAM.INFO."+stream); got != want {
t.Errorf("%s: may ask the stream info of EVENTS and %s: %v, want %v", u.Module, stream, got, want)
}
if woke[u.Module] != want || buscompose.MaySubscribe(perms, "mesh.seat.mesh-grants.event.durables-composed.b.other") {
t.Errorf("%s: hears its durables-composed: %v (and another module's: want neither of the second), want %v", u.Module, woke[u.Module], want)
}
}
if len(woke) != 2 {
t.Fatalf("composed accounts of %v, want mod-c and mod-d", woke)
}
})
// 774/AC6 (novox/hq ADR 0561 §6), 1126/A1/AC1: the durable consumers an account needs, with the composed
// configuration, are created where the bus lacks them with no lease key at all (the controller ended by its
// unassignment, never by the lease write); one the bus holds is never changed.
@@ -52,3 +52,19 @@ func gatedEndedGrants(user string, marked, invokes, answers []string) (pub, sub
func GatedEndedSubject(seat, caller string) string {
return seatdef.EventSubject(seat, seatdef.GatedEndedEvent) + "." + caller
}
// hubGrants are what the event hub of a module's program asks beside its durables (design 47 H2b §836 2., H-A-870): the stream
// info of EVENTS and of each kept seat event's stream its module consumes (the hub binds a stream it finds), and its wake, the
// grants part's durables-composed for its own node and module. A module with no program has none.
func hubGrants(p Principal) (pub, sub []string) {
if p.Kind != KindModule || !p.HasProgram || !safeSubject.MatchString(p.Node) || !safeSubject.MatchString(p.Module) {
return nil, nil
}
pub = []string{"$JS.API.STREAM.INFO.EVENTS"}
for _, h := range p.Hears {
if safeSubject.MatchString(h.Stream) && strings.HasPrefix(h.Stream, seatdef.KeptStreamPrefix) {
pub = append(pub, "$JS.API.STREAM.INFO."+h.Stream)
}
}
return unique(pub), []string{seatdef.EventSubject(GrantsModule, "durables-composed") + "." + p.Node + "." + p.Module}
}
@@ -1147,6 +1147,11 @@ func permissionsFor(p Principal) (Permissions, error) {
}
pub = append(pub, heardGrants(p, p.Hears)...)
// 2a'. The event hub of its program (design 47 H2b §836 2., H-A-870): the stream info of EVENTS and of each kept
// stream its module consumes, and its wake, the grants part's durables-composed for this node and module.
hp, hs := hubGrants(p)
pub, sub = append(pub, hp...), append(sub, hs...)
// 2b. Events of a role it watches, under the seat's own namespace. Subscribe only: watching a
// role is hearing what it announced, not taking part in it.
sub = append(sub, watchedEvents(p.Watches)...)