v0.3.55 fdc6643

interactive_model_test.go RawHistoryFolder

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 TestNormalizeModelQueryKeepsPresetAtSign(t *testing.T) {
85	if got := normalizeModelQuery("@preset/flash"); got != "@presetflash" {
86		t.Fatalf("id = %q; want @presetflash", got)
87	}
88	if got := normalizeModelQuery("preset"); got != "preset" {
89		t.Fatalf("query = %q; want preset", got)
90	}
91	haystack := normalizeModelQuery("openrouter @preset/flash Flash (preset)")
92	if !strings.Contains(haystack, normalizeModelQuery("preset")) {
93		t.Fatalf("%q does not contain preset", haystack)
94	}
95}
96
97func TestModelDialogAdvertisesReasoningSelector(t *testing.T) {
98	d := newModelDialog()
99	d.Open("", nil, "high")
100
101	text := strings.Join(d.Render(tui.Dark, 100), "\n")
102	if !strings.Contains(text, "current reasoning: high") || !strings.Contains(text, "/reasoning") {
103		t.Fatalf("model dialog missing reasoning guidance: %q", text)
104	}
105}
106
107func TestModelPickerSkipsLlamaRefreshWhenRouterIsNotConfigured(t *testing.T) {
108	i := &Interactive{
109		cfg: InteractiveConfig{
110			RefreshLlamaCPPModels: func(context.Context) error { return nil },
111		},
112		modelRefresh: make(chan modelRefreshResult, 1),
113		modelDialog:  newModelDialog(),
114	}
115
116	i.runSlash(context.Background(), "/model")
117
118	if !i.modelDialog.Active() {
119		t.Fatal("model picker did not open immediately")
120	}
121	if i.statusOK == "refreshing models" {
122		t.Fatal("refresh status shown without llama.cpp router configuration")
123	}
124}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 477

↑↓ moveenter openesc close