1package modes
2
3import (
4 "context"
5 "slices"
6 "strings"
7 "testing"
8
9 "github.com/patriceckhart/zot/packages/tui"
10)
11
12func TestReasoningSelectorUsesCurrentModelLevels(t *testing.T) {
13 i := &Interactive{cfg: InteractiveConfig{
14 Provider: "openai",
15 Model: "gpt-5.6-sol",
16 Reasoning: "minimum",
17 }}
18
19 item := i.reasoningSettingItem()
20 var levels []string
21 for _, option := range item.options {
22 levels = append(levels, option.value)
23 }
24 want := []string{"", "low", "medium", "high", "xhigh", "max"}
25 if !slices.Equal(levels, want) {
26 t.Fatalf("reasoning levels = %q, want %q", levels, want)
27 }
28 if item.options[item.choice].value != "low" {
29 t.Fatalf("clamped current level = %q, want low", item.options[item.choice].value)
30 }
31}
32
33func TestReasoningSelectorOnlyOffersOffForUnsupportedModel(t *testing.T) {
34 i := &Interactive{cfg: InteractiveConfig{
35 Provider: "google",
36 Model: "gemini-2.0-flash",
37 Reasoning: "high",
38 }}
39
40 item := i.reasoningSettingItem()
41 if len(item.options) != 1 || item.options[0].value != "" {
42 t.Fatalf("reasoning levels = %#v, want off only", item.options)
43 }
44 if item.hint != "current model does not support reasoning" {
45 t.Fatalf("hint = %q", item.hint)
46 }
47}
48
49func TestReasoningCommandOpensDirectSelector(t *testing.T) {
50 i := &Interactive{
51 cfg: InteractiveConfig{
52 Reasoning: "high",
53 },
54 settingsDialog: newSettingsDialog(),
55 }
56
57 i.runSlash(context.Background(), "/reasoning")
58
59 if !i.settingsDialog.Active() || !i.settingsDialog.selecting || !i.settingsDialog.direct {
60 t.Fatal("reasoning command did not open the direct option selector")
61 }
62 lines := i.settingsDialog.Render(tui.Dark, 100)
63 text := strings.Join(lines, "\n")
64 if !strings.Contains(text, "reasoning level") || !strings.Contains(text, "high") {
65 t.Fatalf("reasoning selector missing current level: %q", text)
66 }
67 i.settingsDialog.HandleKey(tui.Key{Kind: tui.KeyDown})
68 act := i.settingsDialog.HandleKey(tui.Key{Kind: tui.KeyEnter})
69 i.applySettingChange(act)
70 if i.cfg.Reasoning != "xhigh" || i.settingsDialog.Active() {
71 t.Fatalf("reasoning selection was not applied and closed: level=%q active=%v", i.cfg.Reasoning, i.settingsDialog.Active())
72 }
73 if i.statusOK != "reasoning level xhigh" {
74 t.Fatalf("reasoning status = %q", i.statusOK)
75 }
76
77 i.runSlash(context.Background(), "/reasoning")
78 act = i.settingsDialog.HandleKey(tui.Key{Kind: tui.KeyEsc})
79 if !act.Close || i.settingsDialog.Active() {
80 t.Fatal("escape did not close the direct reasoning selector")
81 }
82}
83
84func TestModelDialogAdvertisesReasoningSelector(t *testing.T) {
85 d := newModelDialog()
86 d.Open("", nil, "high")
87
88 text := strings.Join(d.Render(tui.Dark, 100), "\n")
89 if !strings.Contains(text, "current reasoning: high") || !strings.Contains(text, "/reasoning") {
90 t.Fatalf("model dialog missing reasoning guidance: %q", text)
91 }
92}
93
94func TestModelPickerSkipsLlamaRefreshWhenRouterIsNotConfigured(t *testing.T) {
95 i := &Interactive{
96 cfg: InteractiveConfig{
97 RefreshLlamaCPPModels: func(context.Context) error { return nil },
98 },
99 modelRefresh: make(chan modelRefreshResult, 1),
100 modelDialog: newModelDialog(),
101 }
102
103 i.runSlash(context.Background(), "/model")
104
105 if !i.modelDialog.Active() {
106 t.Fatal("model picker did not open immediately")
107 }
108 if i.statusOK == "refreshing models" {
109 t.Fatal("refresh status shown without llama.cpp router configuration")
110 }
111}