package cli import ( "strings" "testing" tea "github.com/charmbracelet/bubbletea" "gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi" ) func presetsHere() *adminapi.PresetsView { return &adminapi.PresetsView{Auto: true, Presets: []adminapi.PresetView{ {Name: "flux-schnell", Makes: "pictures", Card: "cc 7.0+, 24 GB+", Fits: true, FitsClasses: []string{"v100-32g"}, Blocked: "the cluster installs no ComfyUI (engines.comfyui); adding it by hand sets that"}, {Name: "triposr", Makes: "meshes", Card: "cc 7.0+, 8 GB+", Fits: true, InCatalog: true, AddedBy: "auto"}, }} } func TestThePresetsAreOnTheModelsScreen(t *testing.T) { m, _ := consoleWith(t, cModels) m.data.presets = presetsHere() v := m.View() for _, want := range []string{"Pictures and 3D models that come with llmgw", "flux-schnell", "v100-32g", "installs no ComfyUI", "added by itself", "P pictures and 3D"} { if !strings.Contains(v, want) { t.Errorf("%q not shown:\n%s", want, v) } } // A control plane that cannot say shows none of it. m.data.presets = nil if v := m.View(); strings.Contains(v, "come with llmgw") || strings.Contains(v, "P pictures") { t.Errorf("presets shown from nothing:\n%s", v) } } func TestAPresetThatInstallsComfyUIIsAddedOnlyWhenConfirmed(t *testing.T) { m, s := consoleWith(t, cModels) m.data.presets = presetsHere() var tm tea.Model = m tm = press(tm, "a") f := tm.(consoleModel).formD if f == nil || !strings.Contains(f.fields[0].value(), "installs ComfyUI too") { t.Fatalf("no add dialog saying what flux-schnell brings: %+v", f) } tm = press(tm, "enter", "enter", "enter") if tm.(consoleModel).confirmD == nil || s.last() != "" { t.Fatalf("added without asking: %q", s.last()) } tm = pressRun(tm, "y") if got := s.last(); got != "POST /api/v1/presets/flux-schnell {}" { t.Fatalf("sent %q", got) } tm = press(tm, "esc", "p") // past what the add said if c := tm.(consoleModel).confirmD; c == nil || !strings.HasPrefix(c.title, "Stop adding") { t.Fatalf("P did not ask to stop: %+v", c) } _ = pressRun(tm, "y") if got := s.last(); got != `PUT /api/v1/presets/auto {"on":false}` { t.Fatalf("sent %q", got) } }