v0.51.0 a9d674e

model_profiles_test.go RawHistoryFolder

1package agent
2
3import (
4	"os"
5	"testing"
6
7	"github.com/bnema/zut/packages/agent/modes"
8	"github.com/bnema/zut/packages/core"
9	"github.com/bnema/zut/packages/tui"
10)
11
12func TestActiveAliasedModelProfilePreservesAutosave(t *testing.T) {
13	t.Setenv("ZUT_HOME", t.TempDir())
14	cfg := Config{
15		ActiveModelProfile: 2,
16		QuickModelShortcuts: []QuickModelShortcut{
17			{},
18			{Provider: "bedrock", Model: "amazon.nova-lite-v1:0"},
19		},
20	}
21	if err := SaveConfig(cfg); err != nil {
22		t.Fatal(err)
23	}
24	r, err := Resolve(Args{APIKey: "synthetic-test-key"}, false)
25	if err != nil {
26		t.Fatal(err)
27	}
28	if r.Provider != "amazon-bedrock" {
29		t.Fatalf("resolved provider = %q", r.Provider)
30	}
31	i := modes.NewInteractive(modes.InteractiveConfig{
32		Theme: tui.Dark, Provider: r.Provider, Model: r.Model, Reasoning: r.Reasoning,
33		Agent:               core.NewAgent(nil, r.Model, "", nil),
34		SettingsStore:       configSettingsStore{},
35		QuickModelShortcuts: interactiveQuickModelShortcuts(cfg.QuickModelShortcuts),
36		ActiveModelProfile:  cfg.ActiveModelProfile,
37	})
38	// A manual model edit must save to the already-active slot, not require
39	// selecting /profile again to repair a spurious startup detachment.
40	const nextModel = "amazon.nova-micro-v1:0"
41	i.SubmitSlash("/model " + nextModel)
42	if i.Agent().Model != nextModel {
43		t.Fatal("model edit was not applied")
44	}
45	saved, err := LoadConfig()
46	if err != nil {
47		t.Fatal(err)
48	}
49	want := QuickModelShortcut{Provider: "amazon-bedrock", Model: nextModel}
50	if saved.ActiveModelProfile != 2 || saved.QuickModelShortcuts[1] != want {
51		t.Fatalf("active aliased profile did not autosave: active=%d profile=%+v", saved.ActiveModelProfile, saved.QuickModelShortcuts[1])
52	}
53	if saved.QuickModelShortcuts[0] != (QuickModelShortcut{}) || cfg.QuickModelShortcuts[1].Provider != "bedrock" {
54		t.Fatal("conversion or saving changed an unrelated slot or the input config")
55	}
56}
57
58func TestLegacyQuickModelShortcutPreservesProfileState(t *testing.T) {
59	t.Setenv("ZUT_HOME", t.TempDir())
60	if err := SaveConfig(Config{
61		QuickModelShortcuts: []QuickModelShortcut{{
62			Provider: "openai", Model: "gpt-5.6-sol", Reasoning: "high", FastMode: true,
63		}},
64	}); err != nil {
65		t.Fatal(err)
66	}
67	if err := (configSettingsStore{}).SetQuickModelShortcut(1, "openai", "gpt-5.5"); err != nil {
68		t.Fatal(err)
69	}
70	cfg, err := LoadConfig()
71	if err != nil {
72		t.Fatal(err)
73	}
74	profile := cfg.QuickModelShortcuts[0]
75	if profile.Model != "gpt-5.5" || profile.Reasoning != "high" || !profile.FastMode {
76		t.Fatalf("legacy shortcut update lost profile state: %+v", profile)
77	}
78}
79
80func TestModelProfileConfigRoundTrip(t *testing.T) {
81	t.Setenv("ZUT_HOME", t.TempDir())
82	if err := SaveConfig(Config{Theme: "dark"}); err != nil {
83		t.Fatal(err)
84	}
85	store := configSettingsStore{}
86	p := modes.QuickModelShortcut{Provider: "openai", Model: "gpt-5.6-sol", Reasoning: "max", FastMode: true}
87	if err := store.SetModelProfile(9, p, 9); err != nil {
88		t.Fatal(err)
89	}
90	cfg, err := LoadConfig()
91	if err != nil {
92		t.Fatal(err)
93	}
94	if cfg.ActiveModelProfile != 9 || len(cfg.QuickModelShortcuts) != 9 || cfg.Reasoning != "max" || cfg.Model != p.Model || cfg.FastMode == nil || !*cfg.FastMode || cfg.QuickModelShortcuts[8].FastMode != p.FastMode || cfg.Theme != "dark" {
95		t.Fatalf("config=%+v", cfg)
96	}
97	// The selected profile is authoritative even after hand-editing its model
98	// and reasoning, without requiring duplicate changes to the legacy defaults.
99	cfg.QuickModelShortcuts[8].Reasoning = "low"
100	cfg.applyActiveModelProfile()
101	if cfg.Reasoning != "low" {
102		t.Fatal("active profile did not supply defaults")
103	}
104	if err := store.SetModelProfile(9, modes.QuickModelShortcut{}, 0); err != nil {
105		t.Fatal(err)
106	}
107	cleared, err := LoadConfig()
108	if err != nil {
109		t.Fatal(err)
110	}
111	if cleared.ActiveModelProfile != 0 || len(cleared.QuickModelShortcuts) != 0 || cleared.Model != p.Model {
112		t.Fatalf("clear=%+v", cleared)
113	}
114}
115
116func TestModelProfileConfigLegacyAndInvalidActiveSlots(t *testing.T) {
117	t.Setenv("ZUT_HOME", t.TempDir())
118	if err := os.WriteFile(ConfigPath(), []byte(`{"provider":"openai","model":"gpt-5.5","reasoning":"high","quick_model_shortcuts":[{"provider":"openai","model":"gpt-5.6-sol"}]}`), 0600); err != nil {
119		t.Fatal(err)
120	}
121	cfg, err := LoadConfig()
122	if err != nil {
123		t.Fatal(err)
124	}
125	for _, slot := range []int{-1, 0, 2, 10} {
126		copy := cfg
127		copy.ActiveModelProfile = slot
128		copy.applyActiveModelProfile()
129		want := "gpt-5.6-sol" // missing/out-of-range active slot defaults to 1
130		if slot == 2 {
131			want = "gpt-5.5"
132		} // valid but unassigned slot
133		if copy.Model != want {
134			t.Fatalf("active slot %d: model %s, want %s", slot, copy.Model, want)
135		}
136	}
137	cfg.ActiveModelProfile = 1
138	cfg.applyActiveModelProfile()
139	if cfg.Model != "gpt-5.6-sol" || cfg.Reasoning != "" {
140		t.Fatal("legacy slots should recall with reasoning off")
141	}
142}
143
144func TestModelProfileStoreRejectsInvalidSlotsAndCorruptConfig(t *testing.T) {
145	t.Setenv("ZUT_HOME", t.TempDir())
146	store := configSettingsStore{}
147	for _, slot := range []int{-1, 0, 10} {
148		if err := store.SetModelProfile(slot, modes.QuickModelShortcut{}, 0); err == nil {
149			t.Fatalf("accepted slot %d", slot)
150		}
151	}
152	original := []byte(`{"invalid":`)
153	if err := os.WriteFile(ConfigPath(), original, 0600); err != nil {
154		t.Fatal(err)
155	}
156	if err := store.SetModelProfile(1, modes.QuickModelShortcut{Provider: "openai", Model: "gpt-5.5"}, 1); err == nil {
157		t.Fatal("corrupt config was accepted")
158	}
159	got, err := os.ReadFile(ConfigPath())
160	if err != nil || string(got) != string(original) {
161		t.Fatal("corrupt config was overwritten")
162	}
163}
164
165func TestModelProfileResolveDefaultsAndExplicitOverrides(t *testing.T) {
166	t.Setenv("ZUT_HOME", t.TempDir())
167	if err := SaveConfig(Config{Provider: "openai", Model: "gpt-5.5", Reasoning: "high", ActiveModelProfile: 1, QuickModelShortcuts: []QuickModelShortcut{{Provider: "openai", Model: "gpt-5.6-sol", Reasoning: "max"}}}); err != nil {
168		t.Fatal(err)
169	}
170	for _, override := range []bool{false, true} {
171		args := Args{APIKey: "synthetic-test-key"}
172		wantModel, wantReasoning := "gpt-5.6-sol", "max"
173		if override {
174			args.Model, args.Reasoning = "gpt-5.5", "off"
175			wantModel, wantReasoning = "gpt-5.5", ""
176		}
177		r, err := Resolve(args, false)
178		if err != nil {
179			t.Fatal(err)
180		}
181		if r.Model != wantModel || r.Reasoning != wantReasoning {
182			t.Fatalf("override=%v model=%s reasoning=%s", override, r.Model, r.Reasoning)
183		}
184	}
185}

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 476

↑↓ moveenter openesc close