v0.3.70 5bef29b

agent_start_test.go RawHistoryFolder

1package core
2
3import (
4	"context"
5	"testing"
6)
7
8func TestBeforeStartLifecycle(t *testing.T) {
9	a := NewAgent(&queueFakeClient{}, "model", "base", Registry{})
10	calls, turns := 0, 0
11	a.BeforeStart = func(ctx context.Context, system string) string {
12		calls++
13		if system != "base" {
14			t.Fatalf("reapplied to modified prompt %q", system)
15		}
16		return system + "/extension"
17	}
18	a.BeforeTurn = func(int) (bool, string) {
19		turns++
20		if calls != 1 || a.System != "base/extension" {
21			t.Fatal("turn ran before preparation")
22		}
23		return true, ""
24	}
25	for range 2 {
26		if err := a.Prompt(context.Background(), "hello", nil, nil); err != nil {
27			t.Fatal(err)
28		}
29	}
30	if calls != 1 || turns != 3 {
31		t.Fatalf("calls=%d turns=%d", calls, turns)
32	}
33	a.BeforeTurn = nil
34	for _, reset := range []func(){
35		func() { a.Model = "other" },
36		func() { a.SetMessages(nil) },
37		func() { a.SessionID = "new-session" },
38		func() { a.SetSystem("base") },
39	} {
40		reset()
41		before := calls
42		if err := a.Continue(context.Background(), nil); err != nil {
43			t.Fatal(err)
44		}
45		if calls != before+1 || a.System != "base/extension" {
46			t.Fatal("reset did not reprepare from base")
47		}
48	}
49	a.BeforeStart = func(context.Context, string) string { return "" }
50	a.SetSystem("base")
51	if err := a.Continue(context.Background(), nil); err != nil {
52		t.Fatal(err)
53	}
54	if a.System != "" {
55		t.Fatal("empty replacement lost")
56	}
57}
58
59func TestBeforeStartCancellationRetriesPreparation(t *testing.T) {
60	a := NewAgent(nil, "model", "base", nil)
61	ctx, cancel := context.WithCancel(context.Background())
62	a.BeforeStart = func(context.Context, string) string { cancel(); return "modified" }
63	if err := a.Continue(ctx, nil); err != context.Canceled {
64		t.Fatalf("error=%v", err)
65	}
66	if a.System != "base" || a.startPrepared {
67		t.Fatal("canceled preparation committed")
68	}
69	a.BeforeStart = func(context.Context, string) string { return "retry" }
70	a.BeforeTurn = func(int) (bool, string) { return false, "test" }
71	if err := a.Continue(context.Background(), nil); err != nil {
72		t.Fatal(err)
73	}
74	if a.System != "retry" {
75		t.Fatal("preparation not retried")
76	}
77}

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