The replica count, its nodes and the mode selector sit side by side instead of stacking in a fixed-width cell, and node names drop the prefix every node shares, with the full name on hover. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
184 lines
6.5 KiB
Go
184 lines
6.5 KiB
Go
package web
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/control/catalog"
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/mirror"
|
|
)
|
|
|
|
// roomyFleet runs one replica of "coder" on n2 and has room for `more`.
|
|
type roomyFleet struct {
|
|
fakeFleet
|
|
more int
|
|
blocked []string
|
|
asked int
|
|
}
|
|
|
|
func (f *roomyFleet) Nodes() []adminapi.NodeView {
|
|
return []adminapi.NodeView{{ID: "n1", MemoryGB: 16}, {ID: "n2", MemoryGB: 32}}
|
|
}
|
|
func (f *roomyFleet) Models() []adminapi.ModelView {
|
|
return []adminapi.ModelView{{Name: "coder", Min: 1, Max: 1, Ready: 1, Total: 1, Desired: 1}}
|
|
}
|
|
func (f *roomyFleet) Replicas(string) []adminapi.ReplicaView {
|
|
return []adminapi.ReplicaView{{ID: "coder-abc", Model: "coder", State: "ready", AgeSec: 3700,
|
|
EngineKey: "secret-engine-key",
|
|
Shards: []adminapi.ShardView{{Node: "n2", CPUCores: 3.5, MemoryBytes: 6 << 30}}}}
|
|
}
|
|
func (f *roomyFleet) Headroom(model string, limit int) (adminapi.HeadroomView, bool) {
|
|
f.asked = limit
|
|
more := min(f.more, limit)
|
|
h := adminapi.HeadroomView{Model: model, Current: 1, More: more}
|
|
for range more {
|
|
h.Nodes = append(h.Nodes, []string{"n1"})
|
|
}
|
|
if more < limit {
|
|
h.Blocked = f.blocked
|
|
} else {
|
|
h.Limited = true
|
|
}
|
|
return h, true
|
|
}
|
|
|
|
func detailPage(t *testing.T, fleet *roomyFleet, cat *fakeCatalog) func(string) string {
|
|
t.Helper()
|
|
m := &fakeMirror{models: []mirror.Status{
|
|
{Model: "coder", Version: "v1", File: "c.gguf", State: mirror.Present, BytesDone: 5 << 30},
|
|
}}
|
|
mux := mirrorPageDeps(t, MirrorDeps{Mirror: m, Catalog: cat, Fleet: fleet}, true)
|
|
return func(path string) string { return mirrorGet(t, mux, path).Body.String() }
|
|
}
|
|
|
|
func coderCatalog() *fakeCatalog {
|
|
return &fakeCatalog{sources: map[string][]catalog.Model{"http://mirror:8081/coder/v1/c.gguf": {
|
|
{Name: "coder", Scaling: catalog.Scaling{Min: 1, Max: 1}}}}}
|
|
}
|
|
|
|
func TestAHeldModelOpensToWhereItRunsAndHowMuchRoomIsLeft(t *testing.T) {
|
|
fleet := &roomyFleet{more: 2, blocked: []string{"n2: 2 GB free of 32, profile needs 6"}}
|
|
get := detailPage(t, fleet, coderCatalog())
|
|
|
|
closed := get("/admin/mirror")
|
|
if strings.Contains(closed, "held-card") {
|
|
t.Error("a card is open before anything was clicked")
|
|
}
|
|
if !strings.Contains(closed, `href="/admin/mirror?tab=held&open=coder%3av1"`) {
|
|
t.Error("the model's name does not open its card")
|
|
}
|
|
|
|
body := get("/admin/mirror?tab=held&open=coder:v1")
|
|
for _, want := range []string{
|
|
"held-card", `<a href="/admin/nodes/n2">n2</a>`, "32 GB", "coder-abc", "1h01m", "3.5 cores", "6.0 GiB",
|
|
"Room for 2 more now, on n1, n1.", "n2: 2 GB free of 32, profile needs 6",
|
|
`name="min" value="1" min="0" max="3"`, `action="/admin/mirror/replicas"`,
|
|
`name="open" value="coder:v1"`,
|
|
} {
|
|
if !strings.Contains(body, want) {
|
|
t.Errorf("the card is missing %q", want)
|
|
}
|
|
}
|
|
if strings.Contains(body, "secret-engine-key") {
|
|
t.Error("the engine's key reached the page")
|
|
}
|
|
if strings.Contains(body, `http-equiv="refresh"`) {
|
|
t.Error("a page with an open form reloads under the operator")
|
|
}
|
|
}
|
|
|
|
func TestAReplicaCountTheClusterHasNoRoomForIsRefused(t *testing.T) {
|
|
fleet := &roomyFleet{more: 1, blocked: []string{"n1: 1 GB free of 16, profile needs 6"}}
|
|
cat := coderCatalog()
|
|
mux := mirrorPageDeps(t, MirrorDeps{Mirror: &fakeMirror{models: []mirror.Status{
|
|
{Model: "coder", Version: "v1", File: "c.gguf", State: mirror.Present, BytesDone: 1},
|
|
}}, Catalog: cat, Fleet: fleet}, true)
|
|
post := func(lo, hi string) string {
|
|
return mirrorPost(t, mux, "/admin/mirror/replicas", url.Values{"csrf": {"tok"},
|
|
"model": {"coder"}, "min": {lo}, "max": {hi}, "open": {"coder:v1"}}).Body.String()
|
|
}
|
|
|
|
body := post("3", "3")
|
|
if len(cat.scaled) != 0 {
|
|
t.Fatalf("three always-on replicas were set with room for two: %+v", cat.lastScale)
|
|
}
|
|
if !strings.Contains(body, "can always run at most 2 now") || !strings.Contains(body, "1 GB free of 16") {
|
|
t.Errorf("the refusal should say how many fit and why: %s", body)
|
|
}
|
|
if !strings.Contains(body, "held-card") {
|
|
t.Error("the card closed on the refusal")
|
|
}
|
|
|
|
body = post("2", "4")
|
|
if len(cat.scaled) != 1 || cat.lastScale.Min != 2 || cat.lastScale.Max != 4 {
|
|
t.Fatalf("what fits was not set: %+v", cat.lastScale)
|
|
}
|
|
if !strings.Contains(body, "coder runs 2, and up to 4 under load; there is room for 2 now") {
|
|
t.Errorf("a ceiling above the room should be taken and said: %s", body)
|
|
}
|
|
|
|
post("0", "2")
|
|
if cat.lastScale.Min != 0 || cat.lastScale.Max != 2 || cat.lastScale.IdleTimeout == 0 {
|
|
t.Errorf("on demand was set as %+v", cat.lastScale)
|
|
}
|
|
for _, bad := range [][2]string{{"3", "2"}, {"-1", "1"}, {"x", "1"}, {"1", "100"}} {
|
|
n := len(cat.scaled)
|
|
post(bad[0], bad[1])
|
|
if len(cat.scaled) != n {
|
|
t.Errorf("min %s max %s was accepted", bad[0], bad[1])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAModelSetInConfigurationIsShownButNotChanged(t *testing.T) {
|
|
cat := coderCatalog()
|
|
cat.declared = "coder"
|
|
body := detailPage(t, &roomyFleet{more: 20}, cat)("/admin/mirror?open=coder:v1")
|
|
if strings.Contains(body, `action="/admin/mirror/replicas"`) || !strings.Contains(body, "change its replicas there") {
|
|
t.Error("a declared model offered a change that would revert")
|
|
}
|
|
if !strings.Contains(body, "Room for at least 16 more") {
|
|
t.Error("room that reached the limit asked should read as at least")
|
|
}
|
|
}
|
|
|
|
func TestAHeldRowSaysHowItsModelRunsWithoutOpening(t *testing.T) {
|
|
body := detailPage(t, &roomyFleet{more: 1}, coderCatalog())("/admin/mirror")
|
|
if strings.Contains(body, "held-card") {
|
|
t.Fatal("the card opened by itself")
|
|
}
|
|
if !strings.Contains(body, `title="replicas ready / wanted">1/1 · <span class="node" title="n2">n2</span></span>`) {
|
|
t.Errorf("the row does not say where its replicas run: %s", body)
|
|
}
|
|
}
|
|
|
|
func TestRunningOnNamesEachNodeOnceAndCountsWhatIsStarting(t *testing.T) {
|
|
nodes, starting := runningOn([]adminapi.ReplicaView{
|
|
{State: "ready", Shards: []adminapi.ShardView{{Node: "n2"}}},
|
|
{State: "starting", Shards: []adminapi.ShardView{{Node: "n1"}}},
|
|
{State: "ready", Shards: []adminapi.ShardView{{Node: "n2"}}},
|
|
})
|
|
if strings.Join(nodes, ",") != "n1,n2" || starting != 1 {
|
|
t.Errorf("nodes %v, starting %d", nodes, starting)
|
|
}
|
|
}
|
|
|
|
func TestNodeNamesLoseOnlyWhatEveryNodeShares(t *testing.T) {
|
|
for _, c := range []struct {
|
|
ids []string
|
|
want string
|
|
}{
|
|
{[]string{"llmgw-node01", "llmgw-node02", "llmgw-node06"}, "llmgw-"},
|
|
{[]string{"gpu-a.dc1", "gpu-b.dc1"}, "gpu-"},
|
|
{[]string{"n1", "n2"}, ""},
|
|
{[]string{"llmgw-node01"}, ""},
|
|
{[]string{"alpha", "beta"}, ""},
|
|
} {
|
|
if got := sharedPrefix(c.ids); got != c.want {
|
|
t.Errorf("%v: %q, expected %q", c.ids, got, c.want)
|
|
}
|
|
}
|
|
}
|