v0.20.0 29be61c

resident_subagent_indicator_test.go RawHistoryFolder

1package modes
2
3import (
4	"strings"
5	"testing"
6	"time"
7
8	"github.com/bnema/zut/packages/agent/subagents"
9	"github.com/bnema/zut/packages/provider"
10	"github.com/bnema/zut/packages/tui"
11)
12
13func TestRenderResidentSubagentActivityLinesShowsOnlyActiveChildren(t *testing.T) {
14	now := time.Date(2026, time.August, 13, 12, 0, 0, 0, time.UTC)
15	lines := renderResidentSubagentActivityLines(tui.Dark, "/", []subagents.ResidentSnapshot{
16		{ID: "running-id", Profile: "reviewer", State: subagents.ResidentRunning, TurnStartedAt: now.Add(-90 * time.Second), ActivityUpdatedAt: now, WaitingForModel: true},
17		{ID: "queued-id", Profile: "planner", State: subagents.ResidentQueued, TurnStartedAt: now.Add(-10 * time.Second), ActivityUpdatedAt: now.Add(-5 * time.Second)},
18		{ID: "foreign-id", Profile: "another process", State: subagents.ResidentRunning, OwnedElsewhere: true, TurnStartedAt: now.Add(-10 * time.Second)},
19		{ID: "idle-id", Profile: "finished", State: subagents.ResidentIdle},
20	}, 80, now)
21	got := strings.Join(plainResidentIndicatorLines(lines), "\n")
22	if !strings.Contains(got, "/ reviewer · Zzzz · activity 0s ago · 1m30s") || !strings.Contains(got, "… planner · queued · activity 5s ago · 10s") {
23		t.Fatalf("activity lines = %q", got)
24	}
25	if strings.Contains(got, "finished") || strings.Contains(got, "another process") {
26		t.Fatalf("activity lines include inactive or foreign child: %q", got)
27	}
28}
29
30func TestRenderResidentSubagentActivityLinesShowsUsageMetadata(t *testing.T) {
31	now := time.Date(2026, time.August, 13, 12, 0, 0, 0, time.UTC)
32	lines := renderResidentSubagentActivityLines(tui.Dark, "/", []subagents.ResidentSnapshot{{
33		ID: "running-id", Profile: "reviewer", State: subagents.ResidentRunning,
34		Usage:       provider.Usage{InputTokens: 84_000, OutputTokens: 1_500, CacheReadTokens: 123_000, CostUSD: 0.525},
35		ContextUsed: 45_152, ContextMax: 272_000, Subscription: true,
36	}}, 100, now)
37	got := strings.Join(plainResidentIndicatorLines(lines), "\n")
38	if !strings.Contains(got, "\n    ↑84k ↓1.5k R123k/ C59.4% $0.525 (sub) 16.6%/272k") {
39		t.Fatalf("activity lines = %q, want usage metadata line", got)
40	}
41}
42
43func TestRenderResidentSubagentActivityLinesAnimatesModelWait(t *testing.T) {
44	started := time.Date(2026, time.August, 13, 12, 0, 0, 0, time.UTC)
45	now := started.Add(2 * time.Second)
46	lines := renderResidentSubagentActivityLines(tui.Dark, "/", []subagents.ResidentSnapshot{{
47		ID: "running-id", Profile: "reviewer", State: subagents.ResidentRunning,
48		TurnStartedAt: started, ActivityUpdatedAt: started, WaitingForModel: true,
49	}}, 80, now)
50	got := strings.Join(plainResidentIndicatorLines(lines), "\n")
51	if !strings.Contains(got, "zzZz") {
52		t.Fatalf("model-wait indicator = %q, want animated waiting frame", got)
53	}
54}
55
56func TestRenderResidentSubagentActivityLinesShowsRunningDuringToolWork(t *testing.T) {
57	now := time.Date(2026, time.August, 13, 12, 0, 2, 0, time.UTC)
58	lines := renderResidentSubagentActivityLines(tui.Dark, "/", []subagents.ResidentSnapshot{{
59		ID: "running-id", Profile: "reviewer", State: subagents.ResidentRunning,
60		TurnStartedAt: now.Add(-time.Minute), ActivityUpdatedAt: now.Add(-time.Second),
61	}}, 80, now)
62	got := strings.Join(plainResidentIndicatorLines(lines), "\n")
63	if !strings.Contains(got, "/ reviewer · running · activity 1s ago · 1m00s") || strings.Contains(got, "Zzzz") {
64		t.Fatalf("tool-work indicator = %q", got)
65	}
66}
67
68func TestLimitResidentSubagentActivityLinesSummarizesOverflow(t *testing.T) {
69	got := plainResidentIndicatorLines(limitResidentSubagentActivityLines(tui.Dark, []string{"one", "two", "three"}, 0, 2, 80))
70	want := []string{"one", "  … 2 more active subagents"}
71	if strings.Join(got, "\n") != strings.Join(want, "\n") {
72		t.Fatalf("limited lines = %#v, want %#v", got, want)
73	}
74}
75
76func TestLimitResidentSubagentActivityLinesKeepsMetadataWithItsAgent(t *testing.T) {
77	lines := []string{"  agent one", "    usage one", "  agent two", "    usage two"}
78	got := plainResidentIndicatorLines(limitResidentSubagentActivityLines(tui.Dark, lines, 0, 3, 80))
79	want := []string{"  agent one", "    usage one", "  … 1 more active subagents"}
80	if strings.Join(got, "\n") != strings.Join(want, "\n") {
81		t.Fatalf("limited lines = %#v, want %#v", got, want)
82	}
83}
84
85func TestLimitResidentSubagentActivityLinesIncludesAlreadyHiddenChildren(t *testing.T) {
86	got := plainResidentIndicatorLines(limitResidentSubagentActivityLines(tui.Dark, []string{"one", "two", "three"}, 4, 2, 80))
87	want := []string{"one", "  … 6 more active subagents"}
88	if strings.Join(got, "\n") != strings.Join(want, "\n") {
89		t.Fatalf("limited lines = %#v, want %#v", got, want)
90	}
91}
92
93func plainResidentIndicatorLines(lines []string) []string {
94	plain := make([]string, len(lines))
95	for index, line := range lines {
96		plain[index] = stripANSIBytes(line)
97	}
98	return plain
99}

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