From 3d058af14cb23d4f5ad6c3401791faa1df16c89a Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 12 Nov 2026 22:47:50 +0100 Subject: [PATCH] D1 (teller): the teller names its own module from its credential's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Its conditions' keys, its asks' subjects, its reader and emitter, its ends bucket and its tools' first views take the module its credential names (the tools: the module the runtime serves them as) instead of constants of its name; a guard test finds none in its code. Builds: design 47 G A-296, §428 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h --- .../cmd/mesh-delivery-teller-tools/main.go | 12 +++--- .../mesh-delivery-teller-tools/main_test.go | 2 +- .../mesh-delivery-teller/integration_test.go | 4 +- .../cmd/mesh-delivery-teller/main.go | 12 +++--- .../cmd/mesh-delivery-teller/names.go | 2 - .../cmd/mesh-delivery-teller/ownname_test.go | 38 +++++++++++++++++++ .../cmd/mesh-delivery-teller/teller.go | 10 +++-- .../cmd/mesh-delivery-teller/teller_test.go | 2 +- .../internal/ends/ends.go | 12 +++--- 9 files changed, 66 insertions(+), 28 deletions(-) create mode 100644 modules/mesh-delivery-teller/cmd/mesh-delivery-teller/ownname_test.go diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main.go index 98d7c87b..27a6035a 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main.go @@ -112,8 +112,8 @@ const ReadAnswersTool = "teller_read_answers" const marksState = "teller-marks" // ReadAnswersTools is the tool teller_read_answers over the state answers and its marks. -func ReadAnswersTools(values, marks views.Source, now func() time.Time) []stdio.Tool { - return []stdio.Tool{views.ReadTool("mesh-delivery-teller", ReadAnswersTool, "answers", +func ReadAnswersTools(module string, values, marks views.Source, now func() time.Time) []stdio.Tool { + return []stdio.Tool{views.ReadTool(module, ReadAnswersTool, "answers", "the operator's answers to the assigner's asks, by the ask's key.", values, marks, now)} } @@ -192,7 +192,7 @@ func askEnd(s stdio.KeptState, bound time.Duration) asker { } r, err := s.Put(key, json.RawMessage(value)) if err != nil { - return ends.End{}, fmt.Errorf("the end could not be written to %s: %w", ends.Bucket, err) + return ends.End{}, fmt.Errorf("the end could not be written to %s: %w", ends.Bucket(os.Getenv(stdio.ServedAs)), err) } mu.Lock() rev = r @@ -207,7 +207,7 @@ func askEnd(s stdio.KeptState, bound time.Duration) asker { case e := <-answered: return e, nil case <-wait.Done(): - return ends.End{}, fmt.Errorf("the teller did not answer within %s: is it running? its answer will be in %s.%s", bound, ends.Bucket, key) + return ends.End{}, fmt.Errorf("the teller did not answer within %s: is it running? its answer will be in %s.%s", bound, ends.Bucket(os.Getenv(stdio.ServedAs)), key) } } } @@ -216,9 +216,9 @@ func main() { // teller_first_views and teller_first_view_again: where the teller's first view of the assigner's asks stands, and // asking it again by hand (ADR 0615, design 25 § 12.2). tools := append(Tools(askEnd(stdio.State(ends.State), 25*time.Second), time.Now), - views.StatusTools("mesh-delivery-teller", "teller_first_views", "teller_first_view_again", stdio.State(views.StatusState), meshhandactsclient.Recorder{Ask: stdio.Ask}, time.Now)...) + views.StatusTools(os.Getenv(stdio.ServedAs), "teller_first_views", "teller_first_view_again", stdio.State(views.StatusState), meshhandactsclient.Recorder{Ask: stdio.Ask}, time.Now)...) tools = append(tools, AnswerTools(stdio.State("answers"))...) - tools = append(tools, ReadAnswersTools(views.KeptSource{State: stdio.State("answers")}, views.KeptSource{State: stdio.State(marksState)}, time.Now)...) + tools = append(tools, ReadAnswersTools(os.Getenv(stdio.ServedAs), views.KeptSource{State: stdio.State("answers")}, views.KeptSource{State: stdio.State(marksState)}, time.Now)...) tools = append(tools, WidensSaidTools(stdio.State(widensSaidState))...) if err := stdio.Serve("", tools); err != nil { fmt.Fprintf(os.Stderr, "[mesh-delivery-teller-tools] %v\n", err) diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main_test.go index 77b53f10..1ceca793 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main_test.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller-tools/main_test.go @@ -86,7 +86,7 @@ func (e entries) Get(key string) (*views.Entry, bool, error) { func TestTellerReadAnswersIsTheViewsReadToolOfTheAnswersState(t *testing.T) { values := entries{"hold.k1": {Value: json.RawMessage(`{"option":"keep"}`), Revision: 3}} - tool := ReadAnswersTools(values, entries{}, time.Now)[0] + tool := ReadAnswersTools("mesh-delivery-teller", values, entries{}, time.Now)[0] if tool.Name != "teller_read_answers" { t.Fatalf("the tool is %s", tool.Name) } 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 7df1c925..059a5628 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 @@ -102,7 +102,7 @@ const ( func fullConf(dir string) string { // ends is the teller's own state (manifest state entry ends), which the controller makes before it starts: a bed // 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)...), + teller := append(append(append(keepsOf(tellerAnswers), keepsOf(tellerAsked)...), keepsOf(ends.Bucket(tellerModule))...), seatAsk, seatCancel, seatCondition, "$JS.API.DIRECT.GET.KV_"+routerAsksBucket+".$KV."+routerAsksBucket+".mesh-delivery-teller.>") 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). @@ -186,7 +186,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, bucketsOf(tellerModule).marks: 1, bucketsOf(tellerModule).firstViews: 1, bucketsOf(tellerModule).findings: 1, bucketsOf(tellerModule).widensSaid: 1} { + for name, history := range map[string]uint8{tellerAnswers: answersHistory, tellerAsked: 1, ends.Bucket(tellerModule): 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) } 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 5a848e9e..01f8b1c9 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/main.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/main.go @@ -77,10 +77,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro return fmt.Errorf("the teller's connection for its tool calls: %w", err) } defer calls.Close() - client := &occ.Client{Module: tellerModule, State: state, Publish: publish, + client := &occ.Client{Module: cred.Module, State: state, Publish: publish, Record: recordVia(calls.Call, calls.Ask), Subscribe: decidedVia(hub.Handle, logger.Printf)} - t := &Teller{Asker: client, Store: state, Answers: kvAnswers{ctx: ctx, kv: kvs[0]}, - Say: sayVia(ctx, js, tellerModule), Logf: logger.Printf, Publish: publish, + t := &Teller{Module: cred.Module, Asker: client, Store: state, Answers: kvAnswers{ctx: ctx, kv: kvs[0]}, + Say: sayVia(ctx, js, cred.Module), Logf: logger.Printf, Publish: publish, // The teller's own events (its manifest's emits), on EVENTS under its module's subject. Emit: func(event string, body []byte, id string) error { _, err := js.Publish(ctx, cred.EventSubject(event), body, jetstream.WithMsgID(id)) @@ -109,7 +109,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro t.Answered = func(key, askID string, answer []byte) error { return calls.Emit(answeredEvent, Answered{Key: key, Ask: askID, Answer: answer}, stdio.EmitOptions{MessageID: answeredID(key, askID)}) } - reader := &views.ProcessReader{Module: tellerModule, Call: calls.Call, Logf: logger.Printf, Hub: hub} + reader := &views.ProcessReader{Module: cred.Module, Call: calls.Call, Logf: logger.Printf, Hub: hub} // The teller's finding stream is its `finding-events` entry, asked of the seat mesh-broker's show (design 47 G A-274, // §529, §577): the writer says its events under that binding's subjects. binding := process.NewBinding(meshbroker.Seat, cred.Module, calls.CallKept, logger.Printf, views.FindingEventsLocal) @@ -151,7 +151,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro } // 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, 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} + em := views.Emitter{Owner: cred.Module, 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) } @@ -167,7 +167,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro }() // A person ends one ask by hand with teller_end_ask, which writes the state ends (issue 774): watched as the gate's asks // are, once it is on the bus. - process.AwaitBucket(ctx, js, conn, ends.Bucket, "teller_end_ask is not answered; the asks still end when they are answered, lapse or their key is taken away", logger.Printf).Ready(func(kv jetstream.KeyValue) { + process.AwaitBucket(ctx, js, conn, ends.Bucket(cred.Module), "teller_end_ask is not answered; the asks still end when they are answered, lapse or their key is taken away", logger.Printf).Ready(func(kv jetstream.KeyValue) { go func() { if err := watchAsks(ctx, kv, func(key string, rev uint64, value []byte) { endAsked(ctx, t, kv, key, rev, value) }, func(string) {}, nil); err != nil { failed <- fmt.Errorf("watching the ends asked by hand: %w", err) 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 3bd9571f..44b303a1 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/names.go @@ -10,8 +10,6 @@ import ( // consumes) and the states it keeps itself; a unit row checks them against it (TestTheNamesAreTheManifests). No contract // names a holder (novox/hq ADR 0625 §4, ADR 0634 §1). const ( - tellerModule = "mesh-delivery-teller" - // answersState is the teller's own state answers, said as its views family views.answers, and marksState the state of // what that family said it up to. answersState = "answers" diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/ownname_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/ownname_test.go new file mode 100644 index 00000000..cebf35c4 --- /dev/null +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/ownname_test.go @@ -0,0 +1,38 @@ +package main + +import ( + "io/fs" + "os" + "path/filepath" + "regexp" + "strings" + "testing" +) + +// tellerModule is the module the tests run the teller as, as its credential would say it; its manifest's name is held equal to it +// by TestTheNamesAreTheManifests. +const tellerModule = "mesh-delivery-teller" + +// No code of the teller names its own module: its buckets, its conditions, its asks' subjects and its tools' first views take +// the module its credential (or the runtime that serves its tools) names (design 47 G A-296, §428). The manifest alone says it. +func TestNoCodeNamesTheTellersOwnModule(t *testing.T) { + name := regexp.MustCompile(`"` + regexp.QuoteMeta(tellerModule) + `(_[^"]*)?"`) + err := filepath.WalkDir("../..", func(path string, d fs.DirEntry, err error) error { + if err != nil || d.IsDir() || !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") { + return err + } + src, err := os.ReadFile(path) + if err != nil { + return err + } + for i, line := range strings.Split(string(src), "\n") { + if !strings.HasPrefix(strings.TrimSpace(line), "//") && name.MatchString(line) { + t.Errorf("%s:%d names the teller's own module: %s", path, i+1, strings.TrimSpace(line)) + } + } + return nil + }) + if err != nil { + t.Fatal(err) + } +} diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go index 355534a1..561444db 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller.go @@ -55,6 +55,8 @@ type asksReader interface { // Teller is the teller's logic; the program's wiring is main.go and decided.go. type Teller struct { + // Module is the module the teller runs as, its credential's (design 47 G A-296): its conditions and its asks are said under it. + Module string Asker routerAsks Store store Answers answers @@ -346,7 +348,7 @@ func oneLine(err error) string { } // conditionKey is the key of the condition about an ask. -func conditionKey(id string) string { return tellerModule + ".merge-ask." + id } +func (t *Teller) conditionKey(id string) string { return t.Module + ".merge-ask." + id } // askWords are the words the teller's conditions use for an ask: one of the assigner's. type askWords struct { @@ -374,7 +376,7 @@ func (t *Teller) raise(askID, headline, why string) { } k := assignerWords needs := k.needs - c := oc.Condition{Key: conditionKey(id), Severity: occ.SeverityWarning, Subject: oc.ConditionSubject{Scope: k.scope, ID: id}, State: occ.StateRaised, + c := oc.Condition{Key: t.conditionKey(id), Severity: occ.SeverityWarning, Subject: oc.ConditionSubject{Scope: k.scope, ID: id}, State: occ.StateRaised, Summary: k.noun + id + ": " + why, Headline: headline, Needs: needs, Explanation: occ.NeedsYou + needs + ". " + k.noun + id + ", " + why + ". " + k.nothing, Resolved: k.resolved} @@ -393,7 +395,7 @@ func (t *Teller) clear(askID string) { if err != nil || e == nil { return } - c := oc.Condition{Key: conditionKey(id), Subject: oc.ConditionSubject{Scope: assignerWords.scope, ID: id}, State: occ.StateCleared} + c := oc.Condition{Key: t.conditionKey(id), Subject: oc.ConditionSubject{Scope: assignerWords.scope, ID: id}, State: occ.StateCleared} if err := t.Say(c); err != nil { t.logf("the condition of %s could not be cleared: %v", id, err) return @@ -670,7 +672,7 @@ func (t *Teller) askAgain(a oc.Ask, msgID string) error { if _, err := t.Store.Create(keptKey(a.ID), occ.Kept{Ask: a, Asked: t.now()}); err != nil { return err } - if err := t.Publish(oc.AcceptSubjectAsk(tellerModule), a, msgID); err != nil { + if err := t.Publish(oc.AcceptSubjectAsk(t.Module), a, msgID); err != nil { _ = t.Store.Delete(keptKey(a.ID)) return err } diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller_test.go index 5c215f74..9ddb8565 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller_test.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/teller_test.go @@ -164,7 +164,7 @@ func newBed(t *testing.T) *bed { }, Subscribe: func(_ string, handle func(stdio.Envelope) error) error { b.hear = handle; return nil }, } - b.t = &Teller{Asker: b.client, Store: b.store, Answers: b.answers, Assigner: b.assigner, View: b.view, Publish: b.client.Publish, Now: func() time.Time { return now }, + b.t = &Teller{Module: tellerModule, Asker: b.client, Store: b.store, Answers: b.answers, Assigner: b.assigner, View: b.view, Publish: b.client.Publish, Now: func() time.Time { return now }, Say: func(c oc.Condition) error { if _, err := occ.EncodeCondition(c); err != nil { t.Errorf("a condition the router would refuse: %v", err) diff --git a/modules/mesh-delivery-teller/internal/ends/ends.go b/modules/mesh-delivery-teller/internal/ends/ends.go index 761a421c..a6f56eb3 100644 --- a/modules/mesh-delivery-teller/internal/ends/ends.go +++ b/modules/mesh-delivery-teller/internal/ends/ends.go @@ -18,14 +18,14 @@ import ( ) const ( - // module is the teller's own name (its manifest's module), the holder of the bucket. - module = "mesh-delivery-teller" - Tool = "teller_end_ask" - // State is the teller's state of ends asked by hand: the bucket mesh-delivery-teller_ends. - State = "ends" - Bucket = module + "_" + State + Tool = "teller_end_ask" + // State is the teller's state of ends asked by hand. + State = "ends" ) +// Bucket is that state's bucket, `_ends` of the module the teller runs as, its credential's (design 47 G A-296). +func Bucket(module string) string { return module + "_" + State } + // Result is the teller's answer to an end: which ask it found (its router id and the gate's or the assigner's key it was // asked for), whether this end ended it, and what it did in words. type Result struct {