@@ -3455,6 +3455,83 @@ fn tool_usage_label_handles_missing_and_legacy_duration() {
34553455 ) ;
34563456}
34573457
3458+ #[ test]
3459+ fn render_tool_message_colors_duration_independently_from_tokens ( ) {
3460+ for ( seconds, duration_color) in [
3461+ ( 0.42 , rgb ( 118 , 118 , 118 ) ) ,
3462+ ( 9.99 , rgb ( 118 , 118 , 118 ) ) ,
3463+ ( 10.0 , rgb ( 214 , 184 , 92 ) ) ,
3464+ ( 59.99 , rgb ( 214 , 184 , 92 ) ) ,
3465+ ( 60.0 , rgb ( 224 , 118 , 118 ) ) ,
3466+ ] {
3467+ for content in [ "ok" . to_owned ( ) , "x" . repeat ( 48_000 ) ] {
3468+ let mut msg = DisplayMessage :: tool (
3469+ content,
3470+ crate :: message:: ToolCall {
3471+ id : "independent-metrics" . into ( ) ,
3472+ name : "read" . into ( ) ,
3473+ input : serde_json:: json!( { } ) ,
3474+ intent : None ,
3475+ thought_signature : None ,
3476+ } ,
3477+ ) ;
3478+ msg. duration_secs = Some ( seconds) ;
3479+ let badge = tool_output_token_badge ( & msg. content ) ;
3480+ for width in [ 32 , 120 ] {
3481+ let lines = render_tool_message ( & msg, width, crate :: config:: DiffDisplayMode :: Off ) ;
3482+ let spans = & lines[ 0 ] . spans ;
3483+ let token_index = spans
3484+ . iter ( )
3485+ . position ( |span| span. content == badge. label )
3486+ . expect ( "missing token span" ) ;
3487+ assert_eq ! ( spans[ token_index] . style. fg, Some ( badge. color) ) ;
3488+ assert_eq ! ( spans[ token_index - 1 ] . content, ", " ) ;
3489+ assert_eq ! ( spans[ token_index - 2 ] . style. fg, Some ( duration_color) ) ;
3490+ assert ! ( lines[ 0 ] . width( ) < width as usize ) ;
3491+ }
3492+ }
3493+ }
3494+ }
3495+
3496+ #[ test]
3497+ fn batch_subcall_colors_duration_independently_from_tokens ( ) {
3498+ let tool = crate :: message:: ToolCall {
3499+ id : "timed-child" . into ( ) ,
3500+ name : "read" . into ( ) ,
3501+ input : serde_json:: json!( { } ) ,
3502+ intent : None ,
3503+ thought_signature : None ,
3504+ } ;
3505+ for ( timing, color) in [
3506+ ( "420ms" , rgb ( 118 , 118 , 118 ) ) ,
3507+ ( "10s" , rgb ( 214 , 184 , 92 ) ) ,
3508+ ( "1m" , rgb ( 224 , 118 , 118 ) ) ,
3509+ ] {
3510+ let content = format ! ( "[tool timing: duration={timing}] {}" , "x" . repeat( 48_000 ) ) ;
3511+ let line = crate :: tui:: ui:: tools_ui:: render_batch_subcall_line (
3512+ & tool,
3513+ "✓" ,
3514+ rgb ( 100 , 180 , 100 ) ,
3515+ 50 ,
3516+ Some ( 60 ) ,
3517+ Some ( & content) ,
3518+ ) ;
3519+ let duration = line
3520+ . spans
3521+ . iter ( )
3522+ . find ( |span| span. content == timing)
3523+ . expect ( "missing duration span" ) ;
3524+ assert_eq ! ( duration. style. fg, Some ( color) ) ;
3525+ let tokens = line
3526+ . spans
3527+ . iter ( )
3528+ . find ( |span| span. content . ends_with ( " tok" ) )
3529+ . expect ( "missing token span" ) ;
3530+ assert_eq ! ( tokens. style. fg, Some ( rgb( 224 , 118 , 118 ) ) ) ;
3531+ assert ! ( line. width( ) <= 60 ) ;
3532+ }
3533+ }
3534+
34583535#[ test]
34593536fn render_tool_message_colors_high_token_badge ( ) {
34603537 let msg = DisplayMessage {
0 commit comments