package adminapi import ( "net/http/httptest" "strings" "testing" "gitea.mynodes.xyz/ilker/llmgw/internal/control/catalog" ) func TestAClaimedActorIsOneShortName(t *testing.T) { for claimed, want := range map[string]string{ "ilker": "ilker", "": "unknown", "ilker\nlevel=ERROR msg=x": "ilkerlevelERRORmsgx", strings.Repeat("a", 500): strings.Repeat("a", 64), "ops@example.org": "ops@example.org", "\x1b[31m": "31m", } { r := httptest.NewRequest("POST", "/", nil) r.Header.Set("X-Llmgw-Actor", claimed) if got := actorOf(r); got != want { t.Errorf("%q: %q, expected %q", claimed, got, want) } } } func TestAReservationThatPlacementCannotTrustIsSaid(t *testing.T) { cpu := func(mem int) catalog.Model { return catalog.Model{Name: "m", Profiles: []catalog.Profile{{Name: "cpu", Engine: "llamacpp", MinMemoryGB: mem}}} } if w := reservationWarnings(cpu(0), 0); len(w) != 1 || !strings.Contains(w[0], "declares no memory") { t.Errorf("no memory declared: %v", w) } if w := reservationWarnings(cpu(6), 8.2); len(w) != 1 || !strings.Contains(w[0], "uses 8.2 GB and reserves 6") { t.Errorf("under-declared: %v", w) } if w := reservationWarnings(cpu(6), 6.4); len(w) != 0 { t.Errorf("within a tenth is mapped weights, not a wrong figure: %v", w) } gpu := catalog.Model{Name: "g", Profiles: []catalog.Profile{{Name: "tp1", Engine: "vllm", GPUClass: "h100-80g"}}} if w := reservationWarnings(gpu, 3); len(w) != 0 { t.Errorf("a GPU model needs no host memory figure: %v", w) } }