v0.4.4 e5506c1

session_environment_test.go RawHistoryFolder

1package agent
2
3import (
4	"os"
5	"path/filepath"
6	"testing"
7
8	"github.com/patriceckhart/zot/packages/core"
9)
10
11func isolateSessionEnvironment(t *testing.T) {
12	t.Helper()
13	for _, name := range []string{"ZOT_SESSION_ID", "ZOT_SESSION_FILE", "ZOT_PROVIDER", "ZOT_MODEL", "ZOT_REASONING_LEVEL"} {
14		t.Setenv(name, "inherited")
15	}
16}
17
18func assertSessionEnvironment(t *testing.T, r Resolved, sess *core.Session) {
19	t.Helper()
20	want := map[string]string{
21		"ZOT_SESSION_ID": "", "ZOT_SESSION_FILE": "",
22		"ZOT_PROVIDER": r.Provider, "ZOT_MODEL": r.Model, "ZOT_REASONING_LEVEL": r.Reasoning,
23	}
24	if sess != nil {
25		want["ZOT_SESSION_ID"] = sess.ID
26		want["ZOT_SESSION_FILE"] = sess.Path
27	}
28	for name, value := range want {
29		got, present := os.LookupEnv(name)
30		if got != value || present != (value != "") {
31			t.Errorf("%s = %q (present=%v), want %q (present=%v)", name, got, present, value, value != "")
32		}
33	}
34}
35
36func TestOpenSessionWithoutPersistencePublishesModelEnvironment(t *testing.T) {
37	isolateSessionEnvironment(t)
38	r := Resolved{Provider: "test-provider", Model: "test-model", Reasoning: "high"}
39	sess, err := openOrCreateSession(Args{NoSess: true}, r, nil, "test")
40	if err != nil || sess != nil {
41		t.Fatalf("openOrCreateSession = %v, %v; want nil, nil", sess, err)
42	}
43	assertSessionEnvironment(t, r, nil)
44}
45
46func TestSessionEnvironmentReplacesSessionAndClearsReasoning(t *testing.T) {
47	isolateSessionEnvironment(t)
48	r := Resolved{Provider: "old-provider", Model: "old-model", Reasoning: "high"}
49	oldSession := &core.Session{ID: "old", Path: filepath.Join(t.TempDir(), "old.jsonl")}
50	setZotSessionEnvironment(r, oldSession)
51	assertSessionEnvironment(t, r, oldSession)
52
53	// A directory change replaces the session and may rebuild a different model.
54	r.Provider, r.Model, r.Reasoning = "new-provider", "new-model", "medium"
55	newSession := &core.Session{ID: "new", Path: filepath.Join(t.TempDir(), "new.jsonl")}
56	setZotSessionEnvironment(r, newSession)
57	assertSessionEnvironment(t, r, newSession)
58
59	r.Reasoning = ""
60	setZotSessionEnvironment(r, newSession)
61	assertSessionEnvironment(t, r, newSession)
62
63	setZotSessionEnvironment(r, nil)
64	assertSessionEnvironment(t, r, nil)
65}

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