Skip to content

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

Rust

docs(uninstall): scope coverage to changed lines (diff-cover); add apply+purge happy-path test

wlechf4e5497d75be
diff --git a/docs/superpowers/plans/2026-05-25-uninstall-dryrun-purge-preview.md b/docs/superpowers/plans/2026-05-25-uninstall-dryrun-purge-preview.md
index eef74080..8bdb50c9 100644
--- a/docs/superpowers/plans/2026-05-25-uninstall-dryrun-purge-preview.md
+++ b/docs/superpowers/plans/2026-05-25-uninstall-dryrun-purge-preview.md
@@ -398,11 +398,58 @@ This removes the `purge_refused` flag, the mid-flow `sibling_processes()` check,
Run: `cargo test -p ai-memory-cli --test uninstall`
Expected: the existing tests pass (none use `--purge-data`, so the apply rewrite must not regress them).
-- [ ] **Step 4: Commit**
+- [ ] **Step 4: Append the apply+purge happy-path test (covers the new apply lines)**
+
+At the end of `crates/ai-memory-cli/tests/uninstall.rs`:
+
+```rust
+#[test]
+fn uninstall_purge_data_apply_wipes() {
+ let home = tempfile::tempdir().unwrap();
+ let data = tempfile::tempdir().unwrap();
+ for sub in ["wiki", "db", "raw"] {
+ std::fs::create_dir_all(data.path().join(sub)).unwrap();
+ std::fs::write(data.path().join(sub).join("f.txt"), b"x").unwrap();
+ }
+ std::fs::create_dir_all(data.path().join("logs")).unwrap();
+ std::fs::write(data.path().join("logs/app.log"), b"l").unwrap();
+
+ let out = Command::new(bin())
+ .args(["uninstall", "--apply", "--yes", "--purge-data"])
+ .env("HOME", home.path())
+ .env("AI_MEMORY_DATA_DIR", data.path())
+ .output()
+ .unwrap();
+ assert!(
+ out.status.success(),
+ "stderr: {}",
+ String::from_utf8_lossy(&out.stderr)
+ );
+
+ for sub in ["wiki", "db", "raw"] {
+ assert!(data.path().join(sub).is_dir(), "{sub} dir should remain");
+ assert!(!data.path().join(sub).join("f.txt").exists(), "{sub} emptied");
+ }
+ assert!(data.path().join("logs/app.log").exists(), "logs preserved");
+ let stdout = String::from_utf8(out.stdout).unwrap();
+ assert!(stdout.contains("✓ purged"), "stdout was: {stdout}");
+}
+```
+
+> Note: relies on no concurrent sibling `ai-memory` process tripping the guard.
+> If this flakes under parallel test load, serialize it (e.g. a file lock) or
+> add a short retry; do not weaken the assertions.
+
+- [ ] **Step 5: Run — must PASS**
+
+Run: `cargo test -p ai-memory-cli --test uninstall uninstall_purge_data_apply_wipes`
+Expected: PASS (data wiped, logs kept, `✓ purged` printed).
+
+- [ ] **Step 6: Commit**
```bash
-git add crates/ai-memory-cli/src/commands/uninstall.rs
-git commit -m "feat(uninstall): all-or-nothing --purge-data guard + shared wipe"
+git add crates/ai-memory-cli/src/commands/uninstall.rs crates/ai-memory-cli/tests/uninstall.rs
+git commit -m "feat(uninstall): all-or-nothing --purge-data guard + shared wipe; apply test"
```
---
@@ -569,15 +616,20 @@ git commit -m "test(uninstall): ignored best-effort guard-refusal test"
**Files:**
- Modify: `CHANGELOG.md`
-- [ ] **Step 1: Install + run coverage**
+- [ ] **Step 1: Install tooling + measure CHANGED-LINE coverage (diff vs main)**
```bash
cargo install cargo-llvm-cov # one-time; pulls llvm-tools-preview if needed
-cargo llvm-cov --summary-only -p ai-memory-cli 2>/dev/null \
- | grep -E "data_purge.rs|reset.rs|uninstall.rs"
+pipx install diff_cover || pip install --user diff-cover # one-time
+cargo llvm-cov --cobertura --output-path target/cov.xml -p ai-memory-cli
+diff-cover target/cov.xml --compare-branch main
```
-Expected: per-file **line** coverage — `data_purge.rs` ≥ 90% (critical logic), `reset.rs`/`uninstall.rs` ≥ 80%. If any touched file is below target, add a focused test (e.g. an extra `data_purge` edge case, or an `uninstall --only` dry-run preview assertion) until it clears, then re-run.
+Expected: on the **changed lines only**, `data_purge` (critical logic) ≥ 90%
+(its unit tests cover ~100%), and changed lines in `reset::run` / `uninstall::run`
+≥ 80%. The single expected miss is the option-B `bail!` line in `uninstall`
+(only the `#[ignore]` sibling test reaches it). If anything else changed is
+uncovered, add a focused test until it clears, then re-run.
- [ ] **Step 2: Add CHANGELOG entry**
@@ -613,7 +665,7 @@ git commit -m "docs(changelog): uninstall dry-run purge preview + all-or-nothing
## Self-review
-- **Spec coverage:** dry-run preview → Task 5; shared mute helper (`WIPE_SUBDIRS`/`purge_preview`/`purge_data_dirs`, `anyhow::Result` + context) → Task 2; `reset` uses it, wording/tracing kept → Task 3; `uninstall` uses it + option B up-front guard, `purge_refused` removed → Task 4; characterization-first for untested `reset` → Task 1; coverage 90/80 line, local → Task 7; `#[ignore]` guard test per H3 → Task 6; CHANGELOG → Task 7. All spec sections map to a task.
+- **Spec coverage:** dry-run preview → Task 5; shared mute helper (`WIPE_SUBDIRS`/`purge_preview`/`purge_data_dirs`, `anyhow::Result` + context) → Task 2; `reset` uses it, wording/tracing kept → Task 3; `uninstall` uses it + option B up-front guard, `purge_refused` removed → Task 4; characterization-first for untested `reset` → Task 1; apply+purge happy-path test (covers new apply lines) → Task 4; changed-line coverage 90/80 via `diff-cover` vs main, local → Task 7; `#[ignore]` guard test per H3 → Task 6; CHANGELOG → Task 7. All spec sections map to a task.
- **Placeholder scan:** no TBD/TODO; every code step shows full code; the only `todo!()` is the intentional TDD red state in Task 2 Step 2, made green in Step 4.
- **Type consistency:** `WIPE_SUBDIRS`, `purge_preview(&Path) -> Vec<PathBuf>`, `purge_data_dirs(&Path) -> anyhow::Result<Vec<PathBuf>>` used identically in Tasks 2/3/4/5; `ResetArgs { confirm }` and `Config { data_dir, ..Default }` match the real signatures; `print_docker_hint(bool)` call updated to drop `purge_refused`.
```
diff --git a/docs/superpowers/specs/2026-05-25-uninstall-dryrun-purge-preview-design.md b/docs/superpowers/specs/2026-05-25-uninstall-dryrun-purge-preview-design.md
index 00693131..49195080 100644
--- a/docs/superpowers/specs/2026-05-25-uninstall-dryrun-purge-preview-design.md
+++ b/docs/superpowers/specs/2026-05-25-uninstall-dryrun-purge-preview-design.md
@@ -34,7 +34,7 @@ Two issues surfaced while exercising `ai-memory uninstall --purge-data`:
- `uninstall --purge-data` is **all-or-nothing**: if another `ai-memory`
process is alive it refuses *up front*, before removing any wiring — no
half-done state. Matches `reset`'s guard-at-top.
-- Coverage on touched/new code across this branch: critical logic ≥ 90%,
+- Coverage on the **changed lines** (diff vs `main`): critical logic ≥ 90%,
rest ≥ 80% (line coverage, local inspection — see Coverage).
## Non-goals
@@ -207,7 +207,12 @@ purge lines cover *data*. Technically correct; left as-is for simplicity.
4. **Integration test `uninstall --purge-data` dry-run** (fails) → implement
preview → green: stdout contains `would purge …/wiki|db|raw` AND the seeded
files still exist on disk afterward.
-5. **Option-B guard (best-effort, `#[ignore]`).** With `--purge-data --apply`
+5. **Integration test `uninstall --purge-data --apply --yes` happy path**
+ (temp HOME + temp data dir, no sibling): asserts `wiki`/`db`/`raw` emptied,
+ `logs/` intact, `✓ purged` printed. Covers the new apply-side lines for the
+ changed-line coverage target. (Small flake risk if another test spawns
+ `ai-memory` concurrently and trips the guard; serialize/retry if it surfaces.)
+6. **Option-B guard (best-effort, `#[ignore]`).** With `--purge-data --apply`
and a live sibling `ai-memory` process, the command bails and **no wiring is
removed** (all-or-nothing). Like H3 this cannot be tested deterministically
(`sysinfo` reads the live process table, no injection seam, and rule #6
@@ -221,19 +226,23 @@ Symlinked subdirs are out of scope; behavior matches existing `reset`
### Coverage
-- Tool: **`cargo llvm-cov`** (`cargo install cargo-llvm-cov`). It is a
- **local inspection, not a CI gate** (CI runs fmt/clippy/test/deny/audit
- only); documented under a "Coverage (local)" note, NOT the "CI parity" list.
-- Metric: **line coverage** via `cargo llvm-cov --lcov` (or `--summary-only`),
- inspected per file for the files this branch touches.
-- Targets for touched/new code across the whole branch (per the maintainer's
- requirement — this includes already-committed uninstall code):
- - **Critical logic ≥ 90%** (criticality, not purity): `data_purge`
- (helper, const, preview) and `uninstall`'s pure `strip_*` /
- `*_is_ours` functions.
- - **Rest ≥ 80%**: `reset::run`, `uninstall::run`, `build_plan` (it does
- filesystem IO — orchestration, not pure), dispatch, print paths.
-- Add tests until thresholds are met for the touched files.
+- **Scope: only the lines changed/added on this branch (the diff vs `main`),
+ not whole files.** Pre-existing untouched code (e.g. the already-committed
+ `strip_*` / `build_plan`) is out of scope.
+- Tool: **`cargo llvm-cov`** for the report + **`diff-cover`** against `main`
+ for the changed-line numbers. Local inspection, not a CI gate (CI runs
+ fmt/clippy/test/deny/audit only).
+ - `cargo llvm-cov --cobertura --output-path target/cov.xml -p ai-memory-cli`
+ - `diff-cover target/cov.xml --compare-branch main`
+- Targets on the changed lines (line coverage):
+ - **Critical logic ≥ 90%**: the new `data_purge` helper (covered ~100% by its
+ own unit tests).
+ - **Rest ≥ 80%**: changed lines in `reset::run` (reset characterization
+ tests) and `uninstall::run` (dry-run preview test + apply+purge happy-path
+ test).
+- **Lone accepted gap:** the option-B `bail!` line in `uninstall` is only
+ reached by the `#[ignore]` sibling test (sysinfo, per H3); it is the single
+ uncovered changed line.
## Project-rule checks
@@ -289,9 +298,10 @@ Symlinked subdirs are out of scope; behavior matches existing `reset`
- **H2 (#10 not addressed):** accepted — explicit N/A note added.
- **H3 (guard test infeasible):** accepted — guard refusal removed from the
characterization set with rationale.
-- **M1 (coverage scope/metric):** partially — kept the whole-branch scope (a
- maintainer requirement, not scope creep); specified line coverage + local
- (non-CI) inspection.
+- **M1 (coverage scope/metric):** the maintainer later scoped coverage to the
+ **changed lines only** (diff vs `main`) — which resolves the reviewer's
+ "whole-file / already-committed" concern. Measured with `cargo llvm-cov`
+ cobertura + `diff-cover`, line coverage, local (non-CI).
- **M2 (`build_plan` is not "pure"):** accepted — moved to the ≥80% bucket;
90% bucket reframed as "critical logic", not "pure".
- **M3 (reset-rationale inverted):** accepted — corrected (reset is the