v0.3.69 6abb410

session_prune_test.go RawHistoryFolder

1package core
2
3import (
4	"os"
5	"path/filepath"
6	"testing"
7
8	"github.com/patriceckhart/zot/packages/provider"
9)
10
11func TestScanStoredSessionGroupsIncludesDefaultAndAgentSessions(t *testing.T) {
12	home := t.TempDir()
13	cwdA := filepath.Join(home, "missing-a")
14	cwdB := filepath.Join(home, "missing-b")
15
16	create := func(root, cwd, text string) string {
17		t.Helper()
18		session, err := NewSession(root, cwd, "test", "test-model", "test-version")
19		if err != nil {
20			t.Fatal(err)
21		}
22		if err := session.AppendMessage(provider.Message{
23			Role:    provider.RoleUser,
24			Content: []provider.Content{provider.TextBlock{Text: text}},
25		}); err != nil {
26			t.Fatal(err)
27		}
28		if err := session.Close(); err != nil {
29			t.Fatal(err)
30		}
31		return session.Path
32	}
33
34	first := create(home, cwdA, "one")
35	second := create(home, cwdA, "two")
36	agentRoot := filepath.Join(home, "sessions", "agents", "reviewer")
37	third := create(agentRoot, cwdA, "agent")
38	_ = create(home, cwdB, "other")
39	bad := filepath.Join(home, "sessions", "bad.jsonl")
40	if err := os.WriteFile(bad, []byte("not json\n"), 0o600); err != nil {
41		t.Fatal(err)
42	}
43
44	groups, issues := ScanStoredSessionGroups(filepath.Join(home, "sessions"))
45	if len(groups) != 2 {
46		t.Fatalf("groups = %#v, want 2", groups)
47	}
48	if groups[0].CWD != cwdA || len(groups[0].Paths) != 3 {
49		t.Fatalf("first group = %#v, want three sessions for %q", groups[0], cwdA)
50	}
51	for _, want := range []string{first, second, third} {
52		if !pruneTestContainsString(groups[0].Paths, want) {
53			t.Errorf("group paths %q do not contain %q", groups[0].Paths, want)
54		}
55	}
56	if groups[0].SizeBytes <= 0 {
57		t.Fatalf("group summary missing size: %#v", groups[0])
58	}
59	if groups[1].CWD != cwdB || len(groups[1].Paths) != 1 {
60		t.Fatalf("second group = %#v", groups[1])
61	}
62	if len(issues) != 1 || issues[0].Path != bad {
63		t.Fatalf("issues = %#v, want malformed session issue", issues)
64	}
65}
66
67func TestScanStoredSessionGroupsMissingRootIsEmpty(t *testing.T) {
68	groups, issues := ScanStoredSessionGroups(filepath.Join(t.TempDir(), "missing"))
69	if len(groups) != 0 || len(issues) != 0 {
70		t.Fatalf("groups = %#v, issues = %#v, want empty", groups, issues)
71	}
72}
73
74func pruneTestContainsString(values []string, want string) bool {
75	for _, value := range values {
76		if value == want {
77			return true
78		}
79	}
80	return false
81}

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