v0.27.1 131edba

budget_test.go RawHistoryFolder

1package subagents
2
3import (
4	"strings"
5	"testing"
6
7	"github.com/bnema/zut/packages/provider"
8)
9
10func TestBudgetLimitDefaultsToSeventyFivePercent(t *testing.T) {
11	limit, ratio, err := BudgetLimit(500_000, 0, 0)
12	if err != nil {
13		t.Fatal(err)
14	}
15	if limit != 375_000 || ratio != 0.75 {
16		t.Fatalf("BudgetLimit = %d, %v; want 375000, 0.75", limit, ratio)
17	}
18
19	limit, ratio, err = BudgetLimit(500_000, 0.5, 0)
20	if err != nil || limit != 250_000 || ratio != 0.5 {
21		t.Fatalf("ratio override = %d, %v, %v", limit, ratio, err)
22	}
23
24	limit, ratio, err = BudgetLimit(500_000, 0.5, 42_000)
25	if err != nil || limit != 42_000 || ratio != 0 {
26		t.Fatalf("token override = %d, %v, %v", limit, ratio, err)
27	}
28}
29
30func TestEffectiveBudgetLimitDerivesLegacyDefault(t *testing.T) {
31	if got := EffectiveBudgetLimit(0, 500_000); got != 375_000 {
32		t.Fatalf("legacy budget limit = %d, want 375000", got)
33	}
34	if got := EffectiveBudgetLimit(42_000, 500_000); got != 42_000 {
35		t.Fatalf("persisted budget limit = %d, want 42000", got)
36	}
37}
38
39func TestWeightedBudgetUsageDiscountsCacheReads(t *testing.T) {
40	usage := provider.Usage{InputTokens: 100, CacheReadTokens: 100, CacheWriteTokens: 20, OutputTokens: 30, ReasoningTokens: 10, ReasoningTokensKnown: true}
41	if got := WeightedBudgetUsage(usage); got != 175 {
42		t.Fatalf("WeightedBudgetUsage = %d, want 175", got)
43	}
44}
45
46func TestBudgetThresholdInstructionsAreProgressiveAndOneShot(t *testing.T) {
47	budget := NewRolloutBudget(1_000, provider.Usage{})
48	cases := []struct {
49		used  int
50		state BudgetState
51		text  string
52	}{
53		{500, BudgetNotice, "prioritize concrete evidence"},
54		{700, BudgetFocused, "Stop broad exploration"},
55		{850, BudgetVerifying, "Do not identify new candidates"},
56		{900, BudgetFinalizing, "Finalization is required now"},
57	}
58	for _, tc := range cases {
59		budget.Observe(provider.Usage{InputTokens: tc.used})
60		if got := budget.Snapshot().State; got != tc.state {
61			t.Fatalf("usage %d state = %q, want %q", tc.used, got, tc.state)
62		}
63		instruction, exceeded := budget.TurnContext()
64		if exceeded || !strings.Contains(instruction, tc.text) {
65			t.Fatalf("usage %d instruction = %q exceeded=%t", tc.used, instruction, exceeded)
66		}
67		if repeated, exceeded := budget.TurnContext(); repeated != "" || exceeded {
68			t.Fatalf("usage %d repeated instruction = %q exceeded=%t", tc.used, repeated, exceeded)
69		}
70	}
71
72	budget.Observe(provider.Usage{InputTokens: 1_000})
73	if instruction, exceeded := budget.TurnContext(); instruction != "" || !exceeded {
74		t.Fatalf("exhausted instruction = %q exceeded=%t", instruction, exceeded)
75	}
76}

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