v2.1 task 02: router mode — status loaded only, per-model /props, guard and hosts view use it; given tests
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package admin_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.wntrmute.dev/kyle/crossbar/internal/admin"
|
||||
"git.wntrmute.dev/kyle/crossbar/internal/health"
|
||||
)
|
||||
|
||||
// The hosts view shows the per-model context the poller learned, and an empty object (never
|
||||
// null) for a host with nothing learned.
|
||||
func TestHostsShowsPerModelContext(t *testing.T) {
|
||||
r := newRig(t)
|
||||
r.hosts.st["alpha"] = health.Status{
|
||||
Healthy: true,
|
||||
Loaded: []string{"m"},
|
||||
NCtx: 0, // a router: the host-level figure stays unknown
|
||||
Models: map[string]health.ModelCtx{"m": {NCtx: 65536, Slots: 2}},
|
||||
}
|
||||
rec := r.do(t, "GET", "/_crossbar/hosts", "")
|
||||
if rec.Code != 200 {
|
||||
t.Fatalf("%d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var out map[string]admin.HostView
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := out["alpha"].Models["m"]; got != (health.ModelCtx{NCtx: 65536, Slots: 2}) {
|
||||
t.Errorf("alpha.models[m] = %+v, want {65536 2}", got)
|
||||
}
|
||||
if out["alpha"].NCtx != 0 {
|
||||
t.Errorf("alpha.n_ctx = %d, want 0 (unknown at host level on a router)", out["alpha"].NCtx)
|
||||
}
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if beta := string(raw["beta"]); !strings.Contains(beta, `"models":{}`) {
|
||||
t.Errorf("beta = %s, want \"models\":{} (never null)", beta)
|
||||
}
|
||||
if alpha := string(raw["alpha"]); !strings.Contains(alpha, `"models":{"m":{"n_ctx":65536,"slots":2}}`) {
|
||||
t.Errorf("alpha = %s, want models keyed by id with n_ctx and slots", alpha)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user