Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

test(reset): characterize wipe + dry-run before refactor

wlech757d37008f1a
diff --git a/crates/ai-memory-cli/src/commands/reset.rs b/crates/ai-memory-cli/src/commands/reset.rs
index fbaf679a..28088813 100644
--- a/crates/ai-memory-cli/src/commands/reset.rs
+++ b/crates/ai-memory-cli/src/commands/reset.rs
@@ -46,3 +46,62 @@ pub fn run(config: &Config, args: ResetArgs) -> Result<()> {
tracing::info!("reset complete");
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use std::fs;
+ use std::path::Path;
+
+ fn seed(dir: &Path) {
+ for sub in ["wiki", "db", "raw"] {
+ fs::create_dir_all(dir.join(sub)).unwrap();
+ fs::write(dir.join(sub).join("f.txt"), b"x").unwrap();
+ }
+ fs::create_dir_all(dir.join("logs")).unwrap();
+ fs::write(dir.join("logs").join("app.log"), b"log").unwrap();
+ }
+
+ fn config_for(dir: &Path) -> Config {
+ Config {
+ data_dir: dir.to_path_buf(),
+ ..Config::default()
+ }
+ }
+
+ #[test]
+ fn reset_dry_run_leaves_files() {
+ let tmp = tempfile::tempdir().unwrap();
+ seed(tmp.path());
+ run(&config_for(tmp.path()), ResetArgs { confirm: false }).unwrap();
+ assert!(tmp.path().join("wiki/f.txt").exists());
+ assert!(tmp.path().join("db/f.txt").exists());
+ assert!(tmp.path().join("raw/f.txt").exists());
+ }
+
+ #[test]
+ fn reset_apply_wipes_data_keeps_logs() {
+ let tmp = tempfile::tempdir().unwrap();
+ seed(tmp.path());
+ run(&config_for(tmp.path()), ResetArgs { confirm: true }).unwrap();
+ for sub in ["wiki", "db", "raw"] {
+ assert!(tmp.path().join(sub).is_dir(), "{sub} dir should remain");
+ assert!(
+ !tmp.path().join(sub).join("f.txt").exists(),
+ "{sub} emptied"
+ );
+ }
+ assert!(tmp.path().join("logs/app.log").exists(), "logs preserved");
+ }
+
+ #[test]
+ fn reset_apply_skips_absent_subdir() {
+ let tmp = tempfile::tempdir().unwrap();
+ fs::create_dir_all(tmp.path().join("wiki")).unwrap();
+ fs::write(tmp.path().join("wiki/f.txt"), b"x").unwrap();
+ // db/ and raw/ intentionally absent.
+ run(&config_for(tmp.path()), ResetArgs { confirm: true }).unwrap();
+ assert!(!tmp.path().join("wiki/f.txt").exists());
+ assert!(tmp.path().join("wiki").is_dir());
+ }
+}