v0.1.58 25a4caf

tool_test.go RawHistoryFolder

1package extensions
2
3import (
4	"context"
5	"encoding/json"
6	"os"
7	"path/filepath"
8	"runtime"
9	"testing"
10	"time"
11)
12
13func writeMockToolExtension(t *testing.T, root string) {
14	t.Helper()
15	if runtime.GOOS == "windows" {
16		t.Skip("mock uses /bin/sh; skip on windows")
17	}
18	dir := filepath.Join(root, "tool-mock")
19	if err := os.MkdirAll(dir, 0o755); err != nil {
20		t.Fatal(err)
21	}
22
23	// Shell-script extension: hello, register one tool, ready, then
24	// loop on stdin echoing back tool_call args as tool_result text.
25	script := `#!/bin/sh
26printf '%s\n' '{"type":"hello","name":"tool-mock","version":"0.1","capabilities":["tools"]}'
27printf '%s\n' '{"type":"register_tool","name":"echo","description":"echo back the args","schema":{"type":"object","properties":{"msg":{"type":"string"}}}}'
28printf '%s\n' '{"type":"ready"}'
29while IFS= read -r line; do
30  case "$line" in
31    *'"type":"tool_call"'*)
32      id=$(printf '%s' "$line" | sed -n 's/.*"id":"\([^"]*\)".*/\1/p')
33      printf '%s\n' "{\"type\":\"tool_result\",\"id\":\"$id\",\"content\":[{\"type\":\"text\",\"text\":\"echoed\"}]}"
34      ;;
35    *'"type":"shutdown"'*)
36      printf '%s\n' '{"type":"shutdown_ack"}'
37      exit 0
38      ;;
39  esac
40done
41`
42	if err := os.WriteFile(filepath.Join(dir, "run.sh"), []byte(script), 0o755); err != nil {
43		t.Fatal(err)
44	}
45	mfb, _ := json.Marshal(map[string]any{"name": "tool-mock", "exec": "./run.sh"})
46	if err := os.WriteFile(filepath.Join(dir, "extension.json"), mfb, 0o644); err != nil {
47		t.Fatal(err)
48	}
49}
50
51func TestManagerToolRegistrationAndInvoke(t *testing.T) {
52	tmp := t.TempDir()
53	writeMockToolExtension(t, filepath.Join(tmp, "extensions"))
54
55	mgr := New(tmp, "", "0.0.0", "anthropic", "opus", &stubHooks{})
56	if errs := mgr.Discover(context.Background()); len(errs) > 0 {
57		t.Fatalf("discover errs: %v", errs)
58	}
59	defer mgr.Stop(2 * time.Second)
60
61	// Wait for ready (the script sends it right after register_tool).
62	mgr.WaitForReady(time.Second)
63
64	tools := mgr.Tools()
65	if len(tools) != 1 || tools[0].Name != "echo" {
66		t.Fatalf("expected one tool 'echo', got %#v", tools)
67	}
68	if !mgr.HasTool("echo") {
69		t.Fatal("HasTool(\"echo\") = false")
70	}
71
72	resp, err := mgr.InvokeTool(context.Background(), "echo", json.RawMessage(`{"msg":"hi"}`), 2*time.Second)
73	if err != nil {
74		t.Fatalf("invoke: %v", err)
75	}
76	if resp.IsError {
77		t.Errorf("expected success, got is_error=true")
78	}
79	if len(resp.Content) != 1 || resp.Content[0].Type != "text" || resp.Content[0].Text != "echoed" {
80		t.Errorf("unexpected content: %#v", resp.Content)
81	}
82}

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