Files
mesh-tools/node-tools/internal/announce/announce_test.go
T
jochen b3ebdd5edd Keep a machine's discovery answer under the bus's message limit
Every tool's schema in one $SRV.INFO reply outgrew max_payload on machines
serving 137-206 tools, and the refused reply was dropped silently, so search
and a machine's view went empty. Module tools now announce without schema;
describe and tools/list ask the module for it. An answer still too large has
its descriptions cut to a line, and a failed reply is logged.
2026-10-04 17:06:20 +02:00

55 lines
2.4 KiB
Go

package announce
import (
"encoding/json"
"fmt"
"strings"
"testing"
)
// What a machine serves fits the bus's largest message (1 MiB) with room to spare at several hundred
// tools: a module's tool is announced without its schema, which made a machine with ~200 tools outgrow it
// and vanish from discovery (2026-10-04). A seat's verb keeps its schema.
func TestAMachinesAnnouncementFitsTheBusAtSeveralHundredTools(t *testing.T) {
schema := json.RawMessage(`{"type":"object","properties":{` + strings.Repeat(`"field_with_a_long_name":{"type":"string","description":"a description of what this argument means, long enough to matter"},`, 12) + `"last":{"type":"string"}}}`)
description := strings.Repeat("A tool that does something useful, described at the length the catalogue's tools are. ", 3)
var endpoints []Endpoint
for i := 0; i < 400; i++ {
for _, subject := range []string{fmt.Sprintf("mesh.mod.m%d.tool.t", i), fmt.Sprintf("mesh.mod.m%d.tool.t.laptop", i)} {
endpoints = append(endpoints, Endpoint{Kind: KindTool, Module: fmt.Sprintf("m%d", i), Tool: "t", Node: "laptop",
Description: description, Schema: schema, Subject: subject})
}
}
endpoints = append(endpoints, Endpoint{Kind: KindSeat, Module: "m0", Tool: "verb", Seat: "a-seat", Scope: "mesh",
Description: "a verb", Schema: schema, Subject: "mesh.seat.a-seat.tool.verb"})
body, err := json.Marshal(Info(Service{Name: "node-tools", ID: "laptop"}, endpoints))
if err != nil {
t.Fatal(err)
}
if len(body) > 1<<20 {
t.Fatalf("400 tools announce %d bytes, beyond the bus's 1 MiB", len(body))
}
t.Logf("400 tools on two subjects each announce %d bytes", len(body))
back := Endpoints(Info(Service{Name: "node-tools", ID: "laptop"}, endpoints))
if len(back[0].Schema) != 0 {
t.Fatalf("a module's tool still carries its schema: %s", back[0].Schema)
}
if seat := back[len(back)-1]; !strings.Contains(string(seat.Schema), "field_with_a_long_name") {
t.Fatalf("a seat's verb lost its schema: %s", seat.Schema)
}
withSchemas := 0
for range endpoints {
withSchemas += len(schema) * 2 // escaped inside a string
}
t.Logf("with every schema it would have been over %d bytes", len(body)+withSchemas)
}
func TestFirstLineShortensADescription(t *testing.T) {
if got := firstLine("One thing. And more after it."); got != "One thing." {
t.Fatalf("%q", got)
}
if got := firstLine(strings.Repeat("x", 300)); len(got) != 160 {
t.Fatalf("%d", len(got))
}
}