G M-5: Hearing takes the function that says which events are defined
Builds: design 47 G §474, §644 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
@@ -289,14 +289,16 @@ type HeardPart struct {
|
|||||||
//
|
//
|
||||||
// Only an entry naming its emitter literally reaches a restricted stream: a wildcard emitter, `**` among them,
|
// Only an entry naming its emitter literally reaches a restricted stream: a wildcard emitter, `**` among them,
|
||||||
// never does, so nothing that hears every event hears a restricted stream by saying so. A `*` emitter before one
|
// never does, so nothing that hears every event hears a restricted stream by saying so. A `*` emitter before one
|
||||||
// event reaches each declaring module's unrestricted stream (design 47 G §386).
|
// event reaches each declaring module's unrestricted stream (design 47 G §386), only where defined, the function the
|
||||||
|
// grants part passes, says the event is one a seat definition of the seat list defines or one of mesh-sdk's finding
|
||||||
|
// events (§474, §644); any other `*` entry stays EVENTS' as before, and nil defines none.
|
||||||
func Hearing(consumer Manifest, shelf map[string]Manifest, machine string,
|
func Hearing(consumer Manifest, shelf map[string]Manifest, machine string,
|
||||||
values func(provider, setting string) []any) (parts []HeardPart, touches bool, onEvents []string) {
|
values func(provider, setting string) []any, defined func(event string) bool) (parts []HeardPart, touches bool, onEvents []string) {
|
||||||
byStream := map[string]*HeardPart{}
|
byStream := map[string]*HeardPart{}
|
||||||
var order []string
|
var order []string
|
||||||
for _, c := range consumer.Consumes {
|
for _, c := range consumer.Consumes {
|
||||||
emitter, rest, named := strings.Cut(c, ".")
|
emitter, rest, named := strings.Cut(c, ".")
|
||||||
if named && emitter == OneName && rest != "" && !strings.ContainsAny(rest, "*>") && rest != TheRest {
|
if named && emitter == OneName && rest != "" && !strings.ContainsAny(rest, "*>") && rest != TheRest && defined != nil && defined(rest) {
|
||||||
// A `*` emitter (design 47 G §386): the event from every module that declares it on a stream, never a
|
// A `*` emitter (design 47 G §386): the event from every module that declares it on a stream, never a
|
||||||
// restricted one; the entry stays EVENTS' too, for the modules that say it there.
|
// restricted one; the entry stays EVENTS' too, for the modules that say it there.
|
||||||
onEvents = append(onEvents, c)
|
onEvents = append(onEvents, c)
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ func TestAConsumerHearsOnlyWhatItAsksAndIsGranted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
reader := Manifest{Module: "reader", Consumes: []string{"mesh-mail.mail.**", "mesh-mail.account.added", "billing.paid"}}
|
reader := Manifest{Module: "reader", Consumes: []string{"mesh-mail.mail.**", "mesh-mail.account.added", "billing.paid"}}
|
||||||
|
|
||||||
parts, touches, onEvents := Hearing(reader, shelf, "ace", values)
|
parts, touches, onEvents := Hearing(reader, shelf, "ace", values, nil)
|
||||||
if !touches || len(parts) != 1 || parts[0].Stream.BusName() != "MAIL" {
|
if !touches || len(parts) != 1 || parts[0].Stream.BusName() != "MAIL" {
|
||||||
t.Fatalf("heard %+v", parts)
|
t.Fatalf("heard %+v", parts)
|
||||||
}
|
}
|
||||||
@@ -96,28 +96,28 @@ func TestAConsumerHearsOnlyWhatItAsksAndIsGranted(t *testing.T) {
|
|||||||
if !slices.Equal(onEvents, []string{"mesh-mail.account.added", "billing.paid"}) {
|
if !slices.Equal(onEvents, []string{"mesh-mail.account.added", "billing.paid"}) {
|
||||||
t.Fatalf("left on EVENTS: %v", onEvents)
|
t.Fatalf("left on EVENTS: %v", onEvents)
|
||||||
}
|
}
|
||||||
parts, _, _ = Hearing(reader, shelf, "shanks", values)
|
parts, _, _ = Hearing(reader, shelf, "shanks", values, nil)
|
||||||
if len(parts) != 1 || len(parts[0].Patterns) != 6 {
|
if len(parts) != 1 || len(parts[0].Patterns) != 6 {
|
||||||
t.Fatalf("on shanks reader hears %+v", parts)
|
t.Fatalf("on shanks reader hears %+v", parts)
|
||||||
}
|
}
|
||||||
|
|
||||||
narrow := Manifest{Module: "reader", Consumes: []string{"mesh-mail.mail.*.message.added"}}
|
narrow := Manifest{Module: "reader", Consumes: []string{"mesh-mail.mail.*.message.added"}}
|
||||||
parts, _, _ = Hearing(narrow, shelf, "ace", values)
|
parts, _, _ = Hearing(narrow, shelf, "ace", values, nil)
|
||||||
if len(parts) != 1 || !slices.Equal(parts[0].Patterns, []string{"mail.mesh.message.added"}) {
|
if len(parts) != 1 || !slices.Equal(parts[0].Patterns, []string{"mail.mesh.message.added"}) {
|
||||||
t.Fatalf("a narrower consumes heard %+v", parts)
|
t.Fatalf("a narrower consumes heard %+v", parts)
|
||||||
}
|
}
|
||||||
|
|
||||||
stranger := Manifest{Module: "stranger", Consumes: []string{"mesh-mail.mail.**"}}
|
stranger := Manifest{Module: "stranger", Consumes: []string{"mesh-mail.mail.**"}}
|
||||||
parts, touches, onEvents = Hearing(stranger, shelf, "ace", values)
|
parts, touches, onEvents = Hearing(stranger, shelf, "ace", values, nil)
|
||||||
if len(parts) != 0 || !touches || len(onEvents) != 0 {
|
if len(parts) != 0 || !touches || len(onEvents) != 0 {
|
||||||
t.Fatalf("a module not granted heard %+v (touches %v, on EVENTS %v)", parts, touches, onEvents)
|
t.Fatalf("a module not granted heard %+v (touches %v, on EVENTS %v)", parts, touches, onEvents)
|
||||||
}
|
}
|
||||||
everything := Manifest{Module: "audit", Consumes: []string{"**", "*.mail.**"}}
|
everything := Manifest{Module: "audit", Consumes: []string{"**", "*.mail.**"}}
|
||||||
parts, touches, _ = Hearing(everything, shelf, "ace", values)
|
parts, touches, _ = Hearing(everything, shelf, "ace", values, nil)
|
||||||
if len(parts) != 0 || touches {
|
if len(parts) != 0 || touches {
|
||||||
t.Fatalf("a wildcard emitter reached a module's stream: %+v", parts)
|
t.Fatalf("a wildcard emitter reached a module's stream: %+v", parts)
|
||||||
}
|
}
|
||||||
parts, _, _ = Hearing(reader, shelf, "ace", func(string, string) []any { return nil })
|
parts, _, _ = Hearing(reader, shelf, "ace", func(string, string) []any { return nil }, nil)
|
||||||
if len(parts) != 0 {
|
if len(parts) != 0 {
|
||||||
t.Fatalf("with no setting reader heard %+v", parts)
|
t.Fatalf("with no setting reader heard %+v", parts)
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ func TestAConsumerHearsOnlyWhatItAsksAndIsGranted(t *testing.T) {
|
|||||||
func TestAnUnrestrictedStreamIsHeardByWhoeverAsks(t *testing.T) {
|
func TestAnUnrestrictedStreamIsHeardByWhoeverAsks(t *testing.T) {
|
||||||
feed := Manifest{Module: "feed", Streams: []StreamDeclaration{{Name: "items", Events: []string{"item.*.added", "item.*.gone"}}}}
|
feed := Manifest{Module: "feed", Streams: []StreamDeclaration{{Name: "items", Events: []string{"item.*.added", "item.*.gone"}}}}
|
||||||
reader := Manifest{Module: "reader", Consumes: []string{"feed.item.**", "feed.item.x.added"}}
|
reader := Manifest{Module: "reader", Consumes: []string{"feed.item.**", "feed.item.x.added"}}
|
||||||
parts, touches, onEvents := Hearing(reader, map[string]Manifest{"feed": feed}, "ace", nil)
|
parts, touches, onEvents := Hearing(reader, map[string]Manifest{"feed": feed}, "ace", nil, nil)
|
||||||
if !touches || len(onEvents) != 0 || len(parts) != 1 ||
|
if !touches || len(onEvents) != 0 || len(parts) != 1 ||
|
||||||
!slices.Equal(parts[0].Patterns, []string{"item.*.added", "item.*.gone"}) {
|
!slices.Equal(parts[0].Patterns, []string{"item.*.added", "item.*.gone"}) {
|
||||||
t.Fatalf("heard %+v, on EVENTS %v", parts, onEvents)
|
t.Fatalf("heard %+v, on EVENTS %v", parts, onEvents)
|
||||||
@@ -165,13 +165,20 @@ func TestAStarEmitterHearsEachDeclaringModulesUnrestrictedStream(t *testing.T) {
|
|||||||
other := Manifest{Module: "c", Streams: []StreamDeclaration{{Name: "c-stuff", Events: []string{"other"}}}}
|
other := Manifest{Module: "c", Streams: []StreamDeclaration{{Name: "c-stuff", Events: []string{"other"}}}}
|
||||||
shelf := map[string]Manifest{"a": a, "b": b, "c": other, "mesh-mail": mail}
|
shelf := map[string]Manifest{"a": a, "b": b, "c": other, "mesh-mail": mail}
|
||||||
keeper := Manifest{Module: "keeper", Consumes: []string{"*.finding-written"}}
|
keeper := Manifest{Module: "keeper", Consumes: []string{"*.finding-written"}}
|
||||||
parts, touches, onEvents := Hearing(keeper, shelf, "ace", func(string, string) []any { return nil })
|
isDefined := func(e string) bool { return e == "finding-written" }
|
||||||
|
parts, touches, onEvents := Hearing(keeper, shelf, "ace", func(string, string) []any { return nil }, isDefined)
|
||||||
if !touches || len(parts) != 2 || parts[0].Emitter != "a" || parts[1].Emitter != "b" ||
|
if !touches || len(parts) != 2 || parts[0].Emitter != "a" || parts[1].Emitter != "b" ||
|
||||||
!slices.Equal(parts[1].Patterns, []string{"finding-written"}) || !slices.Equal(onEvents, []string{"*.finding-written"}) {
|
!slices.Equal(parts[1].Patterns, []string{"finding-written"}) || !slices.Equal(onEvents, []string{"*.finding-written"}) {
|
||||||
t.Fatalf("heard %+v (touches %v, on EVENTS %v)", parts, touches, onEvents)
|
t.Fatalf("heard %+v (touches %v, on EVENTS %v)", parts, touches, onEvents)
|
||||||
}
|
}
|
||||||
|
// §474, §644: a `*` entry before an event no definition names keeps its meaning on main, the shared stream alone
|
||||||
|
undefined := Manifest{Module: "late", Consumes: []string{"*.finding-written"}}
|
||||||
|
if parts, touches, onEvents := Hearing(undefined, shelf, "ace", func(string, string) []any { return nil },
|
||||||
|
func(string) bool { return false }); len(parts) != 0 || touches || !slices.Equal(onEvents, []string{"*.finding-written"}) {
|
||||||
|
t.Fatalf("an undefined event heard %+v (touches %v, on EVENTS %v)", parts, touches, onEvents)
|
||||||
|
}
|
||||||
restricted := Manifest{Module: "audit", Consumes: []string{"*.mail.mesh.message.added", "*.>"}}
|
restricted := Manifest{Module: "audit", Consumes: []string{"*.mail.mesh.message.added", "*.>"}}
|
||||||
if parts, _, _ := Hearing(restricted, shelf, "ace", func(string, string) []any { return nil }); len(parts) != 0 {
|
if parts, _, _ := Hearing(restricted, shelf, "ace", func(string, string) []any { return nil }, nil); len(parts) != 0 {
|
||||||
t.Fatalf("a wildcard reached %+v", parts)
|
t.Fatalf("a wildcard reached %+v", parts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user