From 292aa54bbb50dd86341fc0c01a9bbd56555bf883 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 16 Nov 2026 14:49:39 +0100 Subject: [PATCH] node-engine: compose-candidate's chunked input is tested through HandActs.Call and past the inline bound, folded into the compose integration test; comments cite A-237c Builds: design 47 G (G-22 lead answers 2) A-237c; A-237b --- cmd/mesh-host/composecandidate_chunks_test.go | 94 ------------------- cmd/mesh-host/engineseat.go | 4 +- cmd/mesh-host/nodeagent_integration_test.go | 74 ++++++++++++++- internal/selfcompose/candidate.go | 2 +- 4 files changed, 76 insertions(+), 98 deletions(-) delete mode 100644 cmd/mesh-host/composecandidate_chunks_test.go diff --git a/cmd/mesh-host/composecandidate_chunks_test.go b/cmd/mesh-host/composecandidate_chunks_test.go deleted file mode 100644 index 9641f7ae..00000000 --- a/cmd/mesh-host/composecandidate_chunks_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package main - -import ( - "encoding/json" - "strings" - "sync" - "testing" - "time" - - nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" - "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" - "git.novox.be/novox/mesh-sdk/go/buscalls" - "github.com/nats-io/nats.go" -) - -// ackingLine is a bus connection that acknowledges every chunk published on it, as a caller does, and keeps the chunks. -type ackingLine struct { - mu sync.Mutex - onAck nats.MsgHandler - chunks map[string][]byte - done chan struct{} - want int -} - -func (l *ackingLine) Subscribe(_ string, cb nats.MsgHandler) (*nats.Subscription, error) { - l.mu.Lock() - l.onAck = cb - l.mu.Unlock() - return &nats.Subscription{}, nil -} - -func (l *ackingLine) Publish(subject string, data []byte) error { - l.mu.Lock() - l.chunks[subject] = data - n, cb := len(l.chunks), l.onAck - l.mu.Unlock() - if n == l.want { - defer close(l.done) - } - ack := strings.Replace(subject, ".chunk.", ".ack.", 1) - go cb(&nats.Msg{Subject: ack}) - return nil -} - -// A-237b: asked with input and a call token, compose-candidate answers the chunks and sends the composition input on the -// connection, whatever its size; asked with no token it answers the input inline. -func TestComposeCandidateSendsItsInputInChunksWhenAskedWithACallToken(t *testing.T) { - big := strings.Repeat("x", buscalls.SeatChunkBytes+1000) // past what one answer carries - answer := func() nodeengine.ComposeCandidateAnswer { - key, _ := nec.RevisionKey("main", 7) - return nodeengine.ComposeCandidateAnswer{Node: "n1", Candidate: key, Verdict: nec.Composed, Modules: []nodeengine.Module{}, - Own: nodeengine.Module{Module: nec.NodeWord, State: nec.ModuleComposed, Digest: "sha256:" + strings.Repeat("a", 64)}, - Input: map[string]any{"data": big}} - } - key, _ := nec.RevisionKey("main", 7) - line := &ackingLine{chunks: map[string][]byte{}, done: make(chan struct{}), want: 2} - const call = "0123456789abcdef0123456789abcdef" - raw, err := answerComposeCandidate(answer(), key, true, call, line) - if err != nil { - t.Fatal(err) - } - got, err := nec.DecodeAnswer(raw.(json.RawMessage)) - if err != nil || got.Chunks != 2 || got.Input != nil { - t.Fatalf("the answer %+v (%v), want 2 chunks and no inline input", got, err) - } - select { - case <-line.done: - case <-time.After(5 * time.Second): - t.Fatalf("the chunks sent: %d, want 2", len(line.chunks)) - } - var file []byte - for n := int64(1); n <= 2; n++ { - var c buscalls.SeatChunk - if err := json.Unmarshal(line.chunks[buscalls.SeatChunks{Seat: nodeengine.Seat, Verb: nodeengine.VerbComposeCandidate, Call: call}.Chunk(n)], &c); err != nil { - t.Fatal(err) - } - file = append(file, c.Data...) - } - var in map[string]string - if err := json.Unmarshal(file, &in); err != nil || in["data"] != big { - t.Errorf("the chunks held %d bytes that read back as %v", len(file), err) - } - // No token: the input stays in the answer, as the checker reads it. - raw, err = answerComposeCandidate(answer(), key, true, "", line) - if err != nil { - t.Fatal(err) - } - if inline, err := nec.DecodeAnswer(raw.(json.RawMessage)); err != nil || inline.Chunks != 0 || inline.Input == nil { - t.Errorf("an ask with no token answered %+v (%v), want the input inline", inline, err) - } - if _, err := answerComposeCandidate(answer(), key, true, call, nil); err == nil { - t.Error("an input was to be chunked with no connection to send it on") - } -} diff --git a/cmd/mesh-host/engineseat.go b/cmd/mesh-host/engineseat.go index 4470abeb..00588ed0 100644 --- a/cmd/mesh-host/engineseat.go +++ b/cmd/mesh-host/engineseat.go @@ -424,9 +424,9 @@ func entryAgainFrom(composer *atomic.Pointer[selfcompose.Composer]) func(ctx con } } -// answerComposeCandidate encodes the answer of compose-candidate. The verb is marked chunks (A-237b): asked with input and a +// answerComposeCandidate encodes the answer of compose-candidate. The verb is marked chunks (A-237b, A-237c): asked with input and a // call token, the composition input goes in chunks over the link's connection, whatever its size, and the answer names them; -// asked with no token (the checker's, until G removes it, G-6 §321) it stays inline in the answer. +// asked with no token (the checker's, until G removes it, G-6 §321, A-237c) it stays inline in the answer. func answerComposeCandidate(a nodeengine.ComposeCandidateAnswer, candidate string, input bool, call string, line buscalls.ChunkLine) (any, error) { var chunked []byte if input && call != "" && a.Input != nil { diff --git a/cmd/mesh-host/nodeagent_integration_test.go b/cmd/mesh-host/nodeagent_integration_test.go index 0b0ef574..d102635d 100644 --- a/cmd/mesh-host/nodeagent_integration_test.go +++ b/cmd/mesh-host/nodeagent_integration_test.go @@ -29,6 +29,7 @@ import ( "time" nec "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient" + "git.novox.be/novox/mesh-sdk/go/buscalls" "git.novox.be/novox/mesh-sdk/go/buscompose" "git.novox.be/novox/mesh-sdk/go/declaration" "git.novox.be/novox/mesh-sdk/go/seatlist" @@ -702,7 +703,10 @@ func h8candidate(t *testing.T, b *itBed, fp, running string) { t.Fatal(err) } path := filepath.Join(b.dir, "web.conf") - man := `{"module":"web","version":"2","config":{"greeting":{"type":"string","description":"what the file says","default":"hello"}},` + + // A description past what one answer carries (900 KiB, and under the bus's 1 MiB for one value), so the composition input this + // node sends is over the inline bound (A-237b, A-237c). + pad := strings.Repeat("x", 930_000) + man := `{"module":"web","version":"2","config":{"greeting":{"type":"string","description":"what the file says ` + pad + `","default":"hello"}},` + `"resources":[{"id":"conf","type":"file","path":"` + path + `","mode":"0640","content":"greeting=${config:greeting}\n"},` + `{"id":"tools","type":"package","package":"web-tools"}]}` digest := meshcatalogclient.ManifestDigest([]byte(man)) @@ -728,6 +732,42 @@ func h8candidate(t *testing.T, b *itBed, fp, running string) { t.Fatal(err) } before, _ := b.composed.Status() + // A-237c: asked with input and no call token (the checker's, until G removes it, G-6 §321) an input past what one answer carries + // is refused; asked with a token it is sent in chunks through the engine's call, whatever its size (A-237b). + if over, err := composeCandidateFrom(itNode, &shadowNow)(key, true, "", nil); err != nil { + t.Fatal(err) + } else if a, err := nec.DecodeAnswer(over.(json.RawMessage)); err != nil || a.Verdict != nec.Refused || !strings.Contains(a.Refused, "an answer on the bus carries") || a.Input != nil { + t.Errorf("an input over the inline bound asked with no token answered %+v (%v)", a, err) + } + line := &ackingLine{chunks: map[string][]byte{}, done: make(chan struct{})} + const call = "0123456789abcdef0123456789abcdef" + acts := &link.HandActs{Node: itNode, ComposeCandidate: composeCandidateFrom(itNode, &shadowNow)} + chunked, err := acts.Call(link.EngineCall{Verb: link.ActComposeCandidate, Line: line, + Args: map[string]any{"candidate": key, "input": true, "call": call}}) + if err != nil { + t.Fatal(err) + } + ca, err := nec.DecodeAnswer(chunked.(json.RawMessage)) + if err != nil || ca.Verdict != nec.Composed || ca.Chunks < 2 || ca.Input != nil { + t.Fatalf("the input asked with a token answered %+v (%v), want the chunks and no inline input", ca, err) + } + line.want = int(ca.Chunks) + select { + case <-line.done: + case <-time.After(10 * time.Second): + t.Fatalf("%d of %d chunks were sent", line.sent(), ca.Chunks) + } + var file []byte + for n := int64(1); n <= ca.Chunks; n++ { + var c buscalls.SeatChunk + if err := json.Unmarshal(line.chunks[buscalls.SeatChunks{Seat: nodeengine.Seat, Verb: nodeengine.VerbComposeCandidate, Call: call}.Chunk(n)], &c); err != nil { + t.Fatal(err) + } + file = append(file, c.Data...) + } + if len(file) <= 900<<10 || !json.Valid(file) { + t.Errorf("the chunks held %d bytes, want a JSON input over 900 KiB", len(file)) + } got, err := composeCandidateFrom(itNode, &shadowNow)(key, false, "", nil) if err != nil { t.Fatal(err) @@ -1237,3 +1277,35 @@ func TestNatsTheFirstReadOfTheSeatListEndsTheNodesWait(t *testing.T) { t.Error("the list was read by the reader of a run begun since, not by the one that met no responders") } } + +// ackingLine is a bus connection that acknowledges every chunk published on it, as a caller does, and keeps the chunks. +type ackingLine struct { + mu sync.Mutex + onAck nats.MsgHandler + chunks map[string][]byte + done chan struct{} + want int + closed bool +} + +func (l *ackingLine) Subscribe(_ string, cb nats.MsgHandler) (*nats.Subscription, error) { + l.mu.Lock() + l.onAck = cb + l.mu.Unlock() + return &nats.Subscription{}, nil +} + +func (l *ackingLine) sent() int { l.mu.Lock(); defer l.mu.Unlock(); return len(l.chunks) } + +func (l *ackingLine) Publish(subject string, data []byte) error { + l.mu.Lock() + l.chunks[subject] = data + cb := l.onAck + if l.want > 0 && len(l.chunks) >= l.want && !l.closed { + l.closed = true + close(l.done) + } + l.mu.Unlock() + go cb(&nats.Msg{Subject: strings.Replace(subject, ".chunk.", ".ack.", 1)}) + return nil +} diff --git a/internal/selfcompose/candidate.go b/internal/selfcompose/candidate.go index bbc6f6ab..42edf498 100644 --- a/internal/selfcompose/candidate.go +++ b/internal/selfcompose/candidate.go @@ -239,7 +239,7 @@ func (s *Shadow) composeCandidate(ctx context.Context, c *Composer, ask nodeengi } }) // An ask with a call token takes the input in chunks, whatever its size (A-237b); one with none is the checker's, answered - // inline until G removes the checker (G-6 §321), so past what the bus carries in one answer it is refused. + // inline until G removes the checker (G-6 §321, A-237c), so past what the bus carries in one answer it is refused. if sentSize > maxSentInput && ask.Call == "" { // Past what the bus carries in one answer, the checker would hear nothing: refused, saying so. size := sentSize