The runtime knows no language, so nothing ties it to Node.js. This ports its serve mode — the pinned bus connection and patient connect, following memberships, launching every served bundle over MCP on stdio with its own environment, a child's emit published as its module, each tool, the tools verb and seat verbs served where the mesh issued them, and the console on loopback — to one static binary. Same subjects, request and reply bodies, event headers and MCP answers. The TypeScript stays: it is still the runtime inside the per-module containers until WP4c. Tests run against a real bus and share the TypeScript fixtures.
49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
package bus
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestSubjectsAreTheOnesTheTypeScriptRuntimeUses(t *testing.T) {
|
|
for key, want := range map[string]string{
|
|
"status": "mesh.mod.self.tool.status",
|
|
"alpha.one": "mesh.mod.alpha.tool.one",
|
|
"alpha.one@anchor": "mesh.mod.alpha.tool.one.anchor",
|
|
"seat:node-shelf.list": "mesh.seat.node-shelf.tool.list",
|
|
"seat:node-shelf.list@anchor": "mesh.seat.node-shelf.tool.list.anchor",
|
|
} {
|
|
if got, err := ToolSubject(key, "self"); err != nil || got != want {
|
|
t.Errorf("%s: %s %v, want %s", key, got, err, want)
|
|
}
|
|
}
|
|
if _, err := ToolSubject("seat:nothing", "self"); err == nil {
|
|
t.Error("a seat with no verb was accepted")
|
|
}
|
|
if SeatToolSubject("s", "v", "node", "n") != "mesh.seat.s.tool.v.n" || SeatToolSubject("s", "v", "mesh", "n") != "mesh.seat.s.tool.v" {
|
|
t.Error("seat subjects")
|
|
}
|
|
}
|
|
|
|
func TestAFingerprintIsReadHoweverItIsWritten(t *testing.T) {
|
|
for _, f := range []string{"sha256:AB:CD:ef", "abcdef", "ABCDEF", "SHA256:abcdef"} {
|
|
if got := normalizeFingerprint(f); got != "abcdef" {
|
|
t.Errorf("%s → %s", f, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestWhatWaitingCannotFixIsFinal(t *testing.T) {
|
|
for err, want := range map[error]string{
|
|
fmt.Errorf("x509: %w: it presented aa", ErrPin): "the bus's certificate does not match the pin",
|
|
errors.New("nats: Authorization Violation"): "the bus refused this account",
|
|
errors.New("nats: invalid url"): "the bus address is not a usable URL",
|
|
errors.New("dial tcp 10.0.0.1:4222: connect: connection refused"): "",
|
|
} {
|
|
if got := Fatal(err); got != want {
|
|
t.Errorf("%v → %q, want %q", err, got, want)
|
|
}
|
|
}
|
|
}
|