Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(list): show placeholder in WorkingDiff and Upstream when data not loaded (#1503)
Maximilian Roos2d4f55c66104
diff --git a/src/commands/list/json_output.rs b/src/commands/list/json_output.rsindex aa6038fb5..40abc8d71 100644--- a/src/commands/list/json_output.rs+++ b/src/commands/list/json_output.rs@@ -859,7 +859,7 @@ mod tests {#[test]fn test_json_item_summary_absent() {let mut item = ListItem::new_branch("abc1234".into(), "feature".into());- // None = not loaded, Some(None) = loaded but no summary — both should be absent in JSON+ // Both "not collected" and "no summary" should be absent in JSONassert!(JsonItem::from_list_item(&item).summary.is_none());item.summary = Some(None);diff --git a/src/commands/list/model/item.rs b/src/commands/list/model/item.rsindex 852db72fd..551692caa 100644--- a/src/commands/list/model/item.rs+++ b/src/commands/list/model/item.rs@@ -137,7 +137,12 @@ pub enum ItemKind {Branch,}-/// Unified item for displaying worktrees and branches in the same table+/// Unified item for displaying worktrees and branches in the same table.+///+/// Column-rendered fields are `Option<U>` where the outer `Option` encodes whether data+/// was collected (`None` = not loaded, render shows placeholder). The inner type `U` is+/// whatever the data naturally is — e.g., `AheadBehind` (always has a value, even if zero)+/// or `Option<PrStatus>` (CI may not exist).#[derive(serde::Serialize)]pub struct ListItem {// Common fields (present for both worktrees and branches)@@ -185,7 +190,7 @@ pub struct ListItem {#[serde(flatten, skip_serializing_if = "Option::is_none")]pub upstream: Option<UpstreamStatus>,- /// CI/PR status: None = not loaded, Some(None) = no CI, Some(Some(status)) = has CI+ /// CI/PR status (inner Option: whether CI exists for this branch)pub pr_status: Option<Option<PrStatus>>,/// Dev server URL computed from project config template@@ -195,7 +200,7 @@ pub struct ListItem {#[serde(skip_serializing_if = "Option::is_none")]pub url_active: Option<bool>,- /// LLM-generated branch summary: None = not loaded, Some(None) = no summary, Some(Some) = has summary+ /// LLM-generated branch summary (inner Option: whether LLM produced a summary)#[serde(skip)]pub summary: Option<Option<String>>,@@ -267,10 +272,6 @@ impl ListItem {self.branch_diff.as_ref()}- pub fn upstream(&self) -> UpstreamStatus {- self.upstream.clone().unwrap_or_default()- }-pub fn worktree_data(&self) -> Option<&WorktreeData> {match &self.kind {ItemKind::Worktree(data) => Some(data),@@ -668,13 +669,6 @@ mod tests {assert!(item.branch_diff().is_none());}- #[test]- fn test_list_item_upstream() {- let item = ListItem::new_branch("abc123".to_string(), "feature".to_string());- let upstream = item.upstream();- assert!(upstream.remote.is_none());- }-#[test]fn test_list_item_worktree_data() {// Branch item has no worktree datadiff --git a/src/commands/list/render.rs b/src/commands/list/render.rsindex 28cc541db..bbadb2b3a 100644--- a/src/commands/list/render.rs+++ b/src/commands/list/render.rs@@ -400,11 +400,11 @@ impl ColumnLayout {cell}ColumnKind::WorkingDiff => {- // TODO: show placeholder when data is missing (currently blank,- // inconsistent with other columns that show ⋯/· for unloaded data)- let Some(diff) = worktree_data.and_then(|data| data.working_tree_diff.as_ref())- else {- return StyledLine::new();+ let Some(data) = worktree_data else {+ return StyledLine::new(); // Branch item — no working tree+ };+ let Some(diff) = data.working_tree_diff.as_ref() else {+ return self.placeholder_cell(placeholder); // Not loaded yet};self.render_diff_cell(diff.added, diff.deleted)}@@ -435,11 +435,11 @@ impl ColumnLayout {self.render_text_cell(&path_str, text_style)}ColumnKind::Upstream => {- // TODO: show placeholder when data is missing (currently blank,- // inconsistent with other columns that show ⋯/· for unloaded data)- let upstream = item.upstream();+ let Some(ref upstream) = item.upstream else {+ return self.placeholder_cell(placeholder); // Not loaded yet+ };let Some(active) = upstream.active() else {- return StyledLine::new();+ return StyledLine::new(); // Loaded, no active upstream};// Show centered | when in sync instead of ⇡0 ⇣0// Note: This duplicates the InSync check from Divergence::Special, but@@ -493,13 +493,9 @@ impl ColumnLayout {return cell;}- // pr_status is Option<Option<PrStatus>>:- // - None = not loaded yet (show spinner)- // - Some(None) = loaded, no CI (show nothing)- // - Some(Some(status)) = loaded with CI (show status)match &item.pr_status {- None => self.placeholder_cell(placeholder), // Not loaded yet- Some(None) => StyledLine::new(), // Loaded, no CI+ None => self.placeholder_cell(placeholder),+ Some(None) => StyledLine::new(), // No CI for this branchSome(Some(pr_status)) => {let mut cell = StyledLine::new();cell.push_raw(@@ -518,22 +514,16 @@ impl ColumnLayout {self.render_text_cell(short_head, Some(Style::new().dimmed()))}}- ColumnKind::Summary => {- // summary is Option<Option<String>>:- // - None = not loaded yet (show spinner)- // - Some(None) = no summary (blank)- // - Some(Some(text)) = has summary- match &item.summary {- None => self.placeholder_cell(placeholder),- Some(None) => StyledLine::new(),- Some(Some(summary)) => {- let mut cell = StyledLine::new();- let msg = truncate_to_width(summary, max_summary_len);- cell.push_styled(msg, Style::new());- cell- }+ ColumnKind::Summary => match &item.summary {+ None => self.placeholder_cell(placeholder),+ Some(None) => StyledLine::new(),+ Some(Some(summary)) => {+ let mut cell = StyledLine::new();+ let msg = truncate_to_width(summary, max_summary_len);+ cell.push_styled(msg, Style::new());+ cell}- }+ },ColumnKind::Message => {let Some(ref commit) = item.commit else {return self.placeholder_cell(placeholder);@@ -1374,4 +1364,92 @@ mod tests {let cell = summary_col.render_cell(&item, &mask, &main_path, 50, 40, "⋯");insta::assert_snapshot!(cell.render(), @"Add user authentication");}++ #[test]+ fn test_working_diff_placeholder_when_not_loaded() {+ use super::super::layout::ColumnLayout;+ use super::super::model::{ItemKind, ListItem, PositionMask};+ use std::path::PathBuf;+ use worktrunk::styling::{ADDITION, DELETION};++ let col = ColumnLayout {+ kind: ColumnKind::WorkingDiff,+ header: "Working",+ start: 0,+ width: 9,+ format: ColumnFormat::Diff(DiffColumnConfig {+ positive_digits: 3,+ negative_digits: 3,+ total_width: 9,+ display: DiffDisplayConfig {+ variant: super::super::columns::DiffVariant::Signs,+ positive_style: ADDITION,+ negative_style: DELETION,+ always_show_zeros: false,+ },+ }),+ };++ let mask = PositionMask::FULL;+ let main_path = PathBuf::from("/tmp");++ // Branch item (no worktree data) → blank, not placeholder+ let branch_item = ListItem::new_branch("abc123".into(), "feat".into());+ let cell = col.render_cell(&branch_item, &mask, &main_path, 50, 40, "⋯");+ assert!(cell.render().is_empty(), "branch item should be blank");++ // Worktree item with working_tree_diff: None → placeholder+ let mut wt_item = ListItem::new_branch("abc123".into(), "feat".into());+ wt_item.kind = ItemKind::Worktree(Box::default());+ let cell = col.render_cell(&wt_item, &mask, &main_path, 50, 40, "⋯");+ insta::assert_snapshot!(cell.render(), @" [2m⋯[0m");++ // Stale placeholder+ let cell = col.render_cell(&wt_item, &mask, &main_path, 50, 40, "·");+ insta::assert_snapshot!(cell.render(), @" [2m·[0m");+ }++ #[test]+ fn test_upstream_placeholder_when_not_loaded() {+ use super::super::layout::ColumnLayout;+ use super::super::model::{ListItem, PositionMask, UpstreamStatus};+ use std::path::PathBuf;+ use worktrunk::styling::{ADDITION, DELETION};++ let col = ColumnLayout {+ kind: ColumnKind::Upstream,+ header: "Remote⇅",+ start: 0,+ width: 7,+ format: ColumnFormat::Diff(DiffColumnConfig {+ positive_digits: 2,+ negative_digits: 2,+ total_width: 7,+ display: DiffDisplayConfig {+ variant: super::super::columns::DiffVariant::UpstreamArrows,+ positive_style: ADDITION,+ negative_style: DELETION.dimmed(),+ always_show_zeros: false,+ },+ }),+ };++ let mask = PositionMask::FULL;+ let main_path = PathBuf::from("/tmp");++ // upstream: None (not loaded) → placeholder+ let item = ListItem::new_branch("abc123".into(), "feat".into());+ assert!(item.upstream.is_none());+ let cell = col.render_cell(&item, &mask, &main_path, 50, 40, "⋯");+ insta::assert_snapshot!(cell.render(), @" [2m⋯[0m");++ // upstream: Some(default) (loaded, no active upstream) → blank+ let mut item = ListItem::new_branch("abc123".into(), "feat".into());+ item.upstream = Some(UpstreamStatus::default());+ let cell = col.render_cell(&item, &mask, &main_path, 50, 40, "⋯");+ assert!(+ cell.render().is_empty(),+ "no active upstream should be blank"+ );+ }}diff --git a/src/commands/select/mod.rs b/src/commands/select/mod.rsindex 3a46a4c55..d59e97b21 100644--- a/src/commands/select/mod.rs+++ b/src/commands/select/mod.rs@@ -135,12 +135,11 @@ pub fn handle_select(.map(|item| {let branch_name = item.branch_name().to_string();- // Use stale rendering (·) for items where data didn't arrive within budget,- // normal rendering (⋯) otherwise. status_symbols is always set by completed- // tasks, so None means worker results didn't arrive for this item.- // Note: prunable worktrees also start with status_symbols: None, but collect()- // sets status_symbols for them in the post-drain loop. If that changes, this- // heuristic would false-positive on prunable items.+ // status_symbols is None only when no task results arrived for this item+ // (budget truncation). collect() sets it for all other items: via drain+ // callbacks for items that received results, and the post-drain loop for+ // prunable worktrees. Each column also shows the placeholder independently+ // when its own data field is None.let rendered_line = if item.status_symbols.is_none() {layout.render_list_item_stale(&item)} else {diff --git a/tests/CLAUDE.md b/tests/CLAUDE.mdindex 361caf8ad..25ad4d86e 100644--- a/tests/CLAUDE.md+++ b/tests/CLAUDE.md@@ -287,6 +287,14 @@ For environment-dependent tests, use `Command::new()` with `.env()` to set varia## Test Style+### Snapshot env drift is cosmetic++`insta_cmd` snapshots record the test's environment variables in an `env:` block.+When test infrastructure changes add or reorder env vars (e.g., `NO_COLOR: ""`+appearing in a snapshot that didn't have it before), the snapshot diff includes+those lines even though the test output is unchanged. This is cosmetic drift —+accept it without comment during review.+### Inline snapshots over multi-assertWhen a test checks formatted output, use `insta::assert_snapshot!` with andiff --git a/tests/snapshots/integration__integration_tests__list__list_empty_repo.snap b/tests/snapshots/integration__integration_tests__list__list_empty_repo.snapindex 8d7817352..817b42e74 100644--- a/tests/snapshots/integration__integration_tests__list__list_empty_repo.snap+++ b/tests/snapshots/integration__integration_tests__list__list_empty_repo.snap@@ -17,6 +17,7 @@ info:HOME: "[TEST_HOME]"LANG: CLC_ALL: C+ NO_COLOR: ""PSModulePath: ""RUST_LOG: warnSHELL: ""@@ -37,7 +38,7 @@ success: trueexit_code: 0----- stdout -----[1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mRemote⇅[0m [1mPath[0m [1mCommit[0m [1mAge[0m [1mMessage-@ main [2m^[22m . [2m⋯[0m [2m⋯+@ main [2m^[22m [2m⋯[0m . [2m⋯[0m [2m⋯[2m○[22m [2mShowing 1 worktreediff --git a/tests/snapshots/integration__integration_tests__list__list_shows_warning_on_git_error.snap b/tests/snapshots/integration__integration_tests__list__list_shows_warning_on_git_error.snapindex bba71b035..4c6675947 100644--- a/tests/snapshots/integration__integration_tests__list__list_shows_warning_on_git_error.snap+++ b/tests/snapshots/integration__integration_tests__list__list_shows_warning_on_git_error.snap@@ -44,7 +44,7 @@ exit_code: 0+ feature-a [2m↑[22m [32m↑1[0m ../repo.feature-a [2m1b87d473[0m [2m16h[0m [2mAdd feature-a file+ feature-b [2m↑[22m [32m↑1[0m ../repo.feature-b [2mf62940fc[0m [2m16h[0m [2mAdd feature-b file+ feature-c [2m↑[22m [32m↑1[0m ../repo.feature-c [2m345c7c93[0m [2m16h[0m [2mAdd feature-c file-+ feature [2m⋯[0m ../repo.feature [2m⋯[0m [2m⋯++ feature [2m⋯[0m [2m⋯[0m ../repo.feature [2m⋯[0m [2m⋯[2m○[22m [2mShowing 5 worktrees, 3 ahead. 1 task faileddiff --git a/tests/snapshots/integration__integration_tests__list__list_skips_operations_for_prunable_worktrees.snap b/tests/snapshots/integration__integration_tests__list__list_skips_operations_for_prunable_worktrees.snapindex 2ef337bca..2008f4a73 100644--- a/tests/snapshots/integration__integration_tests__list__list_skips_operations_for_prunable_worktrees.snap+++ b/tests/snapshots/integration__integration_tests__list__list_skips_operations_for_prunable_worktrees.snap@@ -18,6 +18,7 @@ info:LANG: CLC_ALL: CMOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""PATH: "[PATH]"PSModulePath: ""RUST_LOG: warn@@ -40,7 +41,7 @@ exit_code: 0----- stdout -----[1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mRemote⇅[0m [1mPath[0m [1mCommit[0m [1mAge[0m [1mMessage@ main [2m^[22m[2m|[22m [2m|[0m . [2m05a4a45d[0m [2m16h[0m [2mInitial commit-+ feature [33m⊟[39m [2m⋯[0m ../repo.feature [2m05a4a45d[0m [2m⋯[0m [2m⋯++ feature [33m⊟[39m [2m⋯[0m [2m⋯[0m [2m⋯[0m ../repo.feature [2m05a4a45d[0m [2m⋯[0m [2m⋯+ feature-a [2m↑[22m [32m↑1[0m ../repo.feature-a [2m1b87d473[0m [2m16h[0m [2mAdd feature-a file+ feature-b [2m↑[22m [32m↑1[0m ../repo.feature-b [2mf62940fc[0m [2m16h[0m [2mAdd feature-b file+ feature-c [2m↑[22m [32m↑1[0m ../repo.feature-c [2m345c7c93[0m [2m16h[0m [2mAdd feature-c file