From 8426885c8327d2b09c3525065a7ece24e5a42388 Mon Sep 17 00:00:00 2001 From: Bortlesboat Date: Mon, 11 May 2026 14:51:01 -0400 Subject: [PATCH] fix: include purge data directories --- src/cortex-cli/src/agent_cmd/tests.rs | 5 +-- src/cortex-cli/src/uninstall_cmd.rs | 53 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/cortex-cli/src/agent_cmd/tests.rs b/src/cortex-cli/src/agent_cmd/tests.rs index e2ff07f9f..18f7ba753 100644 --- a/src/cortex-cli/src/agent_cmd/tests.rs +++ b/src/cortex-cli/src/agent_cmd/tests.rs @@ -3,10 +3,9 @@ #[cfg(test)] mod tests { use crate::agent_cmd::cli::{CopyArgs, ExportArgs}; - use crate::agent_cmd::loader::{ - load_builtin_agents, parse_frontmatter, read_file_with_encoding, - }; + use crate::agent_cmd::loader::{load_builtin_agents, parse_frontmatter}; use crate::agent_cmd::types::AgentMode; + use crate::utils::file::read_file_with_encoding; #[test] fn test_read_file_with_utf8() { diff --git a/src/cortex-cli/src/uninstall_cmd.rs b/src/cortex-cli/src/uninstall_cmd.rs index aa4db4306..a9061c430 100644 --- a/src/cortex-cli/src/uninstall_cmd.rs +++ b/src/cortex-cli/src/uninstall_cmd.rs @@ -439,6 +439,30 @@ fn collect_cortex_home_items(home_dir: &Path) -> Result> { }); } + // Delegates directory + let delegates_dir = cortex_home.join("delegates"); + if delegates_dir.exists() { + items.push(RemovalItem { + path: delegates_dir.clone(), + description: "Delegate data".to_string(), + size: get_dir_size(&delegates_dir), + requires_sudo: false, + category: RemovalCategory::Data, + }); + } + + // Snapshots directory + let snapshots_dir = cortex_home.join("snapshots"); + if snapshots_dir.exists() { + items.push(RemovalItem { + path: snapshots_dir.clone(), + description: "Snapshot data".to_string(), + size: get_dir_size(&snapshots_dir), + requires_sudo: false, + category: RemovalCategory::Data, + }); + } + // Plugins directory let plugins_dir = cortex_home.join("plugins"); if plugins_dir.exists() { @@ -976,4 +1000,33 @@ mod tests { | InstallMethod::Unknown => {} } } + + #[test] + fn test_collect_cortex_home_items_includes_delegate_and_snapshot_dirs() { + let temp_home = tempfile::tempdir().unwrap(); + let cortex_home = temp_home.path().join(".cortex"); + + for dir_name in ["sessions", "delegates", "snapshots"] { + let dir = cortex_home.join(dir_name); + fs::create_dir_all(&dir).unwrap(); + fs::write(dir.join("marker.txt"), "test\n").unwrap(); + } + + let items = collect_cortex_home_items(temp_home.path()).unwrap(); + + assert!( + items + .iter() + .any(|item| item.path == cortex_home.join("sessions")), + "control sessions directory should be collected" + ); + + for dir_name in ["delegates", "snapshots"] { + let item = items + .iter() + .find(|item| item.path == cortex_home.join(dir_name)) + .unwrap_or_else(|| panic!("{dir_name} directory should be collected")); + assert_eq!(item.category, RemovalCategory::Data); + } + } }