GR14: the keeper hears either finding stream form, each module publishing its own node's

A * emitter before a finding event reaches the stream a part asked for by the
template events (its finding-events) beside the old stream; a part's finding
stream is published on its own node's subjects alone.

Builds: design 47 G §386, §529, §515

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
2026-11-12 06:05:07 +01:00
parent a4fcf3de51
commit eb45c3c67c
5 changed files with 98 additions and 3 deletions
@@ -239,6 +239,16 @@ type boundGrants struct {
// the bus being the mesh's `<module>_<local>` (BusStateStreams) and a stream's subjects under `mesh.bus.<module>.<local>`;
// a binding naming any other is granted nothing.
func boundOf(module string, bindings []membership.BusBinding) boundGrants {
return boundOn(module, "", bindings)
}
// FindingEventsLocal is the local name a part asks its finding stream under, by the template events (design 47 G §529).
const FindingEventsLocal = "finding-events"
// boundOn is boundOf for the account of a module on node: the module's finding stream, whose subjects end in the machine
// (`mesh.bus.<module>.finding-events.<event>.<node>`), is published on its own node's subjects alone (§529). An empty node
// grants every machine's.
func boundOn(module, node string, bindings []membership.BusBinding) boundGrants {
var g boundGrants
for _, b := range bindings {
base := module + "_" + b.Local
@@ -263,7 +273,11 @@ func boundOf(module string, bindings []membership.BusBinding) boundGrants {
if b.Stream != base || b.Subject != "mesh.bus."+module+"."+b.Local {
continue
}
g.Streams = append(g.Streams, b.Subject+".>",
published := b.Subject + ".>"
if node != "" && b.Local == FindingEventsLocal && safeSubject.MatchString(node) {
published = b.Subject + ".*." + node
}
g.Streams = append(g.Streams, published,
"$JS.API.STREAM.INFO."+base, "$JS.API.STREAM.MSG.GET."+base, "$JS.API.DIRECT.GET."+base+".>",
"$JS.API.CONSUMER.CREATE."+base+".>", "$JS.API.CONSUMER.DELETE."+base+".>", "$JS.FC."+base+".>")
}
@@ -1068,7 +1068,7 @@ func permissionsFor(p Principal) (Permissions, error) {
// 5. Its state, and the state of others it reads (novox/hq ADR 0201): every one read and
// watched, its own written too.
// Its bus state asked in `requires` is granted as the old sections are (boundOf, ADR 0595 §1, issue 1966).
bound := boundOf(p.Module, p.Bound)
bound := boundOn(p.Module, p.Node, p.Bound)
kept := stateAccess{Module: p.Module, Node: p.Node, Keeps: append(slices.Clone(p.State), bound.States...), PerMachine: p.PerMachine,
ReadOnly: p.ReadOnly, Reads: p.Reads, KeyedReads: p.KeyedReads, Nodes: p.Nodes}
pub = append(pub, stateGrants(kept)...)
@@ -1178,7 +1178,7 @@ func permissionsFor(p Principal) (Permissions, error) {
// each assignment is issued, as it keeps each module's events under that module's own name.
for _, d := range p.Carries {
// Its bus state asked in `requires` as its old sections' (boundOf, ADR 0595 §1, §9, issue 1966).
bound := boundOf(d.Module, d.Bindings)
bound := boundOn(d.Module, p.Node, d.Bindings)
pub = append(pub, stateGrants(stateAccess{Module: d.Module, Node: p.Node, Keeps: append(stateNames(d.State), bound.States...),
PerMachine: perMachineNames(d.State), ReadOnly: readOnlyNames(d.State), Reads: d.Reads, KeyedReads: d.KeyedReads, Nodes: p.Nodes})...)
pub = append(pub, objectGrants(append(objectNames(d.Objects), bound.Objects...), d.ReadsObjects)...)
@@ -36,3 +36,23 @@ func TestStateObjectsAndSentStores(t *testing.T) {
t.Error("a reader of a sent store reads that one and writes none")
}
}
// A part's finding stream is published on its own node's subjects alone (design 47 G §529): the machine is the subject's last
// token, and another machine's is refused.
func TestFindingEventsOnOwnNodeOnly(t *testing.T) {
bound := []membership.BusBinding{{Local: "finding-events", Storage: catalogue.StorageStream, Template: catalogue.TemplateEvents,
Stream: "shop_finding-events", Subject: "mesh.bus.shop.finding-events"}}
perms, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: "shop", Bound: bound})
if err != nil {
t.Fatal(err)
}
for subject, want := range map[string]bool{
"mesh.bus.shop.finding-events.finding-written.one": true,
"mesh.bus.shop.finding-events.finding-written.two": false,
"mesh.bus.shop.finding-events.findings-stated.two": false,
} {
if got := MayPublish(perms, subject); got != want {
t.Errorf("may publish %s: %v, want %v", subject, got, want)
}
}
}