v0.2.16 a7ef8c2

extcmd_test.go RawHistoryFolder

1package agent
2
3import (
4	"os"
5	"path/filepath"
6	"testing"
7)
8
9// TestExtInstallDotSource verifies that `zot ext install .` derives the
10// extension name from the resolved directory name rather than collapsing
11// to the extensions/ parent directory (the false "already exists" bug).
12func TestExtInstallDotSource(t *testing.T) {
13	home := t.TempDir()
14	t.Setenv("ZOT_HOME", home)
15
16	// Pre-create extensions/ to mimic a normal first run.
17	if err := os.MkdirAll(filepath.Join(home, "extensions"), 0o755); err != nil {
18		t.Fatal(err)
19	}
20
21	srcParent := t.TempDir()
22	src := filepath.Join(srcParent, "kagi")
23	if err := os.MkdirAll(src, 0o755); err != nil {
24		t.Fatal(err)
25	}
26	if err := os.WriteFile(filepath.Join(src, "extension.json"), []byte(`{"name":"kagi"}`), 0o644); err != nil {
27		t.Fatal(err)
28	}
29
30	cwd, err := os.Getwd()
31	if err != nil {
32		t.Fatal(err)
33	}
34	defer os.Chdir(cwd)
35	if err := os.Chdir(src); err != nil {
36		t.Fatal(err)
37	}
38
39	if err := extInstall([]string{"."}); err != nil {
40		t.Fatalf("install with '.' failed: %v", err)
41	}
42
43	out := filepath.Join(home, "extensions", "kagi")
44	if _, err := os.Stat(filepath.Join(out, "extension.json")); err != nil {
45		t.Fatalf("expected installed extension at %s: %v", out, err)
46	}
47}
48
49// TestExtInstallRejectsParentName guards against deriving a name of ".."
50// from a source that resolves to a filesystem root edge case. A normal
51// directory always yields a real basename, so this just ensures the
52// guard logic does not crash for well-formed input.
53func TestExtInstallNamedDir(t *testing.T) {
54	home := t.TempDir()
55	t.Setenv("ZOT_HOME", home)
56
57	src := filepath.Join(t.TempDir(), "myext")
58	if err := os.MkdirAll(src, 0o755); err != nil {
59		t.Fatal(err)
60	}
61	if err := os.WriteFile(filepath.Join(src, "extension.json"), []byte(`{"name":"myext"}`), 0o644); err != nil {
62		t.Fatal(err)
63	}
64
65	if err := extInstall([]string{src}); err != nil {
66		t.Fatalf("install failed: %v", err)
67	}
68	if _, err := os.Stat(filepath.Join(home, "extensions", "myext", "extension.json")); err != nil {
69		t.Fatalf("expected installed extension: %v", err)
70	}
71}
72
73// TestCopyDirRespectsGitignore verifies that non-portable directories
74// listed in the source .gitignore (e.g. .venv, node_modules) are not
75// copied during install, while tracked files are.
76func TestCopyDirRespectsGitignore(t *testing.T) {
77	src := t.TempDir()
78	dst := filepath.Join(t.TempDir(), "out")
79
80	mustWrite := func(rel, content string) {
81		p := filepath.Join(src, filepath.FromSlash(rel))
82		if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
83			t.Fatal(err)
84		}
85		if err := os.WriteFile(p, []byte(content), 0o644); err != nil {
86			t.Fatal(err)
87		}
88	}
89
90	mustWrite("extension.json", `{"name":"x"}`)
91	mustWrite("main.py", "print('hi')")
92	mustWrite(".gitignore", ".venv/\nnode_modules/\n*.log\n")
93	mustWrite(".venv/bin/python", "binary")
94	mustWrite("node_modules/pkg/index.js", "module")
95	mustWrite("debug.log", "noise")
96	mustWrite("src/app.py", "code")
97	mustWrite(".git/config", "gitdir")
98
99	if err := copyDir(src, dst); err != nil {
100		t.Fatal(err)
101	}
102
103	wantPresent := []string{"extension.json", "main.py", "src/app.py", ".gitignore"}
104	for _, rel := range wantPresent {
105		if _, err := os.Stat(filepath.Join(dst, filepath.FromSlash(rel))); err != nil {
106			t.Fatalf("expected %s to be copied: %v", rel, err)
107		}
108	}
109
110	wantAbsent := []string{".venv", "node_modules", "debug.log", ".git"}
111	for _, rel := range wantAbsent {
112		if _, err := os.Stat(filepath.Join(dst, filepath.FromSlash(rel))); err == nil {
113			t.Fatalf("expected %s to be skipped, but it was copied", rel)
114		}
115	}
116}
117
118func TestGitignoreNegation(t *testing.T) {
119	g := loadGitignoreFromString("build/\n!build/keep.txt\n")
120	if !g.match("build", true) {
121		t.Fatal("expected build/ dir to be ignored")
122	}
123	if g.match("build/keep.txt", false) {
124		t.Fatal("expected build/keep.txt to be re-included by negation")
125	}
126}

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