diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go index 84fdcc65..f9ad00e9 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go @@ -98,7 +98,7 @@ func fullConf(dir string) string { // without it held the start ten seconds on a read the bus never answered, and the tests raced that stall. teller := append(append(append(keepsOf(tellerAnswers), keepsOf(tellerAsked)...), keepsOf(ends.Bucket)...), seatAsk, seatCancel, seatCondition, "$JS.API.DIRECT.GET.KV_"+routerAsksBucket+".$KV."+routerAsksBucket+".mesh-delivery-teller.>") - teller = append(teller, keepsOf(widensSaidBucket)...) // design 47 G §335: the state widens-said + teller = append(teller, keepsOf(bucketsOf(tellerModule).widensSaid)...) // design 47 G §335: the state widens-said // The durable consumer on EVENTS the controller makes for the seat it uses, pulled and acknowledged (issue 1126). teller = append(teller, "$JS.API.CONSUMER.INFO.EVENTS."+tellerConsumer, "$JS.API.CONSUMER.MSG.NEXT.EVENTS."+tellerConsumer, "$JS.ACK.EVENTS."+tellerConsumer+".>") // The finding writer finds the stream of the keeper's findings-asked (design 47 G §384): the bed has none, so it is @@ -106,11 +106,11 @@ func fullConf(dir string) string { teller = append(teller, "$JS.API.STREAM.NAMES") // The manifest's emits (ADR 0596 §2; design 47 G A-175: its answers as its views family) and its marks state (A-178). teller = append(teller, "mesh.mod.mesh-delivery-teller.event.answered", "mesh.mod.mesh-delivery-teller.event.ask-ended", "mesh.mod.mesh-delivery-teller.event.views.answers") - teller = append(teller, keepsOf(marksBucket)...) + teller = append(teller, keepsOf(bucketsOf(tellerModule).marks)...) // The assigner's asks and the view's answers, each by its read tool and its views family (ADR 0615, DLV-M3; A-175), and the // teller's own first-views and findings; the buckets themselves are no longer the teller's to read. - teller = append(append(append(teller, viewstest.Grants(assignerModule, assignerModule+".assigner_read_asks", tellerConsumer)...), viewstest.Grants(viewModule, viewModule+"."+viewstate.ViewAnswersReadTool, tellerConsumer)...), keepsOf(firstViewsBucket)...) - teller = append(teller, keepsOf(findingsBucket)...) + teller = append(append(append(teller, viewstest.Grants(assignerModule, assignerModule+".assigner_read_asks", tellerConsumer)...), viewstest.Grants(viewModule, viewModule+"."+viewstate.ViewAnswersReadTool, tellerConsumer)...), keepsOf(bucketsOf(tellerModule).firstViews)...) + teller = append(teller, keepsOf(bucketsOf(tellerModule).findings)...) view := append(append(readOf(tellerAnswers), readOf(assignerAsks)...), keepsOf(viewAnswers)...) assigner := keepsOf(assignerAsks) return fmt.Sprintf(` @@ -175,7 +175,7 @@ func startFull(t *testing.T) *fullBed { } ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) t.Cleanup(cancel) - for name, history := range map[string]uint8{tellerAnswers: answersHistory, tellerAsked: 1, ends.Bucket: 1, routerAsksBucket: 1, assignerAsks: 5, viewAnswers: 5, marksBucket: 1, firstViewsBucket: 1, findingsBucket: 1, widensSaidBucket: 1} { + for name, history := range map[string]uint8{tellerAnswers: answersHistory, tellerAsked: 1, ends.Bucket: 1, routerAsksBucket: 1, assignerAsks: 5, viewAnswers: 5, bucketsOf(tellerModule).marks: 1, bucketsOf(tellerModule).firstViews: 1, bucketsOf(tellerModule).findings: 1, bucketsOf(tellerModule).widensSaid: 1} { if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: name, History: history}); err != nil { t.Fatal(err) } @@ -253,7 +253,7 @@ func TestCredentialsWriteOnlyTheirOwnBuckets(t *testing.T) { // 1343/AC4 who jetstream.JetStream bucket string key string - }{{teller, tellerAnswers, "hold.a"}, {teller, marksBucket, "answers"}, {assigner, assignerAsks, "hold.a"}, {view, viewAnswers, "hold.a.view"}} { + }{{teller, tellerAnswers, "hold.a"}, {teller, bucketsOf(tellerModule).marks, "answers"}, {assigner, assignerAsks, "hold.a"}, {view, viewAnswers, "hold.a.view"}} { if err := b.put(t, c.who, c.bucket, c.key); err != nil { t.Errorf("a credential cannot write its own %s: %v", c.bucket, err) } diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/main.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/main.go index 51cf7eac..28c506c7 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/main.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/main.go @@ -52,8 +52,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro } defer conn.Close() // The answers it writes and what it asked: its own work, so each stops the start, naming its grant. + own := bucketsOf(cred.Module) var kvs [3]jetstream.KeyValue - for i, name := range []string{answersBucket, askedBucket, widensSaidBucket} { + for i, name := range []string{own.answers, own.asked, own.widensSaid} { if kvs[i], err = process.EssentialBucket(ctx, js, "teller", name, "write an answer, remember what it asked or remember what it said of a widening"); err != nil { return err } @@ -132,13 +133,13 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro return err } viewKV := jetstream.KeyValue(answered) - reader.Start(ctx, js, cred, process.AwaitBucket(ctx, js, conn, firstViewsBucket, "teller_first_views reads nothing and teller_first_view_again is not heard", logger.Printf)) + reader.Start(ctx, js, cred, process.AwaitBucket(ctx, js, conn, own.firstViews, "teller_first_views reads nothing and teller_first_view_again is not heard", logger.Printf)) // Every part has registered: the hub pulls the module's durable. if err := hub.Start(ctx, js, cred); err != nil { return fmt.Errorf("the consumer %s on %s cannot be read (%v): the teller hears no answer without it, so it stops", cred.EventConsumerName(), process.EventsStream, err) } // The teller says its own answers as its views family (A-175, A-178): once its marks state is bound. - process.AwaitBucket(ctx, js, conn, marksBucket, "no answer is said on the views family, so the view waits on its first view", logger.Printf).Ready(func(mk jetstream.KeyValue) { + process.AwaitBucket(ctx, js, conn, own.marks, "no answer is said on the views family, so the view waits on its first view", logger.Printf).Ready(func(mk jetstream.KeyValue) { em := views.Emitter{Owner: tellerModule, Subject: cred.EventSubject, Publish: views.JetStreamPublish(js), Marks: mk, Findings: writer, Logf: logger.Printf} if err := em.Start(ctx, answersState, kvs[0], failed); err != nil { logger.Printf("%v: the view asks the first view of the answers at each change until the teller starts again", err) @@ -173,19 +174,5 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro } } -// askedBucket is the teller's state bucket asked, `_`: what it asked of the router and which condition it -// raised (manifest state entry asked, novox/hq ADR 0437 §4). -const askedBucket = tellerModule + "_asked" - -// The teller's own states of its first view of the assigner's asks (views.StatusState) and of its findings, where the -// condition keeper raises a first view unanswered past its bound (ADR 0615 §6). -var ( - firstViewsBucket = tellerModule + "_" + views.StatusState - findingsBucket = tellerModule + "_findings" -) - // assignerAsksState is the assigner's state of its asks (assignerAsksBucket). const assignerAsksState = "asks" - -// marksBucket is the teller's state of what its views family said its answers up to (A-178). -const marksBucket = tellerModule + "_" + marksState diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names.go index a029289f..b10b2e47 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names.go @@ -1,6 +1,10 @@ package main -import "encoding/json" +import ( + "encoding/json" + + "git.novox.be/novox/mesh-sdk/go/views" +) // The holders and buckets the teller names, taken from its own manifest (module.json: its name, what it invokes and // consumes) and the states it keeps itself; a unit row checks them against it (TestTheNamesAreTheManifests). No contract @@ -14,14 +18,23 @@ const ( // what that family said it up to. answersState = "answers" marksState = "teller-marks" - // answersBucket is the teller's own state answers. - answersBucket = tellerModule + "_" + answersState - // widensSaidBucket is the teller's own state widens-said, the last commit it said a widening of per module and branch. - widensSaidBucket = tellerModule + "_" + widensSaidState // The revisions the teller's answers keep per key. answersHistory = 5 ) +// ownBuckets are the teller's own state buckets, `_`, the module its credential's (design 47 G A-296): answers, +// asked (what it asked of the router and which condition it raised, ADR 0437 §4), widens-said (the last commit it said a widening +// of per module and branch), its first views (views.StatusState) and findings (ADR 0615 §6), and the marks of what its views +// family said its answers up to (A-178). +type ownBuckets struct{ answers, asked, widensSaid, firstViews, findings, marks string } + +// bucketsOf names the teller's own buckets from module, its credential's. +func bucketsOf(module string) ownBuckets { + b := func(state string) string { return module + "_" + state } + return ownBuckets{answers: b(answersState), asked: b("asked"), widensSaid: b(widensSaidState), firstViews: b(views.StatusState), + findings: b("findings"), marks: b(marksState)} +} + // answerKey is the key, in the teller's answers, of its answer to the ask at askKey: the same string. func answerKey(askKey string) string { return askKey } diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names_test.go index 505f6121..99dabb58 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names_test.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names_test.go @@ -45,11 +45,13 @@ func TestTheNamesAreTheManifests(t *testing.T) { if want := "views." + answersState; !slices.Contains(m.Emits, want) { t.Errorf("the teller says %s, its manifest's emits are %v", want, m.Emits) } + // A-296: the teller's own buckets are named from its credential's module, each a state its manifest keeps. var own []string for _, s := range m.State { - own = append(own, tellerModule+"_"+s.Name) + own = append(own, "a-teller_"+s.Name) } - for _, want := range []string{answersBucket, marksBucket} { + b := bucketsOf("a-teller") + for _, want := range []string{b.answers, b.asked, b.widensSaid, b.firstViews, b.marks} { // findings is a requires state if !slices.Contains(own, want) { t.Errorf("the teller keeps %s, its manifest's states are %v", want, own) }