v0.19.0 d7aa01a

json_activity_test.go RawHistoryFolder

1package modes
2
3import (
4	"bytes"
5	"context"
6	"encoding/json"
7	"errors"
8	"strings"
9	"testing"
10	"time"
11
12	"github.com/bnema/zut/packages/core"
13	"github.com/bnema/zut/packages/provider"
14)
15
16func TestRunJSONCompletionUserMessageIsValidJSONL(t *testing.T) {
17	message := core.EvUserMessage{Message: provider.Message{
18		Role:    provider.RoleUser,
19		Content: []provider.Content{provider.TextBlock{Text: "[auto-subagents update] worker finished"}},
20	}}
21	var line bytes.Buffer
22	if err := json.NewEncoder(&line).Encode(EventToJSON(message)); err != nil {
23		t.Fatal(err)
24	}
25	var decoded map[string]any
26	if err := json.Unmarshal(bytes.TrimSpace(line.Bytes()), &decoded); err != nil {
27		t.Fatalf("completion event is not JSON: %v", err)
28	}
29	if decoded["type"] != "user_message" {
30		t.Fatalf("event type = %#v, want user_message", decoded["type"])
31	}
32}
33
34type failingJSONWriter struct{ err error }
35
36func (w failingJSONWriter) Write([]byte) (int, error) { return 0, w.err }
37
38func TestRunJSONPropagatesOutputErrors(t *testing.T) {
39	providerErr := errors.New("provider unavailable")
40	writerErr := errors.New("stdout unavailable")
41	ag := core.NewAgent(&streamTestClient{err: providerErr}, "test-model", "", nil)
42	_, err := RunJSONWithContextRecovery(context.Background(), ag, "hello", nil, failingJSONWriter{err: writerErr}, nil)
43	if !errors.Is(err, providerErr) || !errors.Is(err, writerErr) {
44		t.Fatalf("RunJSONWithContextRecovery error = %v, want provider and output errors", err)
45	}
46}
47
48func TestRunJSONFailureEmitsOneErrorObject(t *testing.T) {
49	client := &streamTestClient{err: errors.New("provider unavailable")}
50	ag := core.NewAgent(client, "test-model", "", nil)
51	var out bytes.Buffer
52	_, err := RunJSONWithContextRecovery(context.Background(), ag, "hello", nil, &out, nil)
53	if err == nil {
54		t.Fatal("RunJSONWithContextRecovery unexpectedly succeeded")
55	}
56	lines := strings.Split(strings.TrimSpace(out.String()), "\n")
57	errorObjects := 0
58	for _, line := range lines {
59		var decoded map[string]any
60		if err := json.Unmarshal([]byte(line), &decoded); err != nil {
61			t.Fatalf("invalid JSONL line %q: %v", line, err)
62		}
63		if decoded["type"] == "error" {
64			errorObjects++
65		}
66	}
67	if errorObjects != 1 {
68		t.Fatalf("error objects = %d, want one; output=%q", errorObjects, out.String())
69	}
70}
71
72func TestEventToJSONActivityLifecycle(t *testing.T) {
73	request := EventToJSON(core.EvRequestStarted{
74		Provider:    "anthropic",
75		Model:       "claude-test",
76		Scope:       core.RetryScopeProvider,
77		Attempt:     2,
78		MaxAttempts: 3,
79	})
80	if got, want := request["type"], "request_started"; got != want {
81		t.Fatalf("type = %q, want %q", got, want)
82	}
83	for key, want := range map[string]any{
84		"provider":     "anthropic",
85		"model":        "claude-test",
86		"scope":        "provider",
87		"attempt":      2,
88		"max_attempts": 3,
89	} {
90		if got := request[key]; got != want {
91			t.Errorf("request[%q] = %#v, want %#v", key, got, want)
92		}
93	}
94
95	retry := EventToJSON(core.EvRetryScheduled{
96		Scope: core.RetryScopeAgent, Attempt: 2, MaxAttempts: 4, Delay: 1500 * time.Millisecond,
97	})
98	if got, want := retry["delay_ms"], int64(1500); got != want {
99		t.Fatalf("delay_ms = %#v, want %#v", got, want)
100	}
101	if _, exists := retry["delay"]; exists {
102		t.Fatal("retry event must not serialize a duration")
103	}
104
105	tool := EventToJSON(core.EvToolExecutionStarted{ID: "call-1", Name: "read"})
106	if got, want := tool["type"], "tool_execution_started"; got != want {
107		t.Fatalf("type = %q, want %q", got, want)
108	}
109	if tool["id"] != "call-1" || tool["name"] != "read" {
110		t.Fatalf("tool event = %#v", tool)
111	}
112}

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