v0.38.0 58133ea

settings_store_test.go RawHistoryFolder

1package agent
2
3import (
4	"strings"
5	"testing"
6)
7
8func TestSubagentsSystemAddendaListOnlyEnabledLifecycleTools(t *testing.T) {
9	builders := []struct {
10		name            string
11		build           func(bool, bool, bool) string
12		noSpawnFallback string
13	}{
14		{name: "proactive", build: ProactiveSubagentsSystemAddendumFor, noSpawnFallback: "Continue non-delegated work locally."},
15		{name: "strict", build: StrictOrchestratorSystemAddendumFor, noSpawnFallback: "Do not implement, debug, test, or review directly."},
16	}
17	for _, builder := range builders {
18		t.Run(builder.name, func(t *testing.T) {
19			for _, tc := range []struct {
20				name      string
21				spawn     bool
22				stop      bool
23				resume    bool
24				want      []string
25				unwanted  []string
26				available bool
27			}{
28				{name: "none", spawn: true, unwanted: []string{"subagent_stop", "subagent_resume"}, available: true},
29				{name: "fully unavailable", unwanted: []string{"subagent_stop", "subagent_resume"}},
30				{name: "stop", spawn: true, stop: true, want: []string{"subagent_stop"}, unwanted: []string{"subagent_resume"}, available: true},
31				{name: "resume", spawn: true, resume: true, want: []string{"subagent_resume"}, unwanted: []string{"subagent_stop"}, available: true},
32				{name: "both", spawn: true, stop: true, resume: true, want: []string{"subagent_stop", "subagent_resume"}, available: true},
33				{name: "stop without spawn", stop: true, want: []string{"subagent_stop", "Spawning new workers is unavailable"}, unwanted: []string{"subagent_resume"}},
34				{name: "resume without spawn", resume: true, want: []string{"subagent_resume", "Spawning new workers is unavailable"}, unwanted: []string{"subagent_stop"}},
35				{name: "both without spawn", stop: true, resume: true, want: []string{"subagent_stop", "subagent_resume", "Spawning new workers is unavailable"}},
36			} {
37				t.Run(tc.name, func(t *testing.T) {
38					got := builder.build(tc.spawn, tc.stop, tc.resume)
39					if !tc.spawn && (tc.stop || tc.resume) && !strings.Contains(got, builder.noSpawnFallback) {
40						t.Fatalf("addendum missing mode-specific no-spawn fallback %q:\n%s", builder.noSpawnFallback, got)
41					}
42					for _, want := range tc.want {
43						if !strings.Contains(got, want) {
44							t.Fatalf("addendum missing enabled lifecycle tool %q:\n%s", want, got)
45						}
46					}
47					for _, unwanted := range tc.unwanted {
48						if strings.Contains(got, unwanted) {
49							t.Fatalf("addendum mentions unavailable lifecycle tool %q:\n%s", unwanted, got)
50						}
51					}
52					if gotAvailable := !strings.Contains(got, "unavailable in this session") && !strings.Contains(got, "Spawning new workers is unavailable"); gotAvailable != tc.available {
53						t.Fatalf("delegation available = %t, want %t:\n%s", gotAvailable, tc.available, got)
54					}
55				})
56			}
57		})
58	}
59}
60
61func TestSubagentPoliciesSeparateProactiveAndStrictOwnership(t *testing.T) {
62	proactive := ProactiveSubagentsSystemAddendumFor(true, false, false)
63	for _, want := range []string{"primary owner and implementer", "immediate next task you will perform locally", "If you cannot name useful non-overlapping local work, do not delegate", "Do not search, read, test, review, edit"} {
64		if !strings.Contains(proactive, want) {
65			t.Fatalf("proactive addendum missing %q:\n%s", want, proactive)
66		}
67	}
68	if strings.Contains(proactive, "not an implementer") {
69		t.Fatalf("proactive addendum retained strict orchestrator contract:\n%s", proactive)
70	}
71
72	strict := StrictOrchestratorSystemAddendumFor(true, false, false)
73	for _, want := range []string{"not an implementer", "non-overlapping worker scopes", "Once a worker is active", "Only coordinate workers"} {
74		if !strings.Contains(strict, want) {
75			t.Fatalf("strict addendum missing %q:\n%s", want, strict)
76		}
77	}
78}
79
80func TestSubagentPoliciesHandleUnavailableDelegationByMode(t *testing.T) {
81	proactive := ProactiveSubagentsSystemAddendumFor(false, false, false)
82	if !strings.Contains(proactive, "Continue the user's task locally") || strings.Contains(proactive, "report this limitation") {
83		t.Fatalf("proactive unavailable guidance blocks local work:\n%s", proactive)
84	}
85	strict := StrictOrchestratorSystemAddendumFor(false, false, false)
86	if !strings.Contains(strict, "report this limitation") || !strings.Contains(strict, "rather than implementing") {
87		t.Fatalf("strict unavailable guidance permits local implementation:\n%s", strict)
88	}
89}
90
91func TestConfigSettingsStorePersistsShowInstructionsAtStartup(t *testing.T) {
92	t.Setenv("ZUT_HOME", t.TempDir())
93	if err := SaveConfig(Config{Theme: "dark"}); err != nil {
94		t.Fatal(err)
95	}
96
97	if err := (configSettingsStore{}).SetShowInstructionsAtStartup(true); err != nil {
98		t.Fatal(err)
99	}
100	cfg, err := LoadConfig()
101	if err != nil {
102		t.Fatal(err)
103	}
104	if cfg.ShowInstructionsAtStartup == nil || !*cfg.ShowInstructionsAtStartup {
105		t.Fatal("show_instructions_at_startup was not persisted as enabled")
106	}
107	if cfg.Theme != "dark" {
108		t.Fatalf("unrelated config changed: theme = %q, want dark", cfg.Theme)
109	}
110}
111
112func TestConfigSettingsStorePersistsTerminalAlerts(t *testing.T) {
113	t.Setenv("ZUT_HOME", t.TempDir())
114	if err := SaveConfig(Config{Theme: "dark"}); err != nil {
115		t.Fatal(err)
116	}
117
118	if err := (configSettingsStore{}).SetTerminalAlertsEnabled(false); err != nil {
119		t.Fatal(err)
120	}
121	cfg, err := LoadConfig()
122	if err != nil {
123		t.Fatal(err)
124	}
125	if cfg.TerminalAlertsEnabled == nil || *cfg.TerminalAlertsEnabled {
126		t.Fatal("terminal_alerts_enabled was not persisted as disabled")
127	}
128	if cfg.Theme != "dark" {
129		t.Fatalf("unrelated config changed: theme = %q, want dark", cfg.Theme)
130	}
131}
132
133func TestConfigSettingsStorePersistsTerminalTitle(t *testing.T) {
134	t.Setenv("ZUT_HOME", t.TempDir())
135	if err := SaveConfig(Config{Theme: "dark"}); err != nil {
136		t.Fatal(err)
137	}
138
139	if err := (configSettingsStore{}).SetTerminalTitleEnabled(false); err != nil {
140		t.Fatal(err)
141	}
142	cfg, err := LoadConfig()
143	if err != nil {
144		t.Fatal(err)
145	}
146	if cfg.TerminalTitleEnabled == nil || *cfg.TerminalTitleEnabled {
147		t.Fatal("terminal_title_enabled was not persisted as disabled")
148	}
149	if cfg.Theme != "dark" {
150		t.Fatalf("unrelated config changed: theme = %q, want dark", cfg.Theme)
151	}
152}
153
154func TestConfigSettingsStorePersistsJailByDefault(t *testing.T) {
155	t.Setenv("ZUT_HOME", t.TempDir())
156	if err := SaveConfig(Config{Theme: "dark"}); err != nil {
157		t.Fatal(err)
158	}
159
160	if err := (configSettingsStore{}).SetJailByDefault(true); err != nil {
161		t.Fatal(err)
162	}
163	cfg, err := LoadConfig()
164	if err != nil {
165		t.Fatal(err)
166	}
167	if cfg.JailByDefault == nil || !*cfg.JailByDefault {
168		t.Fatal("jail_by_default was not persisted as enabled")
169	}
170	if cfg.Theme != "dark" {
171		t.Fatalf("unrelated config changed: theme = %q, want dark", cfg.Theme)
172	}
173}
174
175func TestConfigSettingsStorePersistsAutoCompactThreshold(t *testing.T) {
176	t.Setenv("ZUT_HOME", t.TempDir())
177	if err := SaveConfig(Config{Theme: "dark"}); err != nil {
178		t.Fatal(err)
179	}
180
181	if err := (configSettingsStore{}).SetAutoCompactThreshold(70); err != nil {
182		t.Fatal(err)
183	}
184	cfg, err := LoadConfig()
185	if err != nil {
186		t.Fatal(err)
187	}
188	if cfg.AutoCompactThreshold == nil || *cfg.AutoCompactThreshold != 70 {
189		t.Fatalf("auto_compact_threshold = %v, want 70", cfg.AutoCompactThreshold)
190	}
191	if cfg.Theme != "dark" {
192		t.Fatalf("unrelated config changed: theme = %q, want dark", cfg.Theme)
193	}
194}
195
196func TestConfigSettingsStorePersistsLSPDefaults(t *testing.T) {
197	t.Setenv("ZUT_HOME", t.TempDir())
198	if err := SaveConfig(Config{Theme: "dark"}); err != nil {
199		t.Fatal(err)
200	}
201
202	if err := (configSettingsStore{}).SetLSPEnabled(false); err != nil {
203		t.Fatal(err)
204	}
205	if err := (configSettingsStore{}).SetSubagentLSPEnabled(false); err != nil {
206		t.Fatal(err)
207	}
208	cfg, err := LoadConfig()
209	if err != nil {
210		t.Fatal(err)
211	}
212	if cfg.LSPEnabled == nil || *cfg.LSPEnabled {
213		t.Fatal("lsp_enabled was not persisted as disabled")
214	}
215	if cfg.SubagentLSPEnabled == nil || *cfg.SubagentLSPEnabled {
216		t.Fatal("subagent_lsp_enabled was not persisted as disabled")
217	}
218	if cfg.Theme != "dark" {
219		t.Fatalf("unrelated config changed: theme = %q, want dark", cfg.Theme)
220	}
221}
222
223func TestConfigLSPEnabledForDefaultsToTrue(t *testing.T) {
224	cfg := Config{}
225	if !cfg.LSPEnabledFor(false) {
226		t.Fatal("main-session LSP should default to enabled")
227	}
228	if !cfg.LSPEnabledFor(true) {
229		t.Fatal("sub-agent LSP should default to enabled")
230	}
231
232	noMain, noSub := false, false
233	cfg.LSPEnabled = &noMain
234	cfg.SubagentLSPEnabled = &noSub
235	if cfg.LSPEnabledFor(false) || cfg.LSPEnabledFor(true) {
236		t.Fatal("explicitly disabled LSP settings were ignored")
237	}
238	yesSub := true
239	cfg.SubagentLSPEnabled = &yesSub
240	write, edit := true, true
241	cfg.LSPDiagnosticsOnWrite = &write
242	cfg.LSPDiagnosticsOnEdit = &edit
243	if cfg.LSPDiagnosticsOnWriteEnabled(false) || cfg.LSPDiagnosticsOnEditEnabled(false) {
244		t.Fatal("diagnostics remained enabled with main-session LSP disabled")
245	}
246	if !cfg.LSPDiagnosticsOnWriteEnabled(true) || !cfg.LSPDiagnosticsOnEditEnabled(true) {
247		t.Fatal("sub-agent diagnostics did not follow sub-agent LSP settings")
248	}
249}
250
251func TestConfigSettingsStoreResetsRemovedInheritedThemeToAuto(t *testing.T) {
252	t.Setenv("ZUT_HOME", t.TempDir())
253	if err := SaveConfig(Config{Theme: "dark"}); err != nil {
254		t.Fatal(err)
255	}
256
257	if err := (configSettingsStore{}).SetTheme("inherited"); err != nil {
258		t.Fatal(err)
259	}
260	cfg, err := LoadConfig()
261	if err != nil {
262		t.Fatal(err)
263	}
264	if cfg.Theme != "" {
265		t.Fatalf("theme = %q, want auto", cfg.Theme)
266	}
267}
268
269func TestConfigWebSearchEnabledForCLIDefaultsToTrue(t *testing.T) {
270	cfg := Config{}
271	if !cfg.WebSearchEnabledForCLI() {
272		t.Fatal("web search should default to enabled when the config field is absent")
273	}
274	disabled := false
275	cfg.WebSearchEnabled = &disabled
276	if cfg.WebSearchEnabledForCLI() {
277		t.Fatal("explicitly disabled web search setting was ignored")
278	}
279}
280
281func TestConfigSettingsStorePersistsWebSearch(t *testing.T) {
282	t.Setenv("ZUT_HOME", t.TempDir())
283	if err := SaveConfig(Config{Theme: "dark"}); err != nil {
284		t.Fatal(err)
285	}
286
287	if err := (configSettingsStore{}).SetWebSearchEnabled(false); err != nil {
288		t.Fatal(err)
289	}
290	cfg, err := LoadConfig()
291	if err != nil {
292		t.Fatal(err)
293	}
294	if cfg.WebSearchEnabled == nil || *cfg.WebSearchEnabled {
295		t.Fatal("web_search_enabled was not persisted as disabled")
296	}
297	if cfg.Theme != "dark" {
298		t.Fatalf("unrelated config changed: theme = %q, want dark", cfg.Theme)
299	}
300}

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