The runner reads the `timeout` (whole seconds) of a seat's verb from the seat list's definitions beside `chunked` and hands it to the bus connection's ask (AskWithin, AskAsWithin, AskAsChunkedWithin); a verb that names none, a seat the definitions do not hold and a module's tool wait the runner's own bound, RequestTimeout. Builds: design 47 H §760, H-A-43 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
73 lines
2.8 KiB
Go
73 lines
2.8 KiB
Go
package bus
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
|
|
// An event given up on and delivered again by the controller arrives under `mesh.again.<consumer>.` and
|
|
// the event's own subject without its `mesh.` (novox/hq issue 330): the handler sees the key it saw the
|
|
// first time, for a module's event and a seat's.
|
|
func TestAnEventDeliveredAgainHasItsOwnKey(t *testing.T) {
|
|
for original, again := range map[string]string{
|
|
"mesh.mod.gitea.event.pull.merged": "mesh.again.ace_sonarr.mod.gitea.event.pull.merged",
|
|
"mesh.seat.node-build-agent.event.built": "mesh.again.ace_sonarr.seat.node-build-agent.event.built",
|
|
} {
|
|
if keyOf(again) != keyOf(original) {
|
|
t.Errorf("%s reads as %q, the event as %q", again, keyOf(again), keyOf(original))
|
|
}
|
|
}
|
|
}
|
|
|
|
// Design 47 H §760: a call waits the bound its verb's definition names, else the tool runner's own.
|
|
func TestWaitOfIsTheVerbsBoundElseTheRunnersOwn(t *testing.T) {
|
|
for within, want := range map[time.Duration]time.Duration{0: RequestTimeout, 40 * time.Second: 40 * time.Second, 600 * time.Second: 600 * time.Second} {
|
|
if got := waitOf(within); got != want {
|
|
t.Errorf("waitOf(%s) = %s, want %s", within, got, want)
|
|
}
|
|
}
|
|
}
|