v0.4.7 2ff82fa

extcmd_test.go RawHistoryFolder

1package agent
2
3import (
4	"bytes"
5	"os"
6	"path/filepath"
7	"strings"
8	"testing"
9
10	"github.com/patriceckhart/zot/packages/agent/extensions"
11)
12
13// TestExtInstallDotSource verifies that `zot ext install .` derives the
14// extension name from the resolved directory name rather than collapsing
15// to the extensions/ parent directory (the false "already exists" bug).
16func TestExtInstallDotSource(t *testing.T) {
17	home := t.TempDir()
18	t.Setenv("ZOT_HOME", home)
19
20	// Pre-create extensions/ to mimic a normal first run.
21	if err := os.MkdirAll(filepath.Join(home, "extensions"), 0o755); err != nil {
22		t.Fatal(err)
23	}
24
25	srcParent := t.TempDir()
26	src := filepath.Join(srcParent, "kagi")
27	if err := os.MkdirAll(src, 0o755); err != nil {
28		t.Fatal(err)
29	}
30	if err := os.WriteFile(filepath.Join(src, "extension.json"), []byte(`{"name":"kagi"}`), 0o644); err != nil {
31		t.Fatal(err)
32	}
33
34	cwd, err := os.Getwd()
35	if err != nil {
36		t.Fatal(err)
37	}
38	defer os.Chdir(cwd)
39	if err := os.Chdir(src); err != nil {
40		t.Fatal(err)
41	}
42
43	if err := extInstall([]string{"."}); err != nil {
44		t.Fatalf("install with '.' failed: %v", err)
45	}
46
47	out := filepath.Join(home, "extensions", "kagi")
48	if _, err := os.Stat(filepath.Join(out, "extension.json")); err != nil {
49		t.Fatalf("expected installed extension at %s: %v", out, err)
50	}
51}
52
53// TestExtInstallRejectsParentName guards against deriving a name of ".."
54// from a source that resolves to a filesystem root edge case. A normal
55// directory always yields a real basename, so this just ensures the
56// guard logic does not crash for well-formed input.
57func TestExtInstallNamedDir(t *testing.T) {
58	home := t.TempDir()
59	t.Setenv("ZOT_HOME", home)
60
61	src := filepath.Join(t.TempDir(), "myext")
62	if err := os.MkdirAll(src, 0o755); err != nil {
63		t.Fatal(err)
64	}
65	if err := os.WriteFile(filepath.Join(src, "extension.json"), []byte(`{"name":"myext"}`), 0o644); err != nil {
66		t.Fatal(err)
67	}
68
69	if err := extInstall([]string{src}); err != nil {
70		t.Fatalf("install failed: %v", err)
71	}
72	if _, err := os.Stat(filepath.Join(home, "extensions", "myext", "extension.json")); err != nil {
73		t.Fatalf("expected installed extension: %v", err)
74	}
75}
76
77// TestCopyDirRespectsGitignore verifies that non-portable directories
78// listed in the source .gitignore (e.g. .venv, node_modules) are not
79// copied during install, while tracked files are.
80func TestCopyDirRespectsGitignore(t *testing.T) {
81	src := t.TempDir()
82	dst := filepath.Join(t.TempDir(), "out")
83
84	mustWrite := func(rel, content string) {
85		p := filepath.Join(src, filepath.FromSlash(rel))
86		if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
87			t.Fatal(err)
88		}
89		if err := os.WriteFile(p, []byte(content), 0o644); err != nil {
90			t.Fatal(err)
91		}
92	}
93
94	mustWrite("extension.json", `{"name":"x"}`)
95	mustWrite("main.py", "print('hi')")
96	mustWrite(".gitignore", ".venv/\nnode_modules/\n*.log\n")
97	mustWrite(".venv/bin/python", "binary")
98	mustWrite("node_modules/pkg/index.js", "module")
99	mustWrite("debug.log", "noise")
100	mustWrite("src/app.py", "code")
101	mustWrite(".git/config", "gitdir")
102
103	if err := copyDir(src, dst); err != nil {
104		t.Fatal(err)
105	}
106
107	wantPresent := []string{"extension.json", "main.py", "src/app.py", ".gitignore"}
108	for _, rel := range wantPresent {
109		if _, err := os.Stat(filepath.Join(dst, filepath.FromSlash(rel))); err != nil {
110			t.Fatalf("expected %s to be copied: %v", rel, err)
111		}
112	}
113
114	wantAbsent := []string{".venv", "node_modules", "debug.log", ".git"}
115	for _, rel := range wantAbsent {
116		if _, err := os.Stat(filepath.Join(dst, filepath.FromSlash(rel))); err == nil {
117			t.Fatalf("expected %s to be skipped, but it was copied", rel)
118		}
119	}
120}
121
122func TestGitignoreNegation(t *testing.T) {
123	g := loadGitignoreFromString("build/\n!build/keep.txt\n")
124	if !g.Match("build", true) {
125		t.Fatal("expected build/ dir to be ignored")
126	}
127	if g.Match("build/keep.txt", false) {
128		t.Fatal("expected build/keep.txt to be re-included by negation")
129	}
130}
131
132func TestExtDoctorStaticScanAndRender(t *testing.T) {
133	home := t.TempDir()
134	t.Setenv("ZOT_HOME", home)
135	cwd := t.TempDir()
136	oldCWD, err := os.Getwd()
137	if err != nil {
138		t.Fatal(err)
139	}
140	defer os.Chdir(oldCWD)
141	if err := os.Chdir(cwd); err != nil {
142		t.Fatal(err)
143	}
144
145	mustWrite := func(path, body string) {
146		t.Helper()
147		if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
148			t.Fatal(err)
149		}
150		if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
151			t.Fatal(err)
152		}
153	}
154
155	mustWrite(filepath.Join(cwd, ".zot", "extensions", "disabled", "extension.json"), `{"name":"disabled","exec":"./run.sh","enabled":false}`)
156	mustWrite(filepath.Join(cwd, ".zot", "extensions", "theme", "extension.json"), `{"name":"theme"}`)
157	mustWrite(filepath.Join(cwd, ".zot", "extensions", "theme", "theme.json"), `{"name":"Theme"}`)
158	mustWrite(filepath.Join(cwd, ".zot", "extensions", "skills", "extension.json"), `{"name":"skills","skills":["./skills"]}`)
159	mustWrite(filepath.Join(cwd, ".zot", "extensions", "bad", "extension.json"), `{bad json`)
160	mustWrite(filepath.Join(cwd, ".zot", "extensions", "dup", "extension.json"), `{"name":"dup","exec":"./project.sh"}`)
161	mustWrite(filepath.Join(home, "extensions", "dup", "extension.json"), `{"name":"dup","exec":"./global.sh"}`)
162
163	rows := scanExtDoctorStatic()
164	if len(rows) != 6 {
165		t.Fatalf("rows = %d, want 6: %#v", len(rows), rows)
166	}
167
168	var out bytes.Buffer
169	for _, row := range rows {
170		printExtDoctorRow(&out, row, extensions.ExtensionDiagnostic{})
171	}
172	got := out.String()
173	for _, want := range []string{
174		"disabled [project] disabled",
175		"theme [project] theme-only",
176		"skills [project] skill-only",
177		"bad [project] error",
178		"dup [global] shadowed",
179		"parse manifest:",
180	} {
181		if !strings.Contains(got, want) {
182			t.Fatalf("doctor output missing %q:\n%s", want, got)
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