v0.11.2 619aabb

slash_suggest_test.go RawHistoryFolder

1package modes
2
3import (
4	"slices"
5	"testing"
6
7	"github.com/bnema/zut/packages/agent/skills"
8)
9
10func TestSlashSuggesterHidesUnjailUntilJailed(t *testing.T) {
11	s := newSlashSuggester()
12
13	if got := commandNames(s.matches("/unj")); contains(got, "/unjail") {
14		t.Fatalf("/unjail should be hidden while not jailed, got %v", got)
15	}
16	if got := commandNames(s.matches("/ja")); !contains(got, "/jail") {
17		t.Fatalf("/jail should be visible while not jailed, got %v", got)
18	}
19
20	s.SetJailed(true)
21	if got := commandNames(s.matches("/unj")); !contains(got, "/unjail") {
22		t.Fatalf("/unjail should be visible while jailed, got %v", got)
23	}
24	if got := commandNames(s.matches("/ja")); contains(got, "/jail") {
25		t.Fatalf("/jail should be hidden while jailed, got %v", got)
26	}
27}
28
29func TestSlashSuggesterShowsLlamaOnlyWhenConfigured(t *testing.T) {
30	s := newSlashSuggester()
31	if got := commandNames(s.matches("/llama")); contains(got, "/llama") {
32		t.Fatalf("/llama visible without login: %v", got)
33	}
34	s.SetLlamaConfigured(true)
35	if got := commandNames(s.matches("/llama")); !contains(got, "/llama") {
36		t.Fatalf("/llama missing with login: %v", got)
37	}
38}
39
40func TestSlashSuggesterHasSupervisor(t *testing.T) {
41	s := newSlashSuggester()
42	if got := commandNames(s.matches("/su")); !contains(got, "/subagents") {
43		t.Fatalf("/subagents missing from suggestions, got %v", got)
44	}
45}
46
47func TestSlashSuggesterHasFastModeToggle(t *testing.T) {
48	s := newSlashSuggester()
49	if got := commandNames(s.matches("/fa")); !contains(got, "/fast") {
50		t.Fatalf("/fast missing from suggestions, got %v", got)
51	}
52	if !isKnownSlashCommand("/FAST") {
53		t.Fatal("/FAST was not recognized as a built-in command")
54	}
55}
56
57func TestSlashCommandsAreCaseInsensitive(t *testing.T) {
58	s := newSlashSuggester()
59	if got := commandNames(s.matches("/EX")); !contains(got, "/exit") {
60		t.Fatalf("/EX did not suggest /exit: %v", got)
61	}
62	if !isKnownSlashCommand("/Exit") {
63		t.Fatal("/Exit was not recognized as a built-in command")
64	}
65	if !isKnownSlashCommand("/Fork") {
66		t.Fatal("/Fork was not recognized as a built-in command")
67	}
68	if !slashCancelsTurn("/CLEAR") {
69		t.Fatal("/CLEAR did not retain /clear cancellation semantics")
70	}
71	if !slashCommandCancelsTurn("/fork") || !slashCommandCancelsTurn("/session fork") {
72		t.Fatal("fork commands did not retain idle-transition cancellation semantics")
73	}
74	if slashCommandCancelsTurn("/session tree") {
75		t.Fatal("/session tree should use its fail-closed gate instead of cancelling a turn")
76	}
77}
78
79func TestSlashSuggesterBuiltinsShadowExtensionsCaseInsensitively(t *testing.T) {
80	s := newSlashSuggester()
81	s.SetExtra([]slashCommand{{Name: "/EXIT", Desc: "extension exit"}})
82	matches := commandNames(s.matches("/exit"))
83	if len(matches) != 1 || matches[0] != "/exit" {
84		t.Fatalf("matches = %v, want only built-in /exit", matches)
85	}
86}
87
88func TestSlashSuggesterCompletesVisibleSkills(t *testing.T) {
89	s := newSlashSuggester()
90	s.SetSkills([]*skills.Skill{
91		{Name: "test-fix", Description: "Fix failing tests."},
92		{Name: "ai-development-workflow", Description: "Guide AI development."},
93		{Name: "manual-only", Description: "Explicit invocation only.", DisableModelInvocation: true},
94		{Name: "builtin", Description: "Internal.", Builtin: true},
95	})
96
97	if got, want := commandNames(s.matches("/skill:")), []string{
98		"/skill:ai-development-workflow",
99		"/skill:manual-only",
100		"/skill:test-fix",
101	}; !slices.Equal(got, want) {
102		t.Fatalf("matches = %v, want %v", got, want)
103	}
104	s.lastMatches = s.matches("/skill:")
105	if got := s.Selection("/skill:"); got != "/skill:ai-development-workflow" {
106		t.Fatalf("initial selection = %q", got)
107	}
108	s.Down()
109	if got := s.Selection("/skill:"); got != "/skill:manual-only" {
110		t.Fatalf("selection after down = %q", got)
111	}
112	if got := commandNames(s.matches("/SKILL:ai-dev")); !slices.Equal(got, []string{"/skill:ai-development-workflow"}) {
113		t.Fatalf("filtered matches = %v", got)
114	}
115	if got := s.Selection("/skill:ai-dev"); got != "/skill:ai-development-workflow" {
116		t.Fatalf("selection = %q", got)
117	}
118}
119
120func TestSlashSuggesterRefreshesSkillsOncePerInputSession(t *testing.T) {
121	s := newSlashSuggester()
122	if s.SkillInputStarted("/skill") {
123		t.Fatal("refresh started before colon")
124	}
125	if !s.SkillInputStarted("/skill:") {
126		t.Fatal("first /skill: did not request refresh")
127	}
128	if s.SkillInputStarted("/skill:review") {
129		t.Fatal("same input session requested another refresh")
130	}
131	if s.SkillInputStarted("") {
132		t.Fatal("leaving skill input requested refresh")
133	}
134	if !s.SkillInputStarted("/SKILL:") {
135		t.Fatal("new case-insensitive input session did not request refresh")
136	}
137}
138
139func commandNames(cmds []slashCommand) []string {
140	out := make([]string, 0, len(cmds))
141	for _, c := range cmds {
142		if !c.Header {
143			out = append(out, c.Name)
144		}
145	}
146	return out
147}
148
149func contains(xs []string, want string) bool {
150	for _, x := range xs {
151		if x == want {
152			return true
153		}
154	}
155	return false
156}

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