v0.3.78 aed6edb

extresolve_test.go RawHistoryFolder

1package agent
2
3import (
4	"os"
5	"path/filepath"
6	"strings"
7	"testing"
8)
9
10func TestFindExtensionDir(t *testing.T) {
11	for _, scope := range []string{"global", "project"} {
12		t.Run(scope, func(t *testing.T) {
13			home := t.TempDir()
14			project := t.TempDir()
15			t.Setenv("ZOT_HOME", home)
16			t.Chdir(project)
17			root := filepath.Join(home, "extensions")
18			if scope == "project" {
19				root = filepath.Join(project, ".zot", "extensions")
20			}
21			dir := writeResolverExtension(t, root, "zot-todo", `{"name":"todo"}`)
22			for _, name := range []string{"todo", "zot-todo"} {
23				got, err := findExtensionDir(name)
24				if err != nil || got != dir {
25					t.Fatalf("findExtensionDir(%q) = %q, %v, want %q", name, got, err, dir)
26				}
27			}
28			if _, err := findExtensionDir("missing"); err == nil {
29				t.Fatal("expected missing extension error")
30			}
31			if err := extToggle([]string{"todo"}, false); err != nil {
32				t.Fatal(err)
33			}
34			raw, err := os.ReadFile(filepath.Join(dir, "extension.json"))
35			if err != nil || !strings.Contains(string(raw), `"enabled": false`) {
36				t.Fatalf("disable did not update manifest: %s, %v", raw, err)
37			}
38			if err := extToggle([]string{"todo"}, true); err != nil {
39				t.Fatal(err)
40			}
41			if err := os.WriteFile(filepath.Join(dir, "state.json"), []byte(`{}`), 0o644); err != nil {
42				t.Fatal(err)
43			}
44			if err := extRemove([]string{"todo", "--yes"}); err != nil {
45				t.Fatal(err)
46			}
47			if _, err := os.Stat(dir); !os.IsNotExist(err) {
48				t.Fatalf("extension was not removed: %v", err)
49			}
50		})
51	}
52}
53
54func TestFindExtensionDirAmbiguous(t *testing.T) {
55	for _, collision := range []string{"manifest", "directory", "cross-scope"} {
56		t.Run(collision, func(t *testing.T) {
57			home := t.TempDir()
58			project := t.TempDir()
59			t.Setenv("ZOT_HOME", home)
60			t.Chdir(project)
61			root := filepath.Join(home, "extensions")
62			first := writeResolverExtension(t, root, "zot-todo", `{"name":"todo"}`)
63			secondName := "other-todo"
64			if collision == "directory" {
65				secondName = "todo"
66			}
67			if collision == "cross-scope" {
68				root = filepath.Join(project, ".zot", "extensions")
69				secondName = "zot-todo"
70			}
71			second := writeResolverExtension(t, root, secondName, `{"name":"todo"}`)
72			if err := extRemove([]string{"todo", "--yes"}); err == nil || !strings.Contains(err.Error(), "ambiguous") {
73				t.Fatalf("expected ambiguity error, got %v", err)
74			}
75			for _, dir := range []string{first, second} {
76				if _, err := os.Stat(dir); err != nil {
77					t.Fatalf("ambiguous removal modified %s: %v", dir, err)
78				}
79			}
80		})
81	}
82}
83
84func TestFindExtensionDirRejectsTraversal(t *testing.T) {
85	home := t.TempDir()
86	t.Setenv("ZOT_HOME", home)
87	t.Chdir(t.TempDir())
88	writeResolverExtension(t, home, "outside", `{"name":"outside"}`)
89	if _, err := findExtensionDir("../outside"); err == nil {
90		t.Fatal("resolved directory outside extension roots")
91	}
92}
93
94func writeResolverExtension(t *testing.T, root, dir, manifest string) string {
95	t.Helper()
96	path := filepath.Join(root, dir)
97	if err := os.MkdirAll(path, 0o755); err != nil {
98		t.Fatal(err)
99	}
100	if err := os.WriteFile(filepath.Join(path, "extension.json"), []byte(manifest), 0o644); err != nil {
101		t.Fatal(err)
102	}
103	return path
104}

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