Files
mesh-host/internal/link/asktool_nats_test.go
T
jochen 3abb07f1e2
mesh/delivery superseded: a newer head of the same pull request
mesh/merge-gate pass: builds mesh-host → ace, g14, novox, shanks; no bus step; every machine composes with the change as it did without (4 of 4 compose)
mesh/repo-check pass: its merge-check.sh passed
State a tool check that waits for the operator as waiting (issue 386, ADR 0283)
A module whose only fault was a secret the operator had not given yet was
stated unhealthy, failed its first-node gate and was put back. The engine
now reads the tool's answer through mesh-sdk go/health and states such a
resource waiting, with what it waits for, on one look; a malformed wait
stays unhealthy.
2026-10-10 21:11:02 +02:00

41 lines
1.2 KiB
Go

package link
import (
"context"
"strings"
"testing"
"time"
"github.com/nats-io/nats.go"
)
// A declared tool check asked over a real bus, through the queue, on the link the node-engine holds:
// the tool's answer is read, and a tool nothing serves is said as such (novox/hq ADR 0240, to-be 48 §3).
func TestNatsAToolCheckIsAskedOnTheLink(t *testing.T) {
conn, js := aBus(t)
const node = "toolcheck"
served, err := conn.Subscribe(ToolSubject("sensors", "sensors_health", node), func(m *nats.Msg) {
_ = m.Respond([]byte(`{"result":{"healthy":true}}`))
})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = served.Unsubscribe() })
if err := conn.Flush(); err != nil {
t.Fatal(err)
}
q := &Queue{Membership: Membership{Node: node}}
q.attach(t.Context(), &natsLink{conn: conn, js: js, node: node})
ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second)
defer cancel()
a, err := q.AskTool(ctx, "sensors", "sensors_health")
if err != nil || !a.Healthy {
t.Fatalf("a served healthy tool read as %+v (%v)", a, err)
}
_, err = q.AskTool(ctx, "sensors", "nothing_serves_this")
if err == nil || !strings.Contains(err.Error(), "nothing on this machine answers") {
t.Fatalf("a tool nothing serves read as %v", err)
}
}