Przeglądaj źródła

fix(health): only show running tmux sessions, summarize stopped

Alexander Korolev 2 miesięcy temu
rodzic
commit
63cc9a42f5

+ 1 - 0
locales/de/main.ftl

@@ -170,6 +170,7 @@ tmux-health-section = Tmux:
 tmux-health-entry-running = { $recipe } — { $node }: laufend (API: { $api })
 tmux-health-entry-degraded = { $recipe } — { $node }: degradiert (Sitzung existiert, Prozess tot)
 tmux-health-entry-stopped = { $recipe } — { $node }: gestoppt
+tmux-health-all-stopped = { $count } tmux-Rezept(e) konfiguriert, alle gestoppt
 tmux-api-ok = 200
 tmux-api-down = aus
 venv-preparing = 🔧 Bereite venv vor: { $venv }

+ 1 - 0
locales/en/main.ftl

@@ -156,6 +156,7 @@ tmux-health-section = Tmux:
 tmux-health-entry-running = { $recipe } — { $node }: running (API: { $api })
 tmux-health-entry-degraded = { $recipe } — { $node }: degraded (session exists, process dead)
 tmux-health-entry-stopped = { $recipe } — { $node }: stopped
+tmux-health-all-stopped = { $count } tmux recipe(s) configured, all stopped
 tmux-api-ok = 200
 tmux-api-down = down
 venv-preparing = 🔧 Preparing venv: { $venv }

+ 1 - 0
locales/es/main.ftl

@@ -170,6 +170,7 @@ tmux-health-section = Tmux:
 tmux-health-entry-running = { $recipe } — { $node }: en ejecución (API: { $api })
 tmux-health-entry-degraded = { $recipe } — { $node }: degradado (la sesión existe, proceso muerto)
 tmux-health-entry-stopped = { $recipe } — { $node }: detenido
+tmux-health-all-stopped = { $count } receta(s) de tmux configurada(s), todas detenidas
 tmux-api-ok = 200
 tmux-api-down = caído
 venv-preparing = 🔧 Preparando venv: { $venv }

+ 1 - 0
locales/fr/main.ftl

@@ -170,6 +170,7 @@ tmux-health-section = Tmux:
 tmux-health-entry-running = { $recipe } — { $node }: en cours (API : { $api })
 tmux-health-entry-degraded = { $recipe } — { $node }: dégradé (la session existe, processus mort)
 tmux-health-entry-stopped = { $recipe } — { $node }: arrêté
+tmux-health-all-stopped = { $count } recette(s) tmux configurée(s), toutes arrêtées
 tmux-api-ok = 200
 tmux-api-down = arrêté
 venv-preparing = 🔧 Préparation du venv : { $venv }

+ 1 - 0
locales/it/main.ftl

@@ -170,6 +170,7 @@ tmux-health-section = Tmux:
 tmux-health-entry-running = { $recipe } — { $node }: in esecuzione (API: { $api })
 tmux-health-entry-degraded = { $recipe } — { $node }: degradata (la sessione esiste, processo morto)
 tmux-health-entry-stopped = { $recipe } — { $node }: fermato
+tmux-health-all-stopped = { $count } ricetta(e) tmux configurata(e), tutte fermate
 tmux-api-ok = 200
 tmux-api-down = giù
 venv-preparing = 🔧 Preparazione venv: { $venv }

+ 1 - 0
locales/ru/main.ftl

@@ -179,6 +179,7 @@ tmux-health-section = Tmux:
 tmux-health-entry-running = { $recipe } — { $node }: запущен (API: { $api })
 tmux-health-entry-degraded = { $recipe } — { $node }: деградирован (сессия существует, процесс мёртв)
 tmux-health-entry-stopped = { $recipe } — { $node }: остановлен
+tmux-health-all-stopped = { $count } tmux-рецепт(а) настроен(ы), все остановлены
 tmux-api-ok = 200
 tmux-api-down = недоступен
 venv-preparing = 🔧 Подготовка venv: { $venv }

+ 41 - 11
src/tmux/discover.rs

@@ -5,6 +5,8 @@
 //! checks each node for active sessions, and reports status alongside
 //! the Docker container listing.
 
+use std::collections::HashSet;
+
 use tracing::warn;
 
 use crate::config::{Cluster, Config, DeployTarget, Recipe};
@@ -86,16 +88,36 @@ pub async fn tmux_health_for_cluster(config: &Config, cluster: &Cluster) -> Vec<
 
 /// Prints tmux health entries to stdout.
 ///
-/// Shows nothing if there are no tmux-deployed recipes.
+/// Only shows sessions that are running or degraded (session exists).
+/// If all sessions are stopped, prints a single summary line.
+/// Shows nothing if there are no tmux-deployed recipes at all.
 pub fn print_tmux_health(entries: &[TmuxHealthEntry]) {
     if entries.is_empty() {
         return;
     }
 
+    // Only show running/degraded sessions — skip stopped ones to keep output readable.
+    let active: Vec<&TmuxHealthEntry> = entries.iter().filter(|e| e.session_exists).collect();
+
+    if active.is_empty() {
+        // All sessions stopped — show a one-line summary.
+        let recipe_count = entries
+            .iter()
+            .map(|e| e.recipe_display.as_str())
+            .collect::<HashSet<_>>()
+            .len();
+        println!();
+        println!(
+            "  {}",
+            fluent_i18n::t!("tmux-health-all-stopped", { "count" => recipe_count })
+        );
+        return;
+    }
+
     println!();
     println!("{}", fluent_i18n::t!("tmux-health-section"));
-    for entry in entries {
-        let status = if entry.session_exists && entry.process_running {
+    for entry in active {
+        let status = if entry.process_running {
             let api_str = if entry.api_ok {
                 fluent_i18n::t!("tmux-api-ok")
             } else {
@@ -106,13 +128,8 @@ pub fn print_tmux_health(entries: &[TmuxHealthEntry]) {
                 "node" => &entry.node_name,
                 "api" => &api_str,
             })
-        } else if entry.session_exists {
-            fluent_i18n::t!("tmux-health-entry-degraded", {
-                "recipe" => &entry.recipe_display,
-                "node" => &entry.node_name,
-            })
         } else {
-            fluent_i18n::t!("tmux-health-entry-stopped", {
+            fluent_i18n::t!("tmux-health-entry-degraded", {
                 "recipe" => &entry.recipe_display,
                 "node" => &entry.node_name,
             })
@@ -153,7 +170,20 @@ mod tests {
     }
 
     #[test]
-    fn print_tmux_health_with_entries() {
+    fn print_tmux_health_all_stopped_shows_summary() {
+        let entries = vec![TmuxHealthEntry {
+            recipe_display: "Test Recipe".to_string(),
+            node_name: "dgx1".to_string(),
+            session_exists: false,
+            process_running: false,
+            api_ok: false,
+        }];
+        // Should not panic — prints summary line
+        print_tmux_health(&entries);
+    }
+
+    #[test]
+    fn print_tmux_health_running_shows_entry() {
         let entries = vec![
             TmuxHealthEntry {
                 recipe_display: "Test Recipe".to_string(),
@@ -170,7 +200,7 @@ mod tests {
                 api_ok: false,
             },
         ];
-        // Should not panic
+        // Should not panic — prints running entry, skips stopped
         print_tmux_health(&entries);
     }
 }