@@ -45,7 +45,7 @@ use systemg::{
4545 CronUnitStatus , ExitMetadata , OverallHealth , ProcessState , ProjectRunMode ,
4646 SpawnedProcessNode , StatusSnapshot , UnitHealth , UnitIntent , UnitKind ,
4747 UnitMetricsSummary , UnitState , UnitStatus , UptimeInfo , collect_disk_snapshot,
48- compute_overall_health, format_elapsed,
48+ compute_overall_health, explain_unit_health , format_elapsed,
4949 } ,
5050 supervisor:: Supervisor ,
5151} ;
@@ -1190,7 +1190,7 @@ mod tests {
11901190 runtime_command : None ,
11911191 spawned_children : vec ! [ ] ,
11921192 } ;
1193- let unit_row = format_unit_row ( & unit, & columns, true ) ;
1193+ let unit_row = format_unit_row_focus ( & unit, & columns, true , None ) ;
11941194 assert ! ( unit_row. contains( "srvc" ) ) ;
11951195 assert ! ( unit_row. contains( "rashad" ) ) ;
11961196
@@ -2248,6 +2248,71 @@ mod tests {
22482248 assert ! ( widths[ 3 ] >= INSPECT_CRON_SOFT_MIN_WIDTHS [ 3 ] ) ;
22492249 }
22502250
2251+ #[ test]
2252+ fn format_inspect_cron_status_colors_by_outcome ( ) {
2253+ let success =
2254+ format_inspect_cron_status ( Some ( & CronExecutionStatus :: Success ) , false ) ;
2255+ assert ! ( success. contains( "success" ) ) ;
2256+ assert ! ( success. contains( BRIGHT_GREEN ) ) ;
2257+
2258+ let running = format_inspect_cron_status ( None , false ) ;
2259+ assert ! ( running. contains( "running" ) ) ;
2260+ assert ! ( running. contains( LIGHT_BLUE ) ) ;
2261+
2262+ let failed = format_inspect_cron_status (
2263+ Some ( & CronExecutionStatus :: Failed ( "boom" . into ( ) ) ) ,
2264+ false ,
2265+ ) ;
2266+ assert ! ( failed. contains( "failed: boom" ) ) ;
2267+ assert ! ( failed. contains( RED_BOLD ) ) ;
2268+ }
2269+
2270+ #[ test]
2271+ fn format_inspect_cron_status_respects_no_color ( ) {
2272+ let success =
2273+ format_inspect_cron_status ( Some ( & CronExecutionStatus :: Success ) , true ) ;
2274+ assert_eq ! ( success, "success" ) ;
2275+ }
2276+
2277+ #[ test]
2278+ fn wrap_paragraph_respects_width_and_keeps_words_whole ( ) {
2279+ let text = "the quick brown fox jumps over the lazy dog" ;
2280+ let lines = wrap_paragraph ( text, 20 ) ;
2281+ assert ! ( lines. iter( ) . all( |line| visible_length( line) <= 20 ) ) ;
2282+ let rejoined = lines. join ( " " ) ;
2283+ assert_eq ! ( rejoined, text) ;
2284+ }
2285+
2286+ #[ test]
2287+ fn render_health_report_includes_required_sections ( ) {
2288+ let mut unit = UnitStatus {
2289+ name : "api" . into ( ) ,
2290+ hash : "hash" . into ( ) ,
2291+ project : None ,
2292+ kind : UnitKind :: Service ,
2293+ lifecycle : Some ( ServiceLifecycleStatus :: Stopped ) ,
2294+ state : UnitState :: Stopped ,
2295+ intent : UnitIntent :: Serve ,
2296+ health : UnitHealth :: Warn ,
2297+ process : None ,
2298+ uptime : None ,
2299+ last_exit : None ,
2300+ cron : None ,
2301+ metrics : None ,
2302+ command : None ,
2303+ runtime_command : None ,
2304+ spawned_children : Vec :: new ( ) ,
2305+ } ;
2306+ unit. intent = UnitIntent :: Serve ;
2307+
2308+ let rendered = render_health_report ( & unit, true ) . join ( "\n " ) ;
2309+ assert ! ( rendered. contains( "# " ) ) ;
2310+ assert ! ( rendered. contains( "Severity:" ) ) ;
2311+ assert ! ( rendered. contains( "TLDR:" ) ) ;
2312+ assert ! ( rendered. contains( "## Description" ) ) ;
2313+ assert ! ( rendered. contains( "## Recommended Fix" ) ) ;
2314+ }
2315+
22512316 #[ test]
22522317 fn test_format_uptime_short ( ) {
22532318 assert_eq ! ( format_uptime_short( "30 secs ago" ) , "< 1m" ) ;
0 commit comments