v0.19.0 d7aa01a

resident_projection_test.go RawHistoryFolder

1package subagents
2
3import (
4	"encoding/json"
5	"strings"
6	"testing"
7
8	"github.com/bnema/zut/packages/core"
9	"github.com/bnema/zut/packages/provider"
10)
11
12func TestResidentLiveProjectionPublishesCopiesAndFinalizesLiveItems(t *testing.T) {
13	projection := newResidentLiveProjection()
14	projection.Start("turn-1")
15	projection.Apply(core.EvTextDelta{Delta: "draft"})
16	projection.Apply(core.EvToolUseStart{ID: "call-1", Name: "bash"})
17	projection.Apply(core.EvToolUseArgs{ID: "call-1", Delta: `{"command":"pwd"}`})
18	projection.Apply(core.EvToolExecutionStarted{ID: "call-1", Name: "bash"})
19
20	live := projection.Snapshot()
21	if live.TurnID != "turn-1" || live.State != ResidentRunning || live.AssistantText != "draft" || len(live.Tools) != 1 || live.Tools[0].State != ResidentLiveToolRunning || string(live.Tools[0].Args) != `{"command":"pwd"}` || live.Revision == 0 {
22		t.Fatalf("live projection = %#v", live)
23	}
24	live.Tools[0].Args[0] = 'x'
25	if got := projection.Snapshot(); string(got.Tools[0].Args) != `{"command":"pwd"}` {
26		t.Fatalf("snapshot mutated projection: %#v", got)
27	}
28
29	projection.Apply(core.EvToolResult{ID: "call-1", Result: core.ToolResult{Content: []provider.Content{provider.TextBlock{Text: "done"}}}})
30	projection.Apply(core.EvRequestStarted{})
31	if !projection.Snapshot().WaitingForModel {
32		t.Fatal("provider request did not mark the resident as waiting for the model")
33	}
34	projection.Apply(core.EvAssistantMessage{Message: provider.Message{Role: provider.RoleAssistant, Content: []provider.Content{provider.TextBlock{Text: "final"}}}})
35	projection.Finish(ResidentIdle)
36	final := projection.Snapshot()
37	if final.AssistantText != "" || len(final.Tools) != 0 || final.State != ResidentIdle || final.Revision <= live.Revision {
38		t.Fatalf("final projection = %#v", final)
39	}
40}
41
42func TestResidentLiveProjectionPreservesContextAcrossZeroUsage(t *testing.T) {
43	projection := newResidentLiveProjection()
44	usage := provider.Usage{InputTokens: 84_000, CacheReadTokens: 123_000}
45	projection.Apply(core.EvUsage{Usage: usage, Cumulative: usage})
46	projection.Apply(core.EvUsage{Usage: provider.Usage{}, Cumulative: usage})
47	got := projection.Snapshot()
48	if got.Usage != usage || got.ContextUsed != 207_000 {
49		t.Fatalf("live usage = %#v, context = %d; want cumulative usage and preserved context", got.Usage, got.ContextUsed)
50	}
51}
52
53func TestResidentLiveProjectionBoundsToolArguments(t *testing.T) {
54	projection := newResidentLiveProjection()
55	projection.Start("turn-1")
56	projection.Apply(core.EvToolCall{ID: "call-1", Name: "bash", Args: json.RawMessage(`{"command":"pwd"}`)})
57	if got := projection.Snapshot(); len(got.Tools) != 1 || string(got.Tools[0].Args) != `{"command":"pwd"}` {
58		t.Fatalf("live tool = %#v", got)
59	}
60	projection.Apply(core.EvToolCall{ID: "call-2", Name: "bash", Args: json.RawMessage(strings.Repeat("a", residentLiveArgumentBytes+1024))})
61	if got := projection.Snapshot(); len(got.Tools) != 2 || len(got.Tools[1].Args) != residentLiveArgumentBytes {
62		t.Fatalf("oversized tool args = %d bytes", len(got.Tools[1].Args))
63	}
64}

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 477

↑↓ moveenter openesc close