Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(list): disclose clipped rows in the loading footer (#4333)
Maximilian Roos442354830ec6
diff --git a/src/commands/list/collect/mod.rs b/src/commands/list/collect/mod.rsindex cae461dfd..bf2fa7b7b 100644--- a/src/commands/list/collect/mod.rs+++ b/src/commands/list/collect/mod.rs@@ -751,6 +751,11 @@ fn render_reveal(.collect()}+fn format_loading_footer(footer_base: &str) -> String {+ let dim = Style::new().dimmed();+ format!("{INFO_SYMBOL} {dim}{footer_base} — loading details…{dim:#}")+}+/// Build the progressive-table footer shown while the drain is stalled.////// Pure so it can be snapshot-tested without spinning up the live table.@@ -758,8 +763,6 @@ fn render_reveal(/// `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,@@ -773,9 +776,7 @@ fn format_stall_footer("waiting on {pending_count} tasks, including <underline>{kind_name}</> for <underline>{first_name}</>")};- cformat!(- "{INFO_SYMBOL} {dim}{footer_base} ({completed}/{total} loaded, no recent progress; {waiting_clause}){dim:#}"- )+ cformat!("{INFO_SYMBOL} {dim}{footer_base} — no recent progress; {waiting_clause}{dim:#}")}/// Caps on the message shown per failed task: at most `MAX_LINES` lines,@@ -1513,27 +1514,9 @@ pub fn collect(// Track expected results per item - populated as spawns are queuedlet expected_results = std::sync::Arc::new(ExpectedResults::default());- let num_worktrees = all_items- .iter()- .filter(|item| item.worktree_data().is_some())- .count();- let num_local_branches = branches_without_worktrees.len();- let num_remote_branches = remote_branches.len();-- let footer_base =- if (show_branches && num_local_branches > 0) || (show_remotes && num_remote_branches > 0) {- let mut parts = vec![format!("{} worktrees", num_worktrees)];- if show_branches && num_local_branches > 0 {- parts.push(format!("{} branches", num_local_branches));- }- if show_remotes && num_remote_branches > 0 {- parts.push(format!("{} remote branches", num_remote_branches));- }- format!("Showing {}", parts.join(", "))- } else {- let plural = if num_worktrees == 1 { "" } else { "s" };- format!("Showing {} worktree{}", num_worktrees, plural)- };+ let mut footer_base = super::SummaryMetrics::from_items(&all_items)+ .inventory_parts(show_branches || show_remotes)+ .join(", ");// Track which placeholder rendering currently uses. Progressive renderers// (table or picker) start blank so commands that finish under@@ -1550,8 +1533,6 @@ pub fn collect(// Create progressive table if showing progress.let mut progressive_table = if show_progress {- let dim = Style::new().dimmed();-// Build skeleton rows for both worktrees and branches// All items need skeleton rendering since computed data (timestamp, ahead/behind, etc.)// hasn't been loaded yet. Using format_list_item_line would show default values like "55y".@@ -1560,14 +1541,20 @@ pub fn collect(.map(|item| layout.render_skeleton_row(item, placeholder).render()).collect();- let initial_footer = format!("{INFO_SYMBOL} {dim}{footer_base} (loading...){dim:#}");-let mut table = ProgressiveTable::new(layout.format_header_line(),skeletons,- initial_footer,+ String::new(),max_width,);+ let visible_rows = table.visible_row_count();+ if visible_rows < all_items.len() {+ footer_base = format!(+ "{footer_base} — first {visible_rows} of {} shown",+ all_items.len()+ );+ }+ table.update_footer(format_loading_footer(&footer_base));table.render_skeleton()?;worktrunk::trace::instant("Skeleton rendered");Some(table)@@ -1960,7 +1947,6 @@ pub fn collect(drain_deadline,primary_target,|event| {- let dim = Style::new().dimmed();let total_results = expected_results.count();match event {@@ -1997,10 +1983,7 @@ pub fn collect(s.progress_overflow = true;}- let completed = s.completed_results;- let footer_msg = format!(- "{INFO_SYMBOL} {dim}{footer_base} ({completed}/{total_results} loaded){dim:#}"- );+ let footer_msg = format_loading_footer(&footer_base);s.table.update_footer(footer_msg);s.table.update_row(item_idx, rendered.clone());@@ -2044,8 +2027,6 @@ 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,@@ -2451,21 +2432,24 @@ mod tests {#[test]fn test_format_stall_footer_single_pending() {- let rendered =- format_stall_footer("Showing 3 worktrees", 5, 12, 1, TaskKind::CiStatus, "feat");+ let rendered = format_stall_footer("3 worktrees", 1, TaskKind::CiStatus, "feat");assert_snapshot!(rendered.ansi_strip(),- @"○ Showing 3 worktrees (5/12 loaded, no recent progress; waiting on CI status for feat)"+ @"○ 3 worktrees — no recent progress; waiting on CI status for feat");}#[test]fn test_format_stall_footer_many_pending() {- let rendered =- format_stall_footer("Showing 3 worktrees", 5, 12, 3, TaskKind::CiStatus, "feat");+ let rendered = format_stall_footer(+ "3 worktrees — first 2 of 3 shown",+ 3,+ TaskKind::CiStatus,+ "feat",+ );assert_snapshot!(rendered.ansi_strip(),- @"○ Showing 3 worktrees (5/12 loaded, no recent progress; waiting on 3 tasks, including CI status for feat)"+ @"○ 3 worktrees — first 2 of 3 shown — no recent progress; waiting on 3 tasks, including CI status for feat");}diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rsindex 7fde02c35..18c42097f 100644--- a/src/commands/list/mod.rs+++ b/src/commands/list/mod.rs@@ -297,11 +297,7 @@ impl SummaryMetrics {}}- pub(super) fn summary_parts(- &self,- include_branches: bool,- hidden_columns: &[String],- ) -> Vec<String> {+ pub(super) fn inventory_parts(&self, include_branches: bool) -> Vec<String> {let mut parts = Vec::new();let plural = if self.worktrees == 1 { "" } else { "s" };@@ -318,6 +314,16 @@ impl SummaryMetrics {}}+ parts+ }++ pub(super) fn summary_parts(+ &self,+ include_branches: bool,+ hidden_columns: &[String],+ ) -> Vec<String> {+ let mut parts = self.inventory_parts(include_branches);+if self.dirty_worktrees > 0 {parts.push(format!("{} with changes", self.dirty_worktrees));}diff --git a/src/commands/list/progressive_table.rs b/src/commands/list/progressive_table.rsindex 8dfef04a7..8ea62f0d2 100644--- a/src/commands/list/progressive_table.rs+++ b/src/commands/list/progressive_table.rs@@ -229,6 +229,11 @@ impl ProgressiveTable {Ok(())}+ /// Number of data rows displayed during progressive rendering.+ pub fn visible_row_count(&self) -> usize {+ self.row_count+ }+/// Print all lines to stdout, followed by the prompt-reserve rows.fn print_all(&self) -> std::io::Result<()> {let mut stdout = stdout();diff --git a/tests/integration_tests/list_progressive.rs b/tests/integration_tests/list_progressive.rsindex 5e657b8ab..11bfa2816 100644--- a/tests/integration_tests/list_progressive.rs+++ b/tests/integration_tests/list_progressive.rs@@ -7,8 +7,63 @@use crate::common::progressive_output::{ProgressiveCaptureOptions, capture_progressive_output};use crate::common::pty::{build_pty_command, exec_cmd_in_pty};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.+#[test]+fn test_list_progressive_loading_footer() {+ let mut repo = TestRepo::standard_main_only();+ repo.add_worktree("feature-a");+ repo.add_worktree("feature-b");+ for branch in ["branch-a", "branch-b"] {+ repo.run_git(&["branch", branch]);+ }++ for (height, expected) in [+ (30, "○ 3 worktrees, 2 branches — loading details…"),+ (+ 9,+ "○ 3 worktrees, 2 branches — first 3 of 5 shown — loading details…",+ ),+ ] {+ let pair = crate::common::open_pty_with_size(height, 150);+ let cmd = build_pty_command(+ wt_bin().to_str().unwrap(),+ &["list", "--progressive", "--branches"],+ repo.root_path(),+ &repo.test_env_vars(),+ None,+ );+ let mut child = pair.slave.spawn_command(cmd).unwrap();+ drop(pair.slave);+ let reader = pair.master.try_clone_reader().unwrap();+ let writer = pair.master.take_writer().unwrap();+ let (raw, exit_code) =+ crate::common::pty::read_pty_output(reader, writer, pair.master, &mut child);+ assert_eq!(exit_code, 0);+ let output = raw.ansi_strip();+ let loading_footers: Vec<_> = output+ .lines()+ .filter(|line| line.contains("loading details…"))+ .map(|line| &line[line.find('○').unwrap()..])+ .collect();+ assert!(+ !loading_footers.is_empty(),+ "initial footer missing: {output}"+ );+ for footer in loading_footers {+ assert_eq!(footer.trim_end(), expected);+ }+ assert!(+ output.contains("Showing 3 worktrees, 2 branches"),+ "final summary missing: {output}"+ );+ }+}+/// 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)