v0.48.1 deaab59

stream_continuation_test.go RawHistoryFolder

1package modes
2
3import (
4	"bytes"
5	"context"
6	"strings"
7	"sync/atomic"
8	"testing"
9
10	"github.com/bnema/zut/packages/core"
11	"github.com/bnema/zut/packages/provider"
12)
13
14// streamContinuationClient emits interim text with StopContinue on the
15// first call and the final answer with StopEnd on the second call.
16type streamContinuationClient struct {
17	calls int32
18}
19
20func (c *streamContinuationClient) Name() string { return "stream-continuation" }
21
22func (c *streamContinuationClient) Stream(ctx context.Context, req provider.Request) (<-chan provider.Event, error) {
23	call := atomic.AddInt32(&c.calls, 1)
24	out := make(chan provider.Event, 8)
25	go func() {
26		defer close(out)
27		text, stop := "final", provider.StopEnd
28		if call == 1 {
29			text, stop = "part one", provider.StopContinue
30		}
31		for _, chunk := range strings.Split(text, " ") {
32			select {
33			case <-ctx.Done():
34				return
35			case out <- provider.EventTextDelta{Delta: chunk + " "}:
36			}
37		}
38		select {
39		case <-ctx.Done():
40			return
41		case out <- provider.EventDone{Stop: stop, Message: provider.Message{
42			Role:    provider.RoleAssistant,
43			Content: []provider.Content{provider.TextBlock{Text: text}},
44		}}:
45		}
46	}()
47	return out, nil
48}
49
50func TestRunStreamContinuation(t *testing.T) {
51	client := &streamContinuationClient{}
52	ag := core.NewAgent(client, "test-model", "", nil)
53	var out, diag bytes.Buffer
54	if err := RunStreamWithDiag(context.Background(), ag, "hi", nil, &out, &diag); err != nil {
55		t.Fatal(err)
56	}
57	// Two inferences happened: execution did not return after the
58	// interim continuation.
59	if got := atomic.LoadInt32(&client.calls); got != 2 {
60		t.Fatalf("provider calls = %d, want 2", got)
61	}
62	got := out.String()
63	if !strings.Contains(got, "final") {
64		t.Fatalf("stdout = %q, want it to include the final answer", got)
65	}
66	if !strings.Contains(got, "part one") {
67		t.Fatalf("stdout = %q, want it to include the interim text", got)
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 476

↑↓ moveenter openesc close