55 "errors"
66 "strings"
77 "testing"
8+ "time"
89)
910
1011func TestRenderer_Start (t * testing.T ) {
@@ -43,7 +44,7 @@ func TestRenderer_Iteration(t *testing.T) {
4344 var buf bytes.Buffer
4445 r := New (& buf , true ).WithModel ("deepseek-chat" )
4546
46- r .Iteration (3 , 90 )
47+ r .Iteration (3 , 90 , 0 , 0 , 0 )
4748
4849 out := buf .String ()
4950 if ! strings .Contains (out , "Iter 3/90" ) {
@@ -58,7 +59,7 @@ func TestRenderer_Iteration_NoModel(t *testing.T) {
5859 var buf bytes.Buffer
5960 r := New (& buf , true )
6061
61- r .Iteration (1 , 10 )
62+ r .Iteration (1 , 10 , 0 , 0 , 0 )
6263
6364 out := buf .String ()
6465 if ! strings .Contains (out , "Iter 1/10" ) {
@@ -260,7 +261,7 @@ func TestRenderer_NoColor(t *testing.T) {
260261 var buf bytes.Buffer
261262 r := New (& buf , false )
262263
263- r .Iteration (1 , 5 )
264+ r .Iteration (1 , 5 , 0 , 0 , 0 )
264265
265266 out := buf .String ()
266267 if strings .Contains (out , "\033 [" ) {
@@ -276,7 +277,7 @@ func TestRenderer_NilWriter(t *testing.T) {
276277
277278 // None of these should panic
278279 r .Start ("task" )
279- r .Iteration (1 , 5 )
280+ r .Iteration (1 , 5 , 0 , 0 , 0 )
280281 r .Thinking ("hello" )
281282 r .ToolCall ("shell" , "{}" )
282283 r .ToolResult ("output" )
@@ -289,7 +290,7 @@ func TestRenderer_NilRenderer(t *testing.T) {
289290
290291 // None of these should panic on nil receiver
291292 r .Start ("task" )
292- r .Iteration (1 , 5 )
293+ r .Iteration (1 , 5 , 0 , 0 , 0 )
293294 r .Thinking ("hello" )
294295 r .ToolCall ("shell" , "{}" )
295296 r .ToolResult ("output" )
@@ -303,11 +304,11 @@ func TestRenderer_FullCycle(t *testing.T) {
303304
304305 // Simulate one full session
305306 r .Start ("what files are here?" )
306- r .Iteration (1 , 90 )
307+ r .Iteration (1 , 90 , 0 , 0 , 0 )
307308 r .Thinking ("I need to read the file to understand its contents." )
308309 r .ToolCall ("shell" , `{"command": "cat main.go"}` )
309310 r .ToolResult ("package main\n \n import \" fmt\" \n \n func main() {\n \t fmt.Println(\" hello\" )\n }" )
310- r .Iteration (2 , 90 )
311+ r .Iteration (2 , 90 , 0 , 0 , 0 )
311312 r .FinalAnswer ("The file contains a simple Go program that prints 'hello'." )
312313
313314 out := buf .String ()
@@ -354,3 +355,61 @@ func TestEvent_String(t *testing.T) {
354355 }
355356 }
356357}
358+
359+ func TestRenderer_Iteration_WithStats (t * testing.T ) {
360+ var buf bytes.Buffer
361+ r := New (& buf , true ).WithModel ("deepseek-v4-pro" )
362+
363+ r .Iteration (3 , 90 , 5 * time .Second , 1247 , 342 )
364+
365+ out := buf .String ()
366+ if ! strings .Contains (out , "Iter 3/90" ) {
367+ t .Errorf ("missing iteration info: %q" , out )
368+ }
369+ if ! strings .Contains (out , "deepseek-v4-pro" ) {
370+ t .Errorf ("missing model name: %q" , out )
371+ }
372+ if ! strings .Contains (out , "1247 in" ) {
373+ t .Errorf ("missing input tokens: %q" , out )
374+ }
375+ if ! strings .Contains (out , "342 out" ) {
376+ t .Errorf ("missing output tokens: %q" , out )
377+ }
378+ if ! strings .Contains (out , "5.0s" ) {
379+ t .Errorf ("missing latency: %q" , out )
380+ }
381+ }
382+
383+ func TestRenderer_Iteration_StatsSuppressedWhenZero (t * testing.T ) {
384+ var buf bytes.Buffer
385+ r := New (& buf , true ).WithModel ("test" )
386+
387+ r .Iteration (1 , 10 , 0 , 0 , 0 )
388+
389+ out := buf .String ()
390+ // Check that the stats pattern (with "in ·") doesn't appear.
391+ // Don't check for "[" which is part of ANSI escape codes.
392+ if strings .Contains (out , "0 in" ) {
393+ t .Errorf ("stats should not appear when all values are zero: %q" , out )
394+ }
395+ }
396+
397+ func TestRenderer_Iteration_WithoutModel (t * testing.T ) {
398+ var buf bytes.Buffer
399+ r := New (& buf , true )
400+
401+ r .Iteration (1 , 10 , time .Second , 100 , 50 )
402+
403+ out := buf .String ()
404+ if ! strings .Contains (out , "Iter 1/10" ) {
405+ t .Errorf ("missing iteration info: %q" , out )
406+ }
407+ if ! strings .Contains (out , "100 in" ) {
408+ t .Errorf ("missing input tokens: %q" , out )
409+ }
410+ }
411+
412+ func TestRenderer_Iteration_NilSafe (t * testing.T ) {
413+ var r * Renderer
414+ r .Iteration (1 , 10 , time .Second , 100 , 50 ) // should not panic
415+ }
0 commit comments