node-tools: a runner rereads the list only for a verb of a seat it defines, one read shared; asks of undefined seats and tools unchanged (A-490m)

Builds: design 47 G A-490m

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-19 23:07:23 +01:00
parent 2f9690fe80
commit d1dc482b05
3 changed files with 111 additions and 36 deletions
+43 -21
View File
@@ -3,16 +3,17 @@ package runtime
import (
"encoding/json"
"errors"
"runtime"
"strings"
"testing"
"time"
"git.novox.be/novox/mesh-sdk/go/approval"
"git.novox.be/novox/mesh-sdk/go/seatdef"
"github.com/novox/mesh-tools/node-tools/internal/bus"
"github.com/nats-io/nats.go"
"github.com/novox/mesh-tools/node-tools/internal/bus"
mt "github.com/novox/mesh-tools/node-tools/internal/meshtest"
)
@@ -151,35 +152,56 @@ func TestTheSubjectThatNamesNoCallerStillWorksAndNamesNone(t *testing.T) {
t.Error("a runner that holds no seat definitions asks no chunks")
}
})
// A seat verb a bundle asks that the definitions held do not name is read again once, never taken for one that sends no chunks:
// the holder refuses an ask that carries no call, and the bundle saw only that refusal (the compositions of 2026-11-19).
t.Run("AVerbTheListDoesNotNameIsReadAgainAndNeverAskedWithoutItsCall", func(t *testing.T) {
// Design 47 G A-490m: a verb of a seat the list defines whose definition does not name it is read again once and never asked
// without its call; a seat the list does not define, a module's tool and a bundle asking through moduleBus.Ask behave as before.
t.Run("AVerbTheDefinitionDoesNotNameIsReadAgainAndNeverAskedWithoutItsCall", func(t *testing.T) {
stale := map[string]seatdef.Definition{"mesh-wants": {Verbs: []seatdef.Verb{{Name: "revision"}}}}
fresh := map[string]seatdef.Definition{"mesh-wants": {Verbs: []seatdef.Verb{{Name: "revision"}, {Name: "input", Chunks: true}}}}
for _, row := range []struct {
name string
again func(held *map[string]seatdef.Definition) error
want bool
wantErr string
wantRead int
name string
key string
again func(held *map[string]seatdef.Definition) error
wantWay string // "plain", "chunked" or "" for a refusal
wantErr string
wantReads int
}{
{"a read that names it", func(h *map[string]seatdef.Definition) error { *h = fresh; return nil }, true, "", 1},
{"a read that fails", func(h *map[string]seatdef.Definition) error { return errors.New("the seat does not answer") }, false, "does not answer", 1},
{"a read that still does not name it", func(h *map[string]seatdef.Definition) error { return nil }, false, "does not name the verb seat:mesh-wants.input", 1},
{"a defined seat's verb the read names", "seat:mesh-wants.input", func(h *map[string]seatdef.Definition) error { *h = fresh; return nil }, "chunked", "", 1},
{"a read that fails", "seat:mesh-wants.input", func(h *map[string]seatdef.Definition) error { return errors.New("the seat does not answer") }, "", "does not answer", 1},
{"a read that still does not name it", "seat:mesh-wants.input@g14", func(h *map[string]seatdef.Definition) error { return nil }, "", "names no verb input", 1},
{"a seat the list does not define", "seat:issue-tracker.list", func(h *map[string]seatdef.Definition) error { return nil }, "plain", "", 0},
{"a module's tool", "mesh-delivery-indexer.indexer", func(h *map[string]seatdef.Definition) error { return nil }, "plain", "", 0},
{"a verb the list names without chunks", "seat:mesh-wants.revision", func(h *map[string]seatdef.Definition) error { return nil }, "plain", "", 0},
} {
t.Run(row.name, func(t *testing.T) {
held, reads := stale, 0
c := &consumers{definitions: func() map[string]seatdef.Definition { return held }, reread: func() error { reads++; return row.again(&held) }}
got, err := c.chunkedAsked("seat:mesh-wants.input")
if got != row.want || reads != row.wantRead || (row.wantErr == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), row.wantErr)) {
t.Errorf("chunkedAsked = %v, %v after %d reads, want %v, %q after %d", got, err, reads, row.want, row.wantErr, row.wantRead)
held, reads, way := stale, 0, ""
c := &consumers{definitions: func() map[string]seatdef.Definition { return held }, reread: func() error { reads++; return row.again(&held) },
askPlain: func(_, _ string, _ any) (bus.Answered, error) { way = "plain"; return bus.Answered{}, nil },
askChunked: func(_, _ string, _ any) (bus.Answered, error) { way = "chunked"; return bus.Answered{}, nil }}
_, err := (&moduleBus{all: c, module: "m"}).Ask(json.RawMessage(`{"key":"` + row.key + `","body":{}}`))
if way != row.wantWay || reads != row.wantReads || (row.wantErr == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), row.wantErr)) {
t.Errorf("Ask %s: asked %q, %v after %d reads, want %q, %q after %d", row.key, way, err, reads, row.wantWay, row.wantErr, row.wantReads)
}
})
}
held := fresh
c := &consumers{definitions: func() map[string]seatdef.Definition { return held }, reread: func() error { t.Error("a verb the list names is not read again"); return nil }}
if got, err := c.chunkedAsked("seat:mesh-wants.input@g14"); !got || err != nil {
t.Errorf("a named chunked verb: %v, %v", got, err)
// the asks that wait on a read share it
release, reads := make(chan struct{}), 0
held := stale
c := &consumers{definitions: func() map[string]seatdef.Definition { return held }, reread: func() error { reads++; <-release; held = fresh; return nil }}
done := make(chan bool, 3)
for i := 0; i < 3; i++ {
go func() { got, err := c.chunkedAsked("seat:mesh-wants.input"); done <- got && err == nil }()
}
for c.rereadWaiting() < 2 {
runtime.Gosched()
}
close(release)
for i := 0; i < 3; i++ {
if !<-done {
t.Error("an ask waiting on the shared read was not answered chunked")
}
}
if reads != 1 {
t.Errorf("%d reads of the seat list for three waiting asks, want 1", reads)
}
if got, err := (&consumers{}).chunkedAsked("seat:mesh-wants.input"); got || err != nil {
t.Errorf("a runner that holds no definitions asks no chunks: %v, %v", got, err)