From a37cde8bcc38571dc92adb1f35d31dc145173d68 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 18:57:21 +0100 Subject: [PATCH] mesh-config: the start waits for an owner view's Ready, the handlers ask the views' Unread beside the own copies' (review r1 finding 3) Builds: design 47 H2 H-A-708 (2), row S8 --- modules/mesh-config/cmd/mesh-config/main.go | 16 ++++++++------ .../mesh-config/cmd/mesh-config/ownerviews.go | 21 ++++++++++++------- .../cmd/mesh-config/ownerviews_test.go | 11 ++++++++-- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/modules/mesh-config/cmd/mesh-config/main.go b/modules/mesh-config/cmd/mesh-config/main.go index 3d1a2d9d5..9bfeb5307 100644 --- a/modules/mesh-config/cmd/mesh-config/main.go +++ b/modules/mesh-config/cmd/mesh-config/main.go @@ -58,14 +58,18 @@ func (r runtimeStore) Get(state, key string) (*Entry, error) { return &Entry{Key: e.Key, Value: e.Value, Revision: e.Revision}, nil } -// Away is the fault `away` while a copy of this module's own states is not read yet: a verb or tool handler asks it -// (asking), the module's own start never does (design 47 H2 H-A-708 (2)). The first views of the owners stay the fault -// `away` at the read itself, since a picture not answered yet is no answer for a pass to resolve from. +// Away is the fault `away` while a copy of this module's own states or a first view of an owner is not read yet: a verb or +// tool handler asks it (asking); the module's own start waits for them instead (design 47 H2 H-A-708 (2)). func (r runtimeStore) Away() error { - if r.own == nil { - return nil + if r.own != nil { + if err := r.own.Unread(); err != nil { + return err + } } - return r.own.Unread() + if theViews != nil { + return theViews.Unread() + } + return nil } // asking is a tool whose handler answers `away` at once while what it reads is not read yet (design 47 H2 H-A-708 (2)). diff --git a/modules/mesh-config/cmd/mesh-config/ownerviews.go b/modules/mesh-config/cmd/mesh-config/ownerviews.go index a0d0037d3..a25f3ab42 100644 --- a/modules/mesh-config/cmd/mesh-config/ownerviews.go +++ b/modules/mesh-config/cmd/mesh-config/ownerviews.go @@ -95,16 +95,25 @@ func (o *ownerViews) read(state string) (*views.Follower, bool) { return f, ok } +// Unread is the fault `away` naming the owner verb of the first view not answered yet, nil when every one is: a verb or tool +// handler asks it before it reads (design 47 H2 H-A-708 (2)). +func (o *ownerViews) Unread() error { + for _, f := range followed { + if err := o.by[f.Read].Unread(); err != nil { + return err + } + } + return nil +} + // get is one key of a followed state. func (o *ownerViews) get(state, key string) (*Entry, bool, error) { f, ok := o.read(state) if !ok { return nil, false, nil } - // A first view not answered yet is the fault `away`, naming the view's owner verb (design 47 H2 H-A-708 (2)). - if err := f.Unread(); err != nil { - return nil, true, err - } + // The module's own read waits for the first view, never reads an empty picture (design 47 H2 H-A-708 (2), row S8). + <-f.Ready() v, held := f.Get(key) if !held { return nil, true, nil @@ -118,9 +127,7 @@ func (o *ownerViews) keys(state string) ([]string, bool, error) { if !ok { return nil, false, nil } - if err := f.Unread(); err != nil { - return nil, true, err - } + <-f.Ready() var out []string for k := range f.Values() { out = append(out, k) diff --git a/modules/mesh-config/cmd/mesh-config/ownerviews_test.go b/modules/mesh-config/cmd/mesh-config/ownerviews_test.go index d961539fa..65e48f06d 100644 --- a/modules/mesh-config/cmd/mesh-config/ownerviews_test.go +++ b/modules/mesh-config/cmd/mesh-config/ownerviews_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + stdio "git.novox.be/novox/mesh-sdk/go" "git.novox.be/novox/mesh-sdk/go/busretry" "git.novox.be/novox/mesh-sdk/go/views" ) @@ -36,9 +37,15 @@ func TestAFollowedStateIsReadFromItsOwnersFirstViewAndEvents(t *testing.T) { o := newOwnerViews(ask, func() { changed.Add(1) }, nopFindings{}) // H-A-708 (2): a read before the first view is answered `away`, naming the view's owner verb, at once. var away *busretry.Away - if _, followed, err := o.get(WantsRead, "want.g14.dunst"); !followed || !errors.As(err, &away) || away.Part != "mesh-delivery-assigner.assigner_read_wants" || + if err := o.Unread(); !errors.As(err, &away) || !strings.HasPrefix(away.Part, "mesh-delivery-") || !strings.HasPrefix(away.Words, "not read yet since ") { - t.Fatalf("before the first view: followed %v, %v", followed, err) + t.Fatalf("before the first view, a handler's ask: %v", err) + } + c := &Config{Store: runtimeStore{}} + theViews = o + defer func() { theViews = nil }() + if _, err := asking(c, stdio.Tool{Run: func(map[string]any) (any, error) { return nil, nil }}).Run(nil); !errors.As(err, &away) { + t.Fatalf("a tool's handler before an owner view is ready: %v", err) } if !o.reader.Follows("mesh-delivery-assigner.wants") { t.Error("the wants view is not one of the reader's (A-28)")