Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(list): restore task progress in the loading footer (#4620)
Maximilian Roosb131f1a3e4c6
diff --git a/src/commands/list/collect/mod.rs b/src/commands/list/collect/mod.rsindex 3fda303a3..9553e1c0f 100644--- a/src/commands/list/collect/mod.rs+++ b/src/commands/list/collect/mod.rs@@ -753,9 +753,13 @@ fn render_reveal(.collect()}-fn format_loading_footer(footer_base: &str) -> String {+fn format_loading_footer(footer_base: &str, progress: Option<(usize, usize)>) -> String {let dim = Style::new().dimmed();- format!("{INFO_SYMBOL} {dim}{footer_base} — loading details…{dim:#}")+ let message = match progress {+ Some((completed, total)) => format!("{completed}/{total} tasks complete — {footer_base}"),+ None => format!("{footer_base} — loading details…"),+ };+ format!("{INFO_SYMBOL} {dim}{message}{dim:#}")}/// Build the progressive-table footer shown while the drain is stalled.@@ -765,11 +769,12 @@ fn format_loading_footer(footer_base: &str) -> String {/// `pending_count` is the total outstanding-result count (≥ 1).fn format_stall_footer(footer_base: &str,+ completed: usize,+ total: usize,pending_count: usize,first_kind: TaskKind,first_name: &str,) -> String {- let dim = Style::new().dimmed();let kind_name = first_kind.display_name();let waiting_clause = if pending_count == 1 {cformat!("waiting on <underline>{kind_name}</> for <underline>{first_name}</>")@@ -778,7 +783,10 @@ fn format_stall_footer("waiting on {pending_count} tasks, including <underline>{kind_name}</> for <underline>{first_name}</>")};- cformat!("{INFO_SYMBOL} {dim}{footer_base} — no recent progress; {waiting_clause}{dim:#}")+ format_loading_footer(+ &format!("no recent progress; {waiting_clause} — {footer_base}"),+ Some((completed, total)),+ )}/// Caps on the message shown per failed task: at most `MAX_LINES` lines,@@ -1562,7 +1570,7 @@ pub fn collect(all_items.len());}- table.update_footer(format_loading_footer(&footer_base));+ table.update_footer(format_loading_footer(&footer_base, None));table.render_skeleton()?;worktrunk::trace::instant("Skeleton rendered");Some(table)@@ -1901,6 +1909,10 @@ pub fn collect(.map(|item| layout.render_skeleton_row(item, placeholder).render()).collect();if let Some(table) = progressive_table.as_mut() {+ table.update_footer(format_loading_footer(+ &footer_base,+ Some((0, expected_results.count())),+ ));for (idx, row) in commit_rows.iter().enumerate() {table.update_row(idx, row.clone());}@@ -1997,7 +2009,10 @@ pub fn collect(s.progress_overflow = true;}- let footer_msg = format_loading_footer(&footer_base);+ let footer_msg = format_loading_footer(+ &footer_base,+ Some((s.completed_results, total_results)),+ );s.table.update_footer(footer_msg);s.table.update_row(item_idx, rendered.clone());@@ -2041,6 +2056,8 @@ pub fn collect(let mut s = state_cell.borrow_mut();let footer_msg = format_stall_footer(&footer_base,+ s.completed_results,+ total_results,pending_count,first_kind,first_name,@@ -2446,10 +2463,10 @@ mod tests {#[test]fn test_format_stall_footer_single_pending() {- let rendered = format_stall_footer("3 worktrees", 1, TaskKind::CiStatus, "feat");+ let rendered = format_stall_footer("3 worktrees", 11, 12, 1, TaskKind::CiStatus, "feat");assert_snapshot!(rendered.ansi_strip(),- @"○ 3 worktrees — no recent progress; waiting on CI status for feat"+ @"○ 11/12 tasks complete — no recent progress; waiting on CI status for feat — 3 worktrees");}@@ -2457,13 +2474,15 @@ mod tests {fn test_format_stall_footer_many_pending() {let rendered = format_stall_footer("3 worktrees — first 2 of 3 shown",+ 9,+ 12,3,TaskKind::CiStatus,"feat",);assert_snapshot!(rendered.ansi_strip(),- @"○ 3 worktrees — first 2 of 3 shown — no recent progress; waiting on 3 tasks, including CI status for feat"+ @"○ 9/12 tasks complete — no recent progress; waiting on 3 tasks, including CI status for feat — 3 worktrees — first 2 of 3 shown");}diff --git a/tests/integration_tests/list_progressive.rs b/tests/integration_tests/list_progressive.rsindex 11bfa2816..46e316e7e 100644--- a/tests/integration_tests/list_progressive.rs+++ b/tests/integration_tests/list_progressive.rs@@ -5,14 +5,14 @@#![cfg(all(unix, feature = "shell-integration-tests"))]use crate::common::progressive_output::{ProgressiveCaptureOptions, capture_progressive_output};-use crate::common::pty::{build_pty_command, exec_cmd_in_pty};+use crate::common::pty::{build_pty_command, exec_cmd_in_pty, exec_cmd_in_pty_prompted_with};use crate::common::{TestRepo, repo, wt_bin};use ansi_str::AnsiStr;use rstest::rstest;-/// Loading footers describe the inventory separately from the displayed rows,-/// both before results arrive and as rows fill in. Capture the complete PTY-/// stream so even a fast run must exercise its initial loading footer.+/// Loading footers distinguish inventory, visible rows, and task progress.+/// Capture the complete PTY stream so even a fast run exercises the counter,+/// including progress from off-screen rows.#[test]fn test_list_progressive_loading_footer() {let mut repo = TestRepo::standard_main_only();@@ -22,14 +22,23 @@ fn test_list_progressive_loading_footer() {repo.run_git(&["branch", branch]);}- for (height, expected) in [- (30, "○ 3 worktrees, 2 branches — loading details…"),+ let progress_pattern =+ regex::Regex::new(r"○ (\d+)/(\d+) tasks complete — (\d+ worktrees[^\r\n]*)").unwrap();+ let mut previous_total = None;+ for (height, width, expected) in [+ (30, 150, "○ 3 worktrees, 2 branches — loading details…"),(9,+ 150,"○ 3 worktrees, 2 branches — first 3 of 5 shown — loading details…",),+ (+ 9,+ 60,+ "○ 3 worktrees, 2 branches — first 3 of 5 shown — loading de…",+ ),] {- let pair = crate::common::open_pty_with_size(height, 150);+ let pair = crate::common::open_pty_with_size(height, width);let cmd = build_pty_command(wt_bin().to_str().unwrap(),&["list", "--progressive", "--branches"],@@ -47,7 +56,7 @@ fn test_list_progressive_loading_footer() {let output = raw.ansi_strip();let loading_footers: Vec<_> = output.lines()- .filter(|line| line.contains("loading details…"))+ .filter(|line| line.contains(" — loading ")).map(|line| &line[line.find('○').unwrap()..]).collect();assert!(@@ -57,6 +66,42 @@ fn test_list_progressive_loading_footer() {for footer in loading_footers {assert_eq!(footer.trim_end(), expected);}+ let progress: Vec<_> = progress_pattern+ .captures_iter(&output)+ .map(|capture| {+ if width == 150 {+ assert_eq!(+ &capture[3],+ expected+ .strip_prefix("○ ")+ .unwrap()+ .strip_suffix(" — loading details…")+ .unwrap()+ );+ }+ (+ capture[1].parse::<usize>().unwrap(),+ capture[2].parse::<usize>().unwrap(),+ )+ })+ .collect();+ let total = progress.last().expect("task counter missing").1;+ assert!(total > 0);+ assert_eq!(progress.first(), Some(&(0, total)));+ assert_eq!(progress.last(), Some(&(total, total)));+ assert!(+ progress+ .iter()+ .all(|&(_, denominator)| denominator == total)+ );+ assert!(progress.windows(2).all(|pair| pair[0].0 <= pair[1].0));+ if let Some(previous_total) = previous_total {+ assert_eq!(+ total, previous_total,+ "clipping must not change task totals"+ );+ }+ previous_total = Some(total);assert!(output.contains("Showing 3 worktrees, 2 branches"),"final summary missing: {output}"@@ -64,6 +109,50 @@ fn test_list_progressive_loading_footer() {}}+/// Keep one summary pending until the stall footer is visible, then let it+/// finish. Dropping the gate also releases the command if the test panics.+#[test]+fn test_list_progressive_stall_keeps_task_progress() {+ let mut repo = TestRepo::standard_main_only();+ repo.add_worktree("clean");+ std::fs::write(repo.root_path().join("file.txt"), "changed\n").unwrap();+ repo.write_test_config(+ r#"+[list]+columns = ["branch", "summary"]++[commit.generation]+command = 'cat >/dev/null; while [ -e "$WORKTRUNK_TEST_SUMMARY_GATE" ]; do sleep 0.05; done; echo Update content'+"#,+ );+ let mut gate = Some(tempfile::NamedTempFile::new_in(repo.home_path()).unwrap());+ let mut env = repo.test_env_vars();+ env.push((+ "WORKTRUNK_TEST_SUMMARY_GATE".to_owned(),+ gate.as_ref().unwrap().path().to_str().unwrap().to_owned(),+ ));+ let cmd = build_pty_command(+ wt_bin().to_str().unwrap(),+ &["list", "--progressive"],+ repo.root_path(),+ &env,+ None,+ );+ let stall_marker = "1/2 tasks complete — no recent progress;";+ let (raw, exit_code) = exec_cmd_in_pty_prompted_with(cmd, &[""], stall_marker, |_| {+ gate.take();+ });+ assert_eq!(exit_code, 0);+ let output = raw.ansi_strip();+ let stall = output+ .lines()+ .find(|line| line.contains(stall_marker))+ .unwrap();+ insta::assert_snapshot!(stall.trim(), @"○ 1/2 tasks complete — no recent progress; waiting on summary generation for main — 2 worktrees");+ assert!(output.contains("○ 2/2 tasks complete — 2 worktrees"));+ assert!(output.contains("Showing 2 worktrees"));+}+/// Tests progressive rendering with multiple worktrees./// Verifies: headers appear immediately, dots decrease over time, all worktrees visible./// (Consolidates previous tests: rendering_basic, dots_decrease, many_worktrees)