Skip to content

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.rs
index 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 JSON
assert!(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.rs
index 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 data
diff --git a/src/commands/list/render.rs b/src/commands/list/render.rs
index 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 branch
Some(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(), @" ⋯");
+
+ // Stale placeholder
+ let cell = col.render_cell(&wt_item, &mask, &main_path, 50, 40, "·");
+ insta::assert_snapshot!(cell.render(), @" ·");
+ }
+
+ #[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(), @" ⋯");
+
+ // 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.rs
index 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.md
index 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-assert
When a test checks formatted output, use `insta::assert_snapshot!` with an
diff --git a/tests/snapshots/integration__integration_tests__list__list_empty_repo.snap b/tests/snapshots/integration__integration_tests__list__list_empty_repo.snap
index 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: C
LC_ALL: C
+ NO_COLOR: ""
PSModulePath: ""
RUST_LOG: warn
SHELL: ""
@@ -37,7 +38,7 @@ success: true
exit_code: 0
----- stdout -----
Branch Status HEAD± main↕ Remote⇅ Path Commit Age Message
-@ main ^ . ⋯ ⋯
+@ main ^ ⋯ . ⋯ ⋯
○ Showing 1 worktree
diff --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.snap
index 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 ↑ ↑1 ../repo.feature-a 1b87d473 16h Add feature-a file
+ feature-b ↑ ↑1 ../repo.feature-b f62940fc 16h Add feature-b file
+ feature-c ↑ ↑1 ../repo.feature-c 345c7c93 16h Add feature-c file
-+ feature ⋯ ../repo.feature ⋯ ⋯
++ feature ⋯ ⋯ ../repo.feature ⋯ ⋯
○ Showing 5 worktrees, 3 ahead. 1 task failed
diff --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.snap
index 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: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -40,7 +41,7 @@ exit_code: 0
----- stdout -----
Branch Status HEAD± main↕ Remote⇅ Path Commit Age Message
@ main ^| | . 05a4a45d 16h Initial commit
-+ feature ⊟ ⋯ ../repo.feature 05a4a45d ⋯ ⋯
++ feature ⊟ ⋯ ⋯ ⋯ ../repo.feature 05a4a45d ⋯ ⋯
+ feature-a ↑ ↑1 ../repo.feature-a 1b87d473 16h Add feature-a file
+ feature-b ↑ ↑1 ../repo.feature-b f62940fc 16h Add feature-b file
+ feature-c ↑ ↑1 ../repo.feature-c 345c7c93 16h Add feature-c file