From 7f3aeedfc04bd0a6dc11cadab9b66d2aea5f7360 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 13 Nov 2026 20:45:47 +0100 Subject: [PATCH] S6 grants-wait-asks-ready: grants' wait for its catalog half asks the catalog client's Ready, so a mesh naming no branch is none-yet Builds: design 47 G A-369 (G-22-lead-answers-2.md) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h --- .../mesh-grants/internal/grants/catalog.go | 4 ++ .../internal/grants/catalogwait_test.go | 51 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 modules/mesh-grants/internal/grants/catalogwait_test.go diff --git a/modules/mesh-grants/internal/grants/catalog.go b/modules/mesh-grants/internal/grants/catalog.go index 4a067cac..270c7a3b 100644 --- a/modules/mesh-grants/internal/grants/catalog.go +++ b/modules/mesh-grants/internal/grants/catalog.go @@ -74,6 +74,10 @@ func (c *CatalogOf) Resolve(fingerprint string) (meshcatalog.CatalogEntry, meshc func (c *CatalogOf) Waiting() []string { followed := c.Branches.Followed() if len(followed) == 0 { + // A mesh whose registrations and gate's source are answered and name no branch is none-yet, as for every part (A-369). + if c.Branches.Ready() == nil { + return nil + } return []string{"no branch is followed yet (the registrations and the gate's source are not answered)"} } var out []string diff --git a/modules/mesh-grants/internal/grants/catalogwait_test.go b/modules/mesh-grants/internal/grants/catalogwait_test.go new file mode 100644 index 00000000..e95cdf6b --- /dev/null +++ b/modules/mesh-grants/internal/grants/catalogwait_test.go @@ -0,0 +1,51 @@ +package grants + +import ( + "context" + "encoding/json" + "testing" + "time" + + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" + seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" + "git.novox.be/novox/mesh-sdk/go/views" +) + +type wiring struct{ followers []*views.Follower } + +func (w *wiring) Adopt(f *views.Follower, _, _ string, _ func(context.Context, []byte) error) error { + w.followers = append(w.followers, f) + return nil +} +func (w *wiring) Drop(string, string) error { return nil } + +// Design 47 G A-369: the grants part's wait for its catalog half asks the catalog client's Ready, so a mesh whose registrations +// and gate's source are answered and name no branch is none-yet for grants, and waits while either is not answered. +func TestAMeshThatNamesNoBranchIsNoWaitForGrants(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + call := func(key string, _ any) (json.RawMessage, error) { + if key == meshcatalogclient.RegistrationsVerb { + return json.Marshal(seat.RegistrationsAnswer{Registrations: []seat.Registration{}}) + } + return json.Marshal(map[string][]string{"branches": {}}) + } + for _, answered := range []bool{false, true} { + w := &wiring{} + b, err := meshcatalogclient.NewBranches(w, call) + if err != nil { + t.Fatal(err) + } + if answered { + for _, f := range w.followers { + if err := f.Start(ctx); err != nil { + t.Fatal(err) + } + } + } + got := (&CatalogOf{Branches: b, Context: ctx}).Waiting() + if (len(got) == 0) != answered { + t.Errorf("answered %v: waiting %v", answered, got) + } + } +}