v0.4.11 e5c9e04

discovery_orphan_test.go RawHistoryFolder

1package extensions
2
3import (
4	"context"
5	"os"
6	"path/filepath"
7	"strings"
8	"testing"
9	"time"
10)
11
12func TestDiscoverIgnoresStateOnlyDirectories(t *testing.T) {
13	for _, globalInstalled := range []bool{false, true} {
14		name := "orphan-only"
15		if globalInstalled {
16			name = "orphan-does-not-shadow-global"
17		}
18		t.Run(name, func(t *testing.T) {
19			home := t.TempDir()
20			project := t.TempDir()
21			orphan := filepath.Join(project, ".zot", "extensions", "zot-loop")
22			writeDiscoveryFile(t, orphan, "state.json", `{}`)
23			global := filepath.Join(home, "extensions", "zot-loop")
24			if globalInstalled {
25				writeDiscoveryFile(t, global, "extension.json", `{"name":"loop"}`)
26				writeDiscoveryFile(t, global, "theme.json", `{"name":"Loop Theme","colors":{"dark":{"accent":204}}}`)
27			} else {
28				writeDiscoveryFile(t, filepath.Join(home, "extensions", "other-orphan"), "state.json", `{}`)
29			}
30			mgr := New(home, project, "test", "", "", nil)
31			t.Cleanup(func() { mgr.Stop(time.Second) })
32			if errs := mgr.Discover(context.Background()); len(errs) != 0 {
33				t.Fatalf("discover errors: %v", errs)
34			}
35			if globalInstalled {
36				opts := mgr.ThemeOptions()
37				if len(opts) != 1 || opts[0].Path != filepath.Join(global, "theme.json") {
38					t.Fatalf("global extension was shadowed: %#v", opts)
39				}
40			}
41			if _, err := os.Stat(filepath.Join(orphan, "state.json")); err != nil {
42				t.Fatalf("discovery must not delete leftover state: %v", err)
43			}
44			if errs := mgr.LoadExplicit(context.Background(), []string{orphan}); len(errs) != 1 || !strings.Contains(errs[0].Error(), "extension.json") {
45				t.Fatalf("explicit missing manifest errors: %v", errs)
46			}
47		})
48	}
49}
50
51func TestDiscoverStillReportsMalformedManifest(t *testing.T) {
52	home := t.TempDir()
53	writeDiscoveryFile(t, filepath.Join(home, "extensions", "broken"), "extension.json", `{`)
54	mgr := New(home, "", "test", "", "", nil)
55	t.Cleanup(func() { mgr.Stop(time.Second) })
56	if errs := mgr.Discover(context.Background()); len(errs) != 1 || !strings.Contains(errs[0].Error(), "parse manifest") {
57		t.Fatalf("malformed manifest errors: %v", errs)
58	}
59}
60
61func writeDiscoveryFile(t *testing.T, dir, name, content string) {
62	t.Helper()
63	if err := os.MkdirAll(dir, 0o755); err != nil {
64		t.Fatal(err)
65	}
66	if err := os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644); err != nil {
67		t.Fatal(err)
68	}
69}

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