v0.1.0 2bf38c4

lsp_test.go RawHistoryFolder

1package tools
2
3import (
4	"context"
5	"encoding/json"
6	"os"
7	"path/filepath"
8	"runtime"
9	"strings"
10	"testing"
11	"unicode/utf8"
12
13	"github.com/bnema/zut/packages/agent/lsp"
14	"github.com/bnema/zut/packages/provider"
15)
16
17func TestLSPToolSchemaAndFormatting(t *testing.T) {
18	tool := NewLSPTool(t.TempDir(), lsp.NewManager())
19	var schema map[string]any
20	if err := json.Unmarshal(tool.Schema(), &schema); err != nil {
21		t.Fatal(err)
22	}
23	if tool.Name() != "lsp" || !strings.Contains(tool.Description(), "diagnostics") {
24		t.Fatalf("tool metadata missing")
25	}
26	result, err := tool.Execute(context.Background(), json.RawMessage(`{"action":"status"}`), nil)
27	if err != nil {
28		t.Fatal(err)
29	}
30	text, ok := result.Content[0].(provider.TextBlock)
31	if !ok || text.Text == "" {
32		t.Fatalf("status result = %#v", result.Content)
33	}
34	if !strings.Contains(text.Text, "[") && !strings.Contains(text.Text, "{") {
35		t.Fatalf("status was not formatted JSON: %q", text.Text)
36	}
37}
38
39func TestLSPToolGlobRespectsJailForSymlinkMatches(t *testing.T) {
40	if runtime.GOOS == "windows" {
41		t.Skip("symlink permissions vary on Windows")
42	}
43	root := t.TempDir()
44	outside := t.TempDir()
45	outsidePath := filepath.Join(outside, "outside.go")
46	if err := os.WriteFile(outsidePath, []byte("package outside\\n"), 0o644); err != nil {
47		t.Fatal(err)
48	}
49	if err := os.Symlink(outsidePath, filepath.Join(root, "link.go")); err != nil {
50		t.Fatal(err)
51	}
52	sandbox := NewSandbox(root)
53	sandbox.Lock()
54	tool := NewLSPTool(root, lsp.NewManager())
55	tool.Sandbox = sandbox
56	result, err := tool.Execute(context.Background(), json.RawMessage(`{"action":"diagnostics","path":"*.go","run_cli":false}`), nil)
57	if err != nil {
58		t.Fatal(err)
59	}
60	if !result.IsError {
61		t.Fatalf("jailed symlink glob was accepted: %#v", result)
62	}
63}
64
65func TestBoundLSPText(t *testing.T) {
66	value := boundLSPText(strings.Repeat("x", maxLSPToolOutput+10))
67	if len(value) > maxLSPToolOutput || !strings.Contains(value, "truncated") {
68		t.Fatalf("bound output = %d bytes", len(value))
69	}
70	unicodeValue := boundLSPText(strings.Repeat("界", maxLSPToolOutput/3+10))
71	if !utf8.ValidString(unicodeValue) {
72		t.Fatal("bound output split a UTF-8 sequence")
73	}
74}

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