v0.2.78 cc6b04d

fsutil_test.go RawHistoryFolder

1package main
2
3import (
4	"os"
5	"path/filepath"
6	"testing"
7)
8
9func TestWriteFileAtomicWritesContentAndPerms(t *testing.T) {
10	path := filepath.Join(t.TempDir(), "sub", "file.json")
11	if err := writeFileAtomic(path, []byte("{}\n"), 0o600); err != nil {
12		t.Fatalf("writeFileAtomic: %v", err)
13	}
14	data, err := os.ReadFile(path)
15	if err != nil {
16		t.Fatalf("read back: %v", err)
17	}
18	if string(data) != "{}\n" {
19		t.Fatalf("content = %q, want %q", data, "{}\n")
20	}
21	info, err := os.Stat(path)
22	if err != nil {
23		t.Fatalf("stat: %v", err)
24	}
25	if got := info.Mode().Perm(); got != 0o600 {
26		t.Fatalf("perm = %o, want 600", got)
27	}
28}
29
30func TestWriteFileAtomicLeavesNoTempFileBehind(t *testing.T) {
31	dir := t.TempDir()
32	path := filepath.Join(dir, "file.json")
33	if err := writeFileAtomic(path, []byte("x"), 0o600); err != nil {
34		t.Fatalf("writeFileAtomic: %v", err)
35	}
36	entries, err := os.ReadDir(dir)
37	if err != nil {
38		t.Fatalf("readdir: %v", err)
39	}
40	if len(entries) != 1 || entries[0].Name() != "file.json" {
41		t.Fatalf("directory not clean: %v", entries)
42	}
43}
44
45func TestToolCacheRoundTrip(t *testing.T) {
46	path := filepath.Join(t.TempDir(), "mcp-tools-cache.json")
47	in := toolCache{
48		Version: toolCacheVersion,
49		Servers: map[string]cachedServer{
50			"srv": {Fingerprint: "abc", Tools: []cachedTool{
51				{Name: "t1", Description: "d", Schema: []byte(`{"type":"object"}`)},
52			}},
53		},
54	}
55	if err := writeToolCache(path, in); err != nil {
56		t.Fatalf("writeToolCache: %v", err)
57	}
58	out, err := readToolCache(path)
59	if err != nil {
60		t.Fatalf("readToolCache: %v", err)
61	}
62	if !toolCachesEqual(in, out) {
63		t.Fatalf("round trip mismatch:\nin:  %+v\nout: %+v", in, out)
64	}
65}
66
67func TestToolCacheVersionMismatchInvalidates(t *testing.T) {
68	path := filepath.Join(t.TempDir(), "mcp-tools-cache.json")
69	if err := os.WriteFile(path, []byte(`{"version": 999, "servers": {"srv": {}}}`), 0o600); err != nil {
70		t.Fatal(err)
71	}
72	out, err := readToolCache(path)
73	if err != nil {
74		t.Fatalf("readToolCache: %v", err)
75	}
76	if len(out.Servers) != 0 || out.Version != toolCacheVersion {
77		t.Fatalf("stale-version cache must be discarded, got %+v", out)
78	}
79}
80
81func TestConfigFileWrittenOwnerOnly(t *testing.T) {
82	tmp := t.TempDir()
83	t.Setenv("ZOT_HOME", tmp)
84
85	if _, err := handleSetup([]string{"add", "grep"}, tmp); err != nil {
86		t.Fatalf("handleSetup: %v", err)
87	}
88	info, err := os.Stat(filepath.Join(tmp, "mcp.json"))
89	if err != nil {
90		t.Fatalf("stat mcp.json: %v", err)
91	}
92	if got := info.Mode().Perm(); got != 0o600 {
93		t.Fatalf("mcp.json perm = %o, want 600 (may contain auth headers)", got)
94	}
95}

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