From 28d4b9eb0d93e2545cbdbbfeb3ac91ab241525f0 Mon Sep 17 00:00:00 2001 From: mesh-tools Date: Tue, 20 Oct 2026 07:03:36 +0000 Subject: [PATCH] Return the lines the composition found on the way (a node not counted as on the network) in Rendered.Said and Declared.Said (review round 1, finding 6). The test failed first; the suite is 1258 tests in 1.05 s --- go/compose/network.go | 11 +++++++++++ go/compose/node.go | 1 + go/compose/node_test.go | 34 ++++++++++++++++++++++++++++++++++ go/compose/render.go | 2 ++ 4 files changed, 48 insertions(+) diff --git a/go/compose/network.go b/go/compose/network.go index de789c6..3c54aed 100644 --- a/go/compose/network.go +++ b/go/compose/network.go @@ -3,6 +3,7 @@ package compose import ( "errors" "fmt" + "slices" "sort" "strconv" "strings" @@ -50,6 +51,16 @@ func (c *composer) suffix() string { // internalName is a node's name inside the mesh. func (c *composer) internalName(node string) string { return node + "." + c.suffix() } +// saidBeside is the lines already said and then every line the composer kept, once each, in the order they were found. +func (c *composer) saidBeside(lines []string) []string { + for _, l := range c.said { + if !slices.Contains(lines, l) { + lines = append(lines, l) + } + } + return lines +} + // overlayRange is the range the mesh allocates node addresses from: the adopted tunnel's first (novox/hq ADR 0105), // then the range genesis was told, then the default. func (c *composer) overlayRange() string { diff --git a/go/compose/node.go b/go/compose/node.go index 982e5fc..858f77d 100644 --- a/go/compose/node.go +++ b/go/compose/node.go @@ -227,6 +227,7 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) { for _, l := range left { out.Said = append(out.Said, l.String()) } + out.Said = c.saidBeside(out.Said) return out, nil } diff --git a/go/compose/node_test.go b/go/compose/node_test.go index 5a79bf0..a863392 100644 --- a/go/compose/node_test.go +++ b/go/compose/node_test.go @@ -382,3 +382,37 @@ func TestTheRestOfTheMeshReadsEachOtherNodesKeptBuild(t *testing.T) { t.Errorf("a node keeping a build that offers nothing still offers: %v %v", providers(w, "s3-bucket"), err) } } + +// Round 1, finding 6: the nodes the composition did not count as on the network are returned, said, not lost. +func TestANodeNotCountedAsOnTheNetworkIsSaidInTheResult(t *testing.T) { + in := aMesh(t) + in.Catalogue["rival-one"] = catalogue.Manifest{Module: "rival-one", Version: "1", Claims: []catalogue.Claim{{Name: "the-seat", Scope: catalogue.ScopeNode}}} + in.Catalogue["rival-two"] = catalogue.Manifest{Module: "rival-two", Version: "1", Claims: []catalogue.Claim{{Name: "the-seat", Scope: catalogue.ScopeNode}}} + laptop := nodeOf(t, &in, "laptop") + laptop.Assigned = append(laptop.Assigned, "rival-one", "rival-two") + said := func(lines []string) bool { + for _, l := range lines { + if strings.HasPrefix(l, "laptop is not counted as on the network") { + return true + } + } + return false + } + got, err := Render(in, "anchor", Foreseeing) + if err != nil || !said(got.Said) { + t.Errorf("rendered: %v %v", got.Said, err) + } + d, _, err := Compose(in, "anchor") + if err != nil || !said(d.Said) { + t.Errorf("declared: %v %v", d.Said, err) + } + n := 0 + for _, l := range d.Said { + if strings.HasPrefix(l, "laptop is not counted") { + n++ + } + } + if n != 1 { + t.Errorf("said %d times: %v", n, d.Said) + } +} diff --git a/go/compose/render.go b/go/compose/render.go index 5f05b84..a50a65e 100644 --- a/go/compose/render.go +++ b/go/compose/render.go @@ -122,5 +122,7 @@ func (c *composer) render(nodeName string, mode Mode) (Rendered, error) { } r.BusMembership = c.in.BusMemberships[nodeName] out.Rendering = r + // And what the composition found on the way, which the controller writes to its log: a machine not counted as on the network. + out.Said = c.saidBeside(out.Said) return out, nil }