@@ -78,6 +78,40 @@ func TestNoStatLineWhileStreaming(t *testing.T) {
7878 }
7979}
8080
81+ // TestGaugeFollowsTurnFill is a regression test: the header gauge must track
82+ // the last turn's contextTokens (the live window fill, which drops after odek
83+ // trims history), not sessionContextTokens, which is cumulative and only grows.
84+ func TestGaugeFollowsTurnFill (t * testing.T ) {
85+ m := driveTurn (t , client.Event {
86+ Type : "done" , Latency : 1 ,
87+ ContextTokens : 900 , OutputTokens : 100 ,
88+ SessionContextTokens : 50000 , SessionOutputTokens : 300 ,
89+ })
90+ m .model = "big"
91+ m .models = []client.ModelInfo {{ID : "big" , MaxContext : 1000 }}
92+ m .resolveMaxContext ()
93+ if out := plain (m .header ()); ! strings .Contains (out , "90%" ) {
94+ t .Errorf ("gauge should reflect the turn fill (90%%), got:\n %s" , out )
95+ }
96+
97+ // Next turn comes back smaller after a history trim — the gauge drops,
98+ // even though the cumulative session total kept growing.
99+ m .msgs = append (m .msgs , message {role : roleAsst , streaming : true })
100+ m .curIdx = len (m .msgs ) - 1
101+ m .busy = true
102+ m .handleEvent (client.Event {
103+ Type : "done" , Latency : 1 ,
104+ ContextTokens : 300 , OutputTokens : 100 ,
105+ SessionContextTokens : 51200 , SessionOutputTokens : 400 ,
106+ })
107+ if m .winCtxTok != 300 {
108+ t .Fatalf ("winCtxTok = %d, want 300" , m .winCtxTok )
109+ }
110+ if out := plain (m .header ()); ! strings .Contains (out , "30%" ) {
111+ t .Errorf ("gauge should drop after a trim (30%%), got:\n %s" , out )
112+ }
113+ }
114+
81115func TestContextGauge (t * testing.T ) {
82116 m := newTestModel ()
83117 m .model = "big"
@@ -87,6 +121,7 @@ func TestContextGauge(t *testing.T) {
87121 t .Fatalf ("maxContext = %d, want 1000" , m .maxContext )
88122 }
89123 m .sessCtxTok = 380
124+ m .winCtxTok = 380
90125
91126 out := plain (m .header ())
92127 for _ , want := range []string {"○" , "38%" , "380/1k" } {
0 commit comments