main 4509ec7

session_freshness_test.go RawHistoryFolder

1package agent
2
3import (
4	"context"
5	"path/filepath"
6	"testing"
7
8	"github.com/bnema/zut/packages/core"
9	"github.com/bnema/zut/packages/provider"
10)
11
12func TestOpenOrCreateSessionStateFreshness(t *testing.T) {
13	for _, name := range []string{"new", "no-session", "new-explicit", "existing-explicit", "continue-existing", "resume-id", "continue-missing"} {
14		t.Run(name, func(t *testing.T) {
15			home, cwd := t.TempDir(), t.TempDir()
16			t.Setenv("ZUT_HOME", home)
17			args := Args{CWD: cwd}
18			resolved := Resolved{CWD: cwd, Provider: "test-provider", Model: "test-model"}
19			wantFresh := true
20			switch name {
21			case "no-session":
22				args.NoSess = true
23			case "new-explicit":
24				args.Session = filepath.Join(home, "explicit.jsonl")
25			case "existing-explicit", "continue-existing", "resume-id":
26				old, err := core.NewSession(home, cwd, resolved.Provider, resolved.Model, "test")
27				if err != nil {
28					t.Fatal(err)
29				}
30				if name != "existing-explicit" {
31					if err := old.AppendMessage(provider.Message{Role: provider.RoleUser, Content: []provider.Content{provider.TextBlock{Text: "saved prompt"}}}); err != nil {
32						t.Fatal(err)
33					}
34				}
35				path, id := old.Path, old.ID
36				if name == "existing-explicit" {
37					// Keep the empty session open so its valid header remains;
38					// restoration is not inferred from message count.
39					t.Cleanup(func() { _ = old.Close() })
40					args.Session = path
41				} else {
42					if err := old.Close(); err != nil {
43						t.Fatal(err)
44					}
45					if name == "continue-existing" {
46						args.Continue = true
47					} else {
48						args.Resume, args.ResumeSessionID = true, id
49					}
50				}
51				wantFresh = false
52			case "continue-missing":
53				args.Continue = true
54			}
55			ag := core.NewAgent(nil, resolved.Model, "system", core.Registry{})
56			sess, fresh, err := openOrCreateSessionState(context.Background(), args, resolved, ag, "test")
57			if err != nil {
58				t.Fatal(err)
59			}
60			if sess != nil {
61				defer sess.Close()
62			}
63			if fresh != wantFresh {
64				t.Fatalf("fresh=%v, want %v", fresh, wantFresh)
65			}
66			if args.NoSess && sess != nil {
67				t.Fatal("session created with persistence disabled")
68			}
69		})
70	}
71}

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