Skip to content

armgit / herdr

Public Imported from GitHub
0

the runtime your coding agents live on

fix: keep repository parents out of worktree children (#4772)

JJ Liebig6262b49148a4
diff --git a/src/app/actions.rs b/src/app/actions.rs
index 1f571f687..bd3570d85 100644
--- a/src/app/actions.rs
+++ b/src/app/actions.rs
@@ -664,11 +664,15 @@ impl AppState {
}
pub fn close_selected_workspace(&mut self) {
+ let close_indices = self.workspace_close_indices(self.selected);
+ self.close_workspaces(close_indices);
+ }
+
+ pub(crate) fn close_workspaces(&mut self, close_indices: Vec<usize>) {
if self.workspaces.is_empty() {
return;
}
self.mark_session_dirty();
- let close_indices = self.workspace_close_indices(self.selected);
let mut terminal_ids = Vec::new();
let mut pane_ids = Vec::new();
@@ -879,6 +883,20 @@ impl AppState {
}
pub(crate) fn workspace_close_indices(&self, ws_idx: usize) -> Vec<usize> {
+ let group = self.workspace_group_close_indices(ws_idx);
+ if group.iter().any(|index| {
+ *index != ws_idx
+ && self.workspaces[*index]
+ .worktree_space()
+ .is_some_and(|space| !space.is_linked_worktree)
+ }) {
+ vec![ws_idx]
+ } else {
+ group
+ }
+ }
+
+ pub(crate) fn workspace_group_close_indices(&self, ws_idx: usize) -> Vec<usize> {
self.workspaces
.get(ws_idx)
.and_then(|ws| ws.worktree_space())
diff --git a/src/app/api/workspaces.rs b/src/app/api/workspaces.rs
index 9b125e577..4ca7c6bba 100644
--- a/src/app/api/workspaces.rs
+++ b/src/app/api/workspaces.rs
@@ -319,7 +319,11 @@ impl App {
if self.state.workspaces.get(index).is_none() {
return workspace_not_found(id, &params.workspace_id);
}
- let close_indices = self.state.workspace_close_indices(index);
+ let close_indices = if params.close_group {
+ self.state.workspace_group_close_indices(index)
+ } else {
+ self.state.workspace_close_indices(index)
+ };
if close_indices.len() >= 2 && !params.close_group {
return encode_error(
id,
@@ -337,7 +341,7 @@ impl App {
})
.collect::<Vec<_>>();
self.state.selected = index;
- self.state.close_selected_workspace();
+ self.state.close_workspaces(close_indices);
self.shutdown_detached_terminal_runtimes();
for (workspace_id, workspace) in closed_workspaces {
self.emit_event(EventEnvelope {
@@ -625,6 +629,84 @@ mod tests {
}
}
+ #[test]
+ fn duplicate_repo_parents_close_independently_unless_group_is_explicit() {
+ for method in ["workspace.close", "pane.close", "tab.close", "group"] {
+ for target_index in [1, 3] {
+ let mut app = app_with_worktree_group();
+ let parent = app.state.workspaces.remove(0);
+ let linked = app.state.workspaces.remove(0);
+ let mut duplicate = Workspace::test_new("duplicate");
+ duplicate.worktree_space = parent.worktree_space.clone();
+ app.state = crate::app::state::AppState::test_with_adversarial_identity_state();
+ let focused_id = app.state.workspaces[0].id.clone();
+ app.state.workspaces.extend([parent, linked, duplicate]);
+ app.state.ensure_test_terminals();
+ app.state.assert_invariants_for_test();
+ let target_id = app.public_workspace_id(target_index);
+ let target_pane = app.state.workspaces[target_index].tabs[0].root_pane;
+ let target_terminal = app
+ .state
+ .terminal_id_for_pane(target_index, target_pane)
+ .unwrap();
+ let closed_indices = if method == "group" {
+ vec![1, 2, 3]
+ } else {
+ vec![target_index]
+ };
+ let closed_ids = closed_indices
+ .iter()
+ .map(|index| app.public_workspace_id(*index))
+ .collect::<Vec<_>>();
+ let surviving_ids = app
+ .state
+ .workspaces
+ .iter()
+ .enumerate()
+ .filter(|(index, _)| !closed_indices.contains(index))
+ .map(|(_, workspace)| workspace.id.clone())
+ .collect::<Vec<_>>();
+ let request = serde_json::json!({
+ "id": "req",
+ "method": if method == "group" { "workspace.close" } else { method },
+ "params": match method {
+ "pane.close" => serde_json::json!({"pane_id": app.public_pane_id(target_index, target_pane).unwrap()}),
+ "tab.close" => serde_json::json!({"tab_id": app.public_tab_id(target_index, 0).unwrap()}),
+ _ => serde_json::json!({"workspace_id": target_id, "close_group": method == "group"}),
+ }
+ });
+
+ let response = app.handle_api_request(serde_json::from_value(request).unwrap());
+ let _: SuccessResponse = serde_json::from_str(&response).unwrap();
+
+ assert_eq!(
+ app.state
+ .workspaces
+ .iter()
+ .map(|workspace| workspace.id.clone())
+ .collect::<Vec<_>>(),
+ surviving_ids
+ );
+ assert_eq!(
+ app.state.workspaces[app.state.active.unwrap()].id,
+ focused_id
+ );
+ assert!(!app.state.terminals.contains_key(&target_terminal));
+ app.state.assert_invariants_for_test();
+ let closed_events = app
+ .event_hub
+ .events_after(0)
+ .into_iter()
+ .filter_map(|(_, event)| match event.data {
+ EventData::WorkspaceClosed { workspace_id, .. } => Some(workspace_id),
+ _ => None,
+ })
+ .collect::<Vec<_>>();
+ assert_eq!(closed_events, closed_ids);
+ }
+ }
+ }
+
#[test]
fn api_workspace_close_noncontiguous_group_preserves_adversarial_identity_state() {
let mut app = app_with_worktree_group();
diff --git a/src/client/shell/actions.rs b/src/client/shell/actions.rs
index 9d0a3bd5d..25878ceee 100644
--- a/src/client/shell/actions.rs
+++ b/src/client/shell/actions.rs
@@ -107,19 +107,7 @@ impl ClientShellState {
}
if action == crate::input::KeybindAction::CloseWorkspace {
if let Some(workspace_id) = self.workspace_action_id() {
- if self.config.confirm_close {
- self.open_confirm_close_overlay(workspace_id);
- } else {
- self.push_endpoint_method(
- crate::api::schema::Method::WorkspaceClose(
- crate::api::schema::WorkspaceCloseParams {
- workspace_id,
- close_group: true,
- },
- ),
- outcome,
- );
- }
+ self.request_workspace_close(workspace_id, None, outcome);
}
outcome.repaint = true;
return;
diff --git a/src/client/shell/context_menu.rs b/src/client/shell/context_menu.rs
index b57bc8436..f7d875562 100644
--- a/src/client/shell/context_menu.rs
+++ b/src/client/shell/context_menu.rs
@@ -29,11 +29,15 @@ impl ClientContextMenuOverlay {
],
ClientContextMenuTarget::Workspace {
has_worktree_children: true,
+ close_group,
collapsed,
..
} => vec![
item("Rename", Action::Rename),
- item("Close group", Action::Close),
+ item(
+ if *close_group { "Close group" } else { "Close" },
+ Action::Close,
+ ),
item("New worktree", Action::NewWorktree),
item("Open worktree...", Action::OpenWorktree),
item(
@@ -94,18 +98,13 @@ impl ClientShellState {
let worktree = workspace.worktree.as_ref();
let has_worktree_children = worktree.is_some_and(|worktree| {
!worktree.is_linked_worktree
- && snapshot
- .workspaces
- .iter()
- .filter(|candidate| {
- candidate
- .worktree
- .as_ref()
- .is_some_and(|candidate| candidate.key == worktree.key)
+ && snapshot.workspaces.iter().any(|candidate| {
+ candidate.worktree.as_ref().is_some_and(|candidate| {
+ candidate.key == worktree.key && candidate.is_linked_worktree
})
- .count()
- >= 2
+ })
});
+ let close_group = super::sidebar::workspace_close_is_group(snapshot, workspace);
let collapsed = worktree.is_some_and(|worktree| {
self.group_is_collapsed(&self.active_endpoint_id, &worktree.key)
});
@@ -115,6 +114,7 @@ impl ClientShellState {
is_git: worktree.is_some() || workspace.branch.is_some(),
is_linked_worktree: worktree.is_some_and(|worktree| worktree.is_linked_worktree),
has_worktree_children,
+ close_group,
collapsed,
},
x,
@@ -192,9 +192,11 @@ impl ClientShellState {
return;
};
match menu.target {
- ClientContextMenuTarget::Workspace { workspace_id, .. } => {
- self.activate_workspace_context_action(workspace_id, action, outcome)
- }
+ ClientContextMenuTarget::Workspace {
+ workspace_id,
+ close_group,
+ ..
+ } => self.activate_workspace_context_action(workspace_id, close_group, action, outcome),
ClientContextMenuTarget::Tab {
tab_id,
workspace_id,
@@ -220,6 +222,7 @@ impl ClientShellState {
fn activate_workspace_context_action(
&mut self,
workspace_id: String,
+ close_group: bool,
action: ClientContextMenuAction,
outcome: &mut ClientShellInput,
) {
@@ -246,19 +249,7 @@ impl ClientShellState {
}
}
ClientContextMenuAction::Close => {
- if self.config.confirm_close {
- self.open_confirm_close_overlay(workspace_id);
- } else {
- self.push_endpoint_method(
- crate::api::schema::Method::WorkspaceClose(
- crate::api::schema::WorkspaceCloseParams {
- workspace_id,
- close_group: true,
- },
- ),
- outcome,
- );
- }
+ self.request_workspace_close(workspace_id, Some(close_group), outcome);
}
ClientContextMenuAction::NewWorktree => {
self.begin_worktree_action_for(KeybindAction::NewWorktree, workspace_id, outcome)
diff --git a/src/client/shell/mouse.rs b/src/client/shell/mouse.rs
index f2df29410..b2d7d91a2 100644
--- a/src/client/shell/mouse.rs
+++ b/src/client/shell/mouse.rs
@@ -518,14 +518,27 @@ impl ClientShellState {
{
return None;
}
+ let snapshot = self.snapshot.as_deref()?;
let mut slots = self
.hits
.workspaces
.iter()
.filter(|hit| hit.endpoint_id == self.active_endpoint_id && !hit.indented)
+ .filter(|hit| {
+ hit.group_toggle.as_ref().is_none_or(|(_, key)| {
+ snapshot
+ .workspaces
+ .iter()
+ .find(|workspace| {
+ workspace.worktree.as_ref().is_some_and(|worktree| {
+ worktree.key == *key && !worktree.is_linked_worktree
+ })
+ })
+ .is_some_and(|workspace| workspace.workspace_id == hit.workspace_id)
+ })
+ })
.map(|hit| (Some(hit.workspace_id.clone()), hit.rect.y.saturating_sub(1)))
.collect::<Vec<_>>();
- let snapshot = self.snapshot.as_deref()?;
let empty_collapsed_groups = HashSet::new();
let collapsed_groups = self
.collapsed_groups_for_endpoint(&self.active_endpoint_id)
@@ -544,7 +557,15 @@ impl ClientShellState {
.is_some_and(|workspace| workspace.workspace_id == last_hit.workspace_id)
})?;
let next = entries.get(last_position + 1);
- if !next.is_some_and(|entry| entry.indented) {
+ if !next.is_some_and(|entry| {
+ entry.indented
+ || last_hit.group_toggle.as_ref().is_some_and(|(_, key)| {
+ snapshot.workspaces[entry.index]
+ .worktree
+ .as_ref()
+ .is_some_and(|worktree| worktree.key == *key)
+ })
+ }) {
let before = next.and_then(|entry| {
snapshot
.workspaces
@@ -607,7 +628,7 @@ impl ClientShellState {
.position(|workspace| workspace.workspace_id == target)?,
None => remaining.len(),
};
- if insert_position == source_position {
+ if source.worktree.is_none() && insert_position == source_position {
return None;
}
@@ -626,7 +647,11 @@ impl ClientShellState {
})
.map(|workspace| workspace.workspace_id.clone()),
)
- .collect();
+ .collect::<Vec<_>>();
+ if before_workspace_id.is_some_and(|target| workspace_ids.iter().any(|id| id == target))
+ {
+ return None;
+ }
Some(crate::api::schema::Method::WorkspaceMoveBlock(
crate::api::schema::WorkspaceMoveBlockParams {
workspace_ids,
diff --git a/src/client/shell/overlay_input.rs b/src/client/shell/overlay_input.rs
index 10bd4a454..653826a64 100644
--- a/src/client/shell/overlay_input.rs
+++ b/src/client/shell/overlay_input.rs
@@ -987,6 +987,33 @@ impl ClientShellState {
outcome.repaint = true;
}
+ pub(super) fn request_workspace_close(
+ &mut self,
+ workspace_id: String,
+ close_group: Option<bool>,
+ outcome: &mut ClientShellInput,
+ ) {
+ if self.config.confirm_close {
+ self.open_close_confirmation(workspace_id, None, close_group);
+ return;
+ }
+ let close_group = close_group.unwrap_or_else(|| {
+ self.snapshot.as_deref().is_some_and(|snapshot| {
+ snapshot.workspaces.iter().any(|workspace| {
+ workspace.workspace_id == workspace_id
+ && super::sidebar::workspace_close_is_group(snapshot, workspace)
+ })
+ })
+ });
+ self.push_endpoint_method(
+ crate::api::schema::Method::WorkspaceClose(crate::api::schema::WorkspaceCloseParams {
+ workspace_id,
+ close_group,
+ }),
+ outcome,
+ );
+ }
+
pub(super) fn request_tab_close(&mut self, tab_id: String, outcome: &mut ClientShellInput) {
let workspace_id = self.snapshot.as_deref().and_then(|snapshot| {
let target = snapshot.tabs.iter().find(|tab| tab.tab_id == tab_id)?;
@@ -998,7 +1025,7 @@ impl ClientShellState {
.then(|| target.workspace_id.clone())
});
if let Some(workspace_id) = workspace_id {
- if self.open_close_confirmation(workspace_id, Some(tab_id.clone())) {
+ if self.open_close_confirmation(workspace_id, Some(tab_id.clone()), None) {
outcome.repaint = true;
return;
}
@@ -1035,17 +1062,22 @@ impl ClientShellState {
} else {
crate::api::schema::Method::WorkspaceClose(crate::api::schema::WorkspaceCloseParams {
workspace_id: confirm.workspace_id,
- close_group: true,
+ close_group: confirm.close_group,
})
};
self.push_endpoint_method(method, outcome);
}
pub(super) fn open_confirm_close_overlay(&mut self, workspace_id: String) {
- self.open_close_confirmation(workspace_id, None);
+ self.open_close_confirmation(workspace_id, None, None);
}
- fn open_close_confirmation(&mut self, workspace_id: String, tab_id: Option<String>) -> bool {
+ fn open_close_confirmation(
+ &mut self,
+ workspace_id: String,
+ tab_id: Option<String>,
+ close_group: Option<bool>,
+ ) -> bool {
let Some(snapshot) = self.snapshot.as_deref() else {
return false;
};
@@ -1059,7 +1091,11 @@ impl ClientShellState {
let group_key = workspace
.worktree
.as_ref()
- .filter(|worktree| !worktree.is_linked_worktree)
+ .filter(|_| {
+ close_group.unwrap_or_else(|| {
+ super::sidebar::workspace_close_is_group(snapshot, workspace)
+ })
+ })
.map(|worktree| worktree.key.as_str());
let group = group_key
.map(|key| {
@@ -1112,6 +1148,7 @@ impl ClientShellState {
self.overlay = Some(ClientShellOverlay::ConfirmClose(
ClientConfirmCloseOverlay {
workspace_id,
+ close_group: closes_group,
tab_target,
title: if closes_group {
"Close worktree group?".to_owned()
diff --git a/src/client/shell/sidebar.rs b/src/client/shell/sidebar.rs
index f94f6bdcf..46c3a1a06 100644
--- a/src/client/shell/sidebar.rs
+++ b/src/client/shell/sidebar.rs
@@ -468,13 +468,17 @@ pub(crate) fn workspace_entries(
let grouped = members
.iter()
.filter(|(_, indices)| {
- indices.len() >= 2
- && indices.iter().any(|index| {
- snapshot.workspaces[*index]
- .worktree
- .as_ref()
- .is_some_and(|worktree| !worktree.is_linked_worktree)
- })
+ indices.iter().any(|index| {
+ snapshot.workspaces[*index]
+ .worktree
+ .as_ref()
+ .is_some_and(|worktree| worktree.is_linked_worktree)
+ }) && indices.iter().any(|index| {
+ snapshot.workspaces[*index]
+ .worktree
+ .as_ref()
+ .is_some_and(|worktree| !worktree.is_linked_worktree)
+ })
})
.map(|(key, _)| *key)
.collect::<HashSet<_>>();
@@ -499,27 +503,27 @@ pub(crate) fn workspace_entries(
let Some(group_members) = members.get(worktree.key.as_str()) else {
continue;
};
- let parent = group_members
- .iter()
- .copied()
- .find(|member| {
- snapshot.workspaces[*member]
- .worktree
- .as_ref()
- .is_some_and(|worktree| !worktree.is_linked_worktree)
- })
- .unwrap_or(index);
- entries.push(WorkspaceEntry {
- index: parent,
- indented: false,
- last_child: false,
- });
+ for parent in group_members.iter().copied().filter(|member| {
+ snapshot.workspaces[*member]
+ .worktree
+ .as_ref()
+ .is_some_and(|worktree| !worktree.is_linked_worktree)
+ }) {
+ entries.push(WorkspaceEntry {
+ index: parent,
+ indented: false,
+ last_child: false,
+ });
+ }
if collapsed_groups.contains(&worktree.key) {
- if let Some(active) = group_members
- .iter()
- .copied()
- .find(|member| *member != parent && snapshot.workspaces[*member].focused)
- {
+ if let Some(active) = group_members.iter().copied().find(|member| {
+ let workspace = &snapshot.workspaces[*member];
+ workspace.focused
+ && workspace
+ .worktree
+ .as_ref()
+ .is_some_and(|worktree| worktree.is_linked_worktree)
+ }) {
entries.push(WorkspaceEntry {
index: active,
indented: true,
@@ -531,7 +535,12 @@ pub(crate) fn workspace_entries(
let children = group_members
.iter()
.copied()
- .filter(|member| *member != parent)
+ .filter(|member| {
+ snapshot.workspaces[*member]
+ .worktree
+ .as_ref()
+ .is_some_and(|worktree| worktree.is_linked_worktree)
+ })
.collect::<Vec<_>>();
for (child_index, child) in children.iter().enumerate() {
entries.push(WorkspaceEntry {
@@ -550,20 +559,47 @@ fn parent_group_key(snapshot: &ClientShellSnapshot, index: usize) -> Option<Stri
if worktree.is_linked_worktree {
return None;
}
- (snapshot
+ snapshot
.workspaces
.iter()
- .filter(|candidate| {
- candidate
- .worktree
- .as_ref()
- .is_some_and(|candidate| candidate.key == worktree.key)
+ .any(|candidate| {
+ candidate.worktree.as_ref().is_some_and(|candidate| {
+ candidate.key == worktree.key && candidate.is_linked_worktree
+ })
})
- .count()
- >= 2)
.then(|| worktree.key.clone())
}
+pub(in crate::client::shell) fn workspace_close_is_group(
+ snapshot: &ClientShellSnapshot,
+ workspace: &ClientShellWorkspace,
+) -> bool {
+ let Some(worktree) = workspace
+ .worktree
+ .as_ref()
+ .filter(|worktree| !worktree.is_linked_worktree)
+ else {
+ return false;
+ };
+ let mut has_child = false;
+ for member in &snapshot.workspaces {
+ if member.workspace_id == workspace.workspace_id {
+ continue;
+ }
+ if let Some(candidate) = member
+ .worktree
+ .as_ref()
+ .filter(|candidate| candidate.key == worktree.key)
+ {
+ if !candidate.is_linked_worktree {
+ return false;
+ }
+ has_child = true;
+ }
+ }
+ has_child
+}
+
pub(in crate::client::shell) fn render_parent_group_toggle(
buffer: &mut Buffer,
workspace_rect: Rect,
@@ -613,10 +649,11 @@ pub(in crate::client::shell) fn displayed_workspace_status(
.workspaces
.iter()
.filter(|candidate| {
- candidate
- .worktree
- .as_ref()
- .is_some_and(|candidate| candidate.key == worktree.key)
+ candidate.worktree.as_ref().is_some_and(|member| {
+ member.key == worktree.key
+ && (member.is_linked_worktree
+ || candidate.workspace_id == workspace.workspace_id)
+ })
})
.map(|candidate| candidate.agent_status)
.max_by_key(|status| status_priority(*status))
diff --git a/src/client/shell/state.rs b/src/client/shell/state.rs
index c170c9b08..8c1d6f343 100644
--- a/src/client/shell/state.rs
+++ b/src/client/shell/state.rs
@@ -534,6 +534,7 @@ pub(super) enum ClientContextMenuTarget {
is_git: bool,
is_linked_worktree: bool,
has_worktree_children: bool,
+ close_group: bool,
collapsed: bool,
},
Tab {
@@ -571,6 +572,7 @@ pub(super) struct ClientTabCloseConfirmation {
#[derive(Debug)]
pub(super) struct ClientConfirmCloseOverlay {
pub(super) workspace_id: String,
+ pub(super) close_group: bool,
pub(super) tab_target: Option<ClientTabCloseConfirmation>,
pub(super) title: String,
pub(super) detail: String,
diff --git a/src/client/shell/tests/agents_worktrees_notifications.rs b/src/client/shell/tests/agents_worktrees_notifications.rs
index 5b8b12243..df09f464a 100644
--- a/src/client/shell/tests/agents_worktrees_notifications.rs
+++ b/src/client/shell/tests/agents_worktrees_notifications.rs
@@ -170,6 +170,125 @@ fn grouped_worktrees_render_parent_branch_and_indented_child() {
));
}
+#[test]
+fn duplicate_repo_parents_remain_visible_and_focusable_when_collapsed() {
+ for linked_child in [false, true] {
+ let mut projected = snapshot();
+ projected.workspaces[0].agent_status = AgentStatus::Idle;
+ projected.workspaces[0].worktree = Some(ClientShellWorktree {
+ key: "repo".into(),
+ label: "repo".into(),
+ is_linked_worktree: false,
+ });
+ let mut duplicate = projected.workspaces[0].clone();
+ duplicate.workspace_id = "ws_duplicate".into();
+ duplicate.label = "duplicate-repo".into();
+ duplicate.focused = false;
+ duplicate.agent_status = AgentStatus::Blocked;
+ projected.workspaces.push(duplicate);
+ if linked_child {
+ let mut child = projected.workspaces[0].clone();
+ child.workspace_id = "ws_child".into();
+ child.focused = false;
+ child.worktree.as_mut().unwrap().is_linked_worktree = true;
+ projected.workspaces.push(child);
+ }
+
+ let mut state = ClientShellState::new(ClientShellConfig::from_config(&Config::default()));
+ state.set_snapshot(Box::new(projected));
+ state.set_pane_surface(surface());
+ for collapsed in [false, true] {
+ if collapsed {
+ state.collapsed_groups.insert("repo".into());
+ }
+ let frame = state
+ .compose(106, 24)
+ .expect("duplicate repository parents");
+ for workspace_id in ["ws_1", "ws_duplicate"] {
+ let hit = state
+ .hits
+ .workspaces
+ .iter()
+ .find(|hit| hit.workspace_id == workspace_id)
+ .expect("repository parent remains visible");
+ assert!(!hit.indented);
+ assert_eq!(hit.group_toggle.is_some(), linked_child);
+ }
+ let parent = state.hits.workspaces[0].rect;
+ let status_cell =
+ usize::from(parent.y) * usize::from(frame.width) + usize::from(parent.x + 1);
+ assert_ne!(
+ frame.cells[status_cell].fg,
+ crate::protocol::color_to_u32(state.config.palette.red)
+ );
+ assert_eq!(
+ state
+ .hits
+ .workspaces
+ .iter()
+ .any(|hit| hit.workspace_id == "ws_child" && hit.indented),
+ linked_child && !collapsed
+ );
+ let duplicate = state.hits.workspaces[1].rect;
+ state.handle_raw_events(vec![RawInputEvent::Mouse(MouseEvent {
+ kind: MouseEventKind::Down(MouseButton::Left),
+ column: duplicate.x + 2,
+ row: duplicate.y,
+ modifiers: KeyModifiers::empty(),
+ })]);
+ let click = state.handle_raw_events(vec![RawInputEvent::Mouse(MouseEvent {
+ kind: MouseEventKind::Up(MouseButton::Left),
+ column: duplicate.x + 2,
+ row: duplicate.y,
+ modifiers: KeyModifiers::empty(),
+ })]);
+ assert!(matches!(click.actions.as_slice(),
+ [ClientShellAction::Endpoint { request, .. }]
+ if matches!(&request.method, crate::api::schema::Method::WorkspaceFocus(target)
+ if target.workspace_id == "ws_duplicate")));
+ }
+ let original = state.snapshot.as_deref().unwrap().clone();
+ for confirm_close in [false, true] {
+ let mut restored = original.clone();
+ restored.revision = state.snapshot.as_deref().unwrap().revision + 1;
+ state.set_snapshot(Box::new(restored));
+ state.config.confirm_close = confirm_close;
+ state.open_workspace_context_menu("ws_duplicate".into(), 0, 0);
+ let Some(ClientShellOverlay::ContextMenu(menu)) = state.overlay.as_ref() else {
+ panic!("repository workspace context menu");
+ };
+ assert_eq!(menu.items()[1].label, "Close");
+ assert_eq!(
+ menu.items()
+ .iter()
+ .any(|item| matches!(item.action, ClientContextMenuAction::ToggleGroup)),
+ linked_child
+ );
+ if linked_child {
+ let mut replacement = original.clone();
+ replacement.revision = state.snapshot.as_deref().unwrap().revision + 1;
+ replacement
+ .workspaces
+ .retain(|workspace| workspace.workspace_id != "ws_1");
+ state.set_snapshot(Box::new(replacement));
+ }
+ let mut close = ClientShellInput::default();
+ state.activate_context_menu_item(1, &mut close);
+ if confirm_close {
+ assert!(close.actions.is_empty());
+ assert!(matches!(state.overlay.as_ref(),
+ Some(ClientShellOverlay::ConfirmClose(confirm))
+ if confirm.title == "Close workspace?" && !confirm.close_group));
+ close = state.handle_input_bytes(b"\r");
+ }
+ assert!(matches!(close.actions.as_slice(),
+ [ClientShellAction::Endpoint { request, .. }]
+ if matches!(&request.method, crate::api::schema::Method::WorkspaceClose(params)
+ if params.workspace_id == "ws_duplicate" && !params.close_group)));
+ }
+ }
+}
+
#[test]
fn workspace_click_waits_for_release_and_drag_reorders_by_stable_id() {
let mut projected = snapshot();
@@ -257,6 +376,59 @@ fn workspace_click_waits_for_release_and_drag_reorders_by_stable_id() {
));
}
+#[test]
+fn duplicate_repo_parent_drag_does_not_target_its_own_move_block() {
+ let mut projected = snapshot();
+ projected.workspaces[0].worktree = Some(ClientShellWorktree {
+ key: "repo".into(),
+ label: "repo".into(),
+ is_linked_worktree: false,
+ });
+ let mut other = projected.workspaces[0].clone();
+ other.workspace_id = "ws_other".into();
+ other.worktree = None;
+ other.focused = false;
+ let mut duplicate = projected.workspaces[0].clone();
+ duplicate.workspace_id = "ws_duplicate".into();
+ duplicate.focused = false;
+ projected.workspaces.extend([other, duplicate]);
+ let mut state = ClientShellState::new(ClientShellConfig::from_config(&Config::default()));
+ state.set_snapshot(Box::new(projected));
+ state.set_pane_surface(surface());
+ state
+ .compose(106, 24)
+ .expect("separated repository parents");
+ let source = state.hits.workspaces[0].rect;
+ let target = state.hits.workspaces[2].rect;
+ for (kind, rect, row) in [
+ (MouseEventKind::Down(MouseButton::Left), source, source.y),
+ (
+ MouseEventKind::Drag(MouseButton::Left),
+ target,
+ target.y.saturating_sub(1),
+ ),
+ ] {
+ state.handle_raw_events(vec![RawInputEvent::Mouse(MouseEvent {
+ kind,
+ column: rect.x + 2,
+ row,
+ modifiers: KeyModifiers::empty(),
+ })]);
+ }
+ assert!(
+ matches!(state.chrome_drag.as_ref(), Some(ClientChromeDrag::Workspace {
+ target: Some((Some(workspace_id), _)), ..
+ }) if workspace_id == "ws_duplicate")
+ );
+ let drop = state.handle_raw_events(vec![RawInputEvent::Mouse(MouseEvent {
+ kind: MouseEventKind::Up(MouseButton::Left),
+ column: target.x + 2,
+ row: target.y.saturating_sub(1),
+ modifiers: KeyModifiers::empty(),
+ })]);
+ assert!(drop.actions.is_empty());
+}
+
#[test]
fn workspace_drag_moves_parent_worktree_as_one_block_and_rejects_child() {
let mut projected = snapshot();
@@ -337,6 +509,54 @@ fn workspace_drag_moves_parent_worktree_as_one_block_and_rejects_child() {
})]);
assert!(dragging_child.actions.is_empty());
assert!(state.chrome_drag.is_none());
+
+ let mut projected = state.snapshot.as_deref().unwrap().clone();
+ let mut duplicate = projected.workspaces[0].clone();
+ duplicate.workspace_id = "ws_duplicate".into();
+ duplicate.focused = false;
+ projected.workspaces.push(duplicate);
+ state = ClientShellState::new(ClientShellConfig::from_config(&Config::default()));
+ state.set_snapshot(Box::new(projected));
+ state.set_pane_surface(surface());
+ state
+ .compose(106, 24)
+ .expect("repository block with duplicate root");
+ let duplicate = state.hits.workspaces[1].rect;
+ let other = state.hits.workspaces[3].rect;
+ for (source, target_row, moving_duplicate) in [
+ (other, duplicate.y.saturating_sub(1), false),
+ (duplicate, other.bottom(), true),
+ ] {
+ state.handle_raw_events(vec![RawInputEvent::Mouse(MouseEvent {
+ kind: MouseEventKind::Down(MouseButton::Left),
+ column: source.x + 2,
+ row: source.y,
+ modifiers: KeyModifiers::empty(),
+ })]);
+ state.handle_raw_events(vec![RawInputEvent::Mouse(MouseEvent {
+ kind: MouseEventKind::Drag(MouseButton::Left),
+ column: source.x + 2,
+ row: target_row,
+ modifiers: KeyModifiers::empty(),
+ })]);
+ let moved = state.handle_raw_events(vec![RawInputEvent::Mouse(MouseEvent {
+ kind: MouseEventKind::Up(MouseButton::Left),
+ column: source.x + 2,
+ row: target_row,
+ modifiers: KeyModifiers::empty(),
+ })]);
+ if moving_duplicate {
+ assert!(matches!(moved.actions.as_slice(),
+ [ClientShellAction::Endpoint { request, .. }]
+ if matches!(&request.method, crate::api::schema::Method::WorkspaceMoveBlock(params)
+ if params.workspace_ids == ["ws_duplicate", "ws_1", "ws_child"] && params.before_workspace_id.is_none())));
+ } else {
+ assert!(matches!(moved.actions.as_slice(),
+ [ClientShellAction::Endpoint { request, .. }]
+ if matches!(&request.method, crate::api::schema::Method::WorkspaceMove(params)
+ if params.workspace_id == "ws_other" && params.insert_index == 0)));
+ }
+ }
}
#[test]
@@ -855,7 +1075,7 @@ fn workspace_actions_preserve_selected_target_and_client_confirmation() {
assert!(matches!(
&request.method,
crate::api::schema::Method::WorkspaceClose(params)
- if params.workspace_id == "ws_2" && params.close_group
+ if params.workspace_id == "ws_2" && !params.close_group
));
}
diff --git a/src/client/shell/tests/chrome_context.rs b/src/client/shell/tests/chrome_context.rs
index ed21bc8a7..1e1d5fc35 100644
--- a/src/client/shell/tests/chrome_context.rs
+++ b/src/client/shell/tests/chrome_context.rs
@@ -474,7 +474,7 @@ fn new_tab_overlay_owns_text_cursor_and_submits_public_api_request() {
}
#[test]
-fn close_confirmation_error_becomes_client_owned_overlay_and_stable_group_close() {
+fn close_confirmation_error_becomes_client_owned_overlay_and_stable_workspace_close() {
let mut state = ClientShellState::new(ClientShellConfig::from_config(&Config::default()));
state.set_snapshot(Box::new(snapshot()));
state.set_pane_surface(surface());
@@ -520,6 +520,6 @@ fn close_confirmation_error_becomes_client_owned_overlay_and_stable_group_close(
assert!(matches!(
&request.method,
crate::api::schema::Method::WorkspaceClose(params)
- if params.workspace_id == "ws_1" && params.close_group
+ if params.workspace_id == "ws_1" && !params.close_group
));
}
diff --git a/src/client/shell/tests/graphics.rs b/src/client/shell/tests/graphics.rs
index e54301a44..6622e3d8b 100644
--- a/src/client/shell/tests/graphics.rs
+++ b/src/client/shell/tests/graphics.rs
@@ -258,6 +258,7 @@ fn every_dialog_and_menu_occludes_its_panel_not_the_whole_screen() {
}),
ClientShellOverlay::ConfirmClose(ClientConfirmCloseOverlay {
workspace_id: "ws_1".into(),
+ close_group: false,
tab_target: None,
title: "close".into(),
detail: "confirm".into(),