v0.1.58 25a4caf

manager_test.go RawHistoryFolder

1package extensions
2
3import (
4	"context"
5	"encoding/json"
6	"os"
7
8	"github.com/patriceckhart/zot/internal/extproto"
9	"path/filepath"
10	"runtime"
11	"sync"
12	"testing"
13	"time"
14)
15
16// stubHooks records every callback so the test can assert on them.
17type stubHooks struct {
18	mu       sync.Mutex
19	notifies []string
20	displays []string
21}
22
23func (s *stubHooks) Notify(name, level, message string) {
24	s.mu.Lock()
25	defer s.mu.Unlock()
26	s.notifies = append(s.notifies, name+":"+level+":"+message)
27}
28func (s *stubHooks) Submit(string) {}
29func (s *stubHooks) Insert(string) {}
30func (s *stubHooks) Display(name, text string) {
31	s.mu.Lock()
32	defer s.mu.Unlock()
33	s.displays = append(s.displays, name+":"+text)
34}
35func (s *stubHooks) OpenPanel(string, extproto.PanelSpec)                 {}
36func (s *stubHooks) UpdatePanel(string, string, string, []string, string) {}
37func (s *stubHooks) ClosePanel(string, string)                            {}
38
39// writeMockExtension creates a minimal extension on disk that uses a
40// shell script (or batch file on windows) to drive the protocol. The
41// script reads commands from stdin and emits hard-coded responses,
42// exercising the manager's spawn/handshake/dispatch path without
43// needing the SDK.
44func writeMockExtension(t *testing.T, root string) {
45	t.Helper()
46	if runtime.GOOS == "windows" {
47		t.Skip("mock extension uses /bin/sh; skip on windows")
48	}
49
50	dir := filepath.Join(root, "mock")
51	if err := os.MkdirAll(dir, 0o755); err != nil {
52		t.Fatal(err)
53	}
54
55	// Shell script: emit hello, read frames, respond. Reads until
56	// stdin closes; tail's -F keeps the pipe alive long enough for
57	// the manager to send command_invoked.
58	script := `#!/bin/sh
59printf '%s\n' '{"type":"hello","name":"mock","version":"0.0.1","capabilities":["commands"]}'
60printf '%s\n' '{"type":"register_command","name":"ping","description":"ping/pong"}'
61while IFS= read -r line; do
62  case "$line" in
63    *'"type":"command_invoked"'*)
64      id=$(printf '%s' "$line" | sed -n 's/.*"id":"\([^"]*\)".*/\1/p')
65      printf '%s\n' "{\"type\":\"command_response\",\"id\":\"$id\",\"action\":\"display\",\"display\":\"pong\"}"
66      ;;
67    *'"type":"shutdown"'*)
68      printf '%s\n' '{"type":"shutdown_ack"}'
69      exit 0
70      ;;
71  esac
72done
73`
74	scriptPath := filepath.Join(dir, "run.sh")
75	if err := os.WriteFile(scriptPath, []byte(script), 0o755); err != nil {
76		t.Fatal(err)
77	}
78
79	manifest := map[string]any{
80		"name":    "mock",
81		"version": "0.0.1",
82		"exec":    "./run.sh",
83	}
84	mfb, _ := json.Marshal(manifest)
85	if err := os.WriteFile(filepath.Join(dir, "extension.json"), mfb, 0o644); err != nil {
86		t.Fatal(err)
87	}
88}
89
90func TestManagerSpawnAndInvoke(t *testing.T) {
91	tmp := t.TempDir()
92	extRoot := filepath.Join(tmp, "extensions")
93	if err := os.MkdirAll(extRoot, 0o755); err != nil {
94		t.Fatal(err)
95	}
96	writeMockExtension(t, extRoot)
97
98	hooks := &stubHooks{}
99	mgr := New(tmp, "", "0.0.0-test", "anthropic", "claude-opus-4-7", hooks)
100
101	if errs := mgr.Discover(context.Background()); len(errs) > 0 {
102		t.Fatalf("discover errors: %v", errs)
103	}
104	defer mgr.Stop(2 * time.Second)
105
106	// Give the extension a beat to send register_command frames after
107	// the hello handshake.
108	time.Sleep(150 * time.Millisecond)
109
110	cmds := mgr.Commands()
111	if len(cmds) != 1 || cmds[0].Name != "ping" {
112		t.Fatalf("expected one command 'ping', got %#v", cmds)
113	}
114	if !mgr.HasCommand("ping") {
115		t.Fatal("HasCommand(\"ping\") = false")
116	}
117
118	resp, err := mgr.Invoke(context.Background(), "ping", "", 2*time.Second)
119	if err != nil {
120		t.Fatalf("invoke: %v", err)
121	}
122	if resp.Action != "display" {
123		t.Errorf("expected action=display, got %q", resp.Action)
124	}
125	if resp.Display != "pong" {
126		t.Errorf("expected display=pong, got %q", resp.Display)
127	}
128}

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