detached b0db349

fix: ignore state-only extension directories during discovery

commit
b0db349cb0e01ea08ab4439cc417789fafdc62b4
author
patriceckhart · · 2026-09-15 16:16 UTC
parent
035a5cd
signature
unsigned
4 files · +89 -0
M docs/extensions.md +10 -0
@@ -822,6 +822,16 @@ name), the command reports the matching paths and makes no changes. Use a
822822 unique directory name to disambiguate where possible. `logs` uses the
823823 manifest name.
824824
825+`remove` deletes the installation directory, including state stored inside
826+it. It does not stop extensions in other running zot sessions. Close those
827+sessions before uninstalling, otherwise an extension may recreate its state
828+directory when saving or shutting down. Normal startup ignores directories
829+without `extension.json`, including state-only leftovers. It does not delete
830+that leftover data. Explicit `--ext` paths still report missing manifests,
831+and malformed or unreadable manifests still produce errors. After closing
832+active sessions, inspect and manually remove any leftover state directory
833+if needed. `ext remove` requires an installation with a manifest.
834+
825835 `zot ext doctor` runs the same discovery path as zot startup, but reports
826836 what happened instead of changing the fail-soft runtime behavior. It shows
827837 manifest errors, disabled or shadowed extensions, subprocess load errors,
@@ -822,6 +822,16 @@ name), the command reports the matching paths and makes no changes. Use a
822 unique directory name to disambiguate where possible. `logs` uses the822 unique directory name to disambiguate where possible. `logs` uses the
823 manifest name.823 manifest name.
824 824
825+`remove` deletes the installation directory, including state stored inside
826+it. It does not stop extensions in other running zot sessions. Close those
827+sessions before uninstalling, otherwise an extension may recreate its state
828+directory when saving or shutting down. Normal startup ignores directories
829+without `extension.json`, including state-only leftovers. It does not delete
830+that leftover data. Explicit `--ext` paths still report missing manifests,
831+and malformed or unreadable manifests still produce errors. After closing
832+active sessions, inspect and manually remove any leftover state directory
833+if needed. `ext remove` requires an installation with a manifest.
834+
825 `zot ext doctor` runs the same discovery path as zot startup, but reports835 `zot ext doctor` runs the same discovery path as zot startup, but reports
826 what happened instead of changing the fail-soft runtime behavior. It shows836 what happened instead of changing the fail-soft runtime behavior. It shows
827 manifest errors, disabled or shadowed extensions, subprocess load errors,837 manifest errors, disabled or shadowed extensions, subprocess load errors,
A packages/agent/extensions/discovery_orphan_test.go +69 -0
@@ -0,0 +1,69 @@
1+package extensions
2+
3+import (
4+ "context"
5+ "os"
6+ "path/filepath"
7+ "strings"
8+ "testing"
9+ "time"
10+)
11+
12+func 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+
51+func 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+
61+func 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+}
@@ -0,0 +1,69 @@
1+package extensions
2+
3+import (
4+ "context"
5+ "os"
6+ "path/filepath"
7+ "strings"
8+ "testing"
9+ "time"
10+)
11+
12+func 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+
51+func 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+
61+func 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+}
M packages/agent/extensions/manager.go +7 -0
@@ -223,6 +223,13 @@ func (m *Manager) Discover(ctx context.Context) []error {
223223 continue // missing directory is fine
224224 }
225225 for _, extDir := range extDirs {
226+ // A running extension can recreate its state directory after
227+ // uninstall. Ignore directories without a manifest before they
228+ // can shadow a valid installation in a lower-priority root.
229+ // Other errors still go through loadOne for diagnostics.
230+ if _, err := os.Stat(filepath.Join(extDir, "extension.json")); os.IsNotExist(err) {
231+ continue
232+ }
226233 name := filepath.Base(extDir)
227234 if seenDirs[name] {
228235 continue // higher-priority location already queued
@@ -223,6 +223,13 @@ func (m *Manager) Discover(ctx context.Context) []error {
223 continue // missing directory is fine223 continue // missing directory is fine
224 }224 }
225 for _, extDir := range extDirs {225 for _, extDir := range extDirs {
226+ // A running extension can recreate its state directory after
227+ // uninstall. Ignore directories without a manifest before they
228+ // can shadow a valid installation in a lower-priority root.
229+ // Other errors still go through loadOne for diagnostics.
230+ if _, err := os.Stat(filepath.Join(extDir, "extension.json")); os.IsNotExist(err) {
231+ continue
232+ }
226 name := filepath.Base(extDir)233 name := filepath.Base(extDir)
227 if seenDirs[name] {234 if seenDirs[name] {
228 continue // higher-priority location already queued235 continue // higher-priority location already queued
M packages/agent/extresolve_test.go +3 -0
@@ -38,6 +38,9 @@ func TestFindExtensionDir(t *testing.T) {
3838 if err := extToggle([]string{"todo"}, true); err != nil {
3939 t.Fatal(err)
4040 }
41+ if err := os.WriteFile(filepath.Join(dir, "state.json"), []byte(`{}`), 0o644); err != nil {
42+ t.Fatal(err)
43+ }
4144 if err := extRemove([]string{"todo", "--yes"}); err != nil {
4245 t.Fatal(err)
4346 }
@@ -38,6 +38,9 @@ func TestFindExtensionDir(t *testing.T) {
38 if err := extToggle([]string{"todo"}, true); err != nil {38 if err := extToggle([]string{"todo"}, true); err != nil {
39 t.Fatal(err)39 t.Fatal(err)
40 }40 }
41+ if err := os.WriteFile(filepath.Join(dir, "state.json"), []byte(`{}`), 0o644); err != nil {
42+ t.Fatal(err)
43+ }
41 if err := extRemove([]string{"todo", "--yes"}); err != nil {44 if err := extRemove([]string{"todo", "--yes"}); err != nil {
42 t.Fatal(err)45 t.Fatal(err)
43 }46 }

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