Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
test: make the auth-enable and residue checks portable; split secret-shaped canaries
AkitaOnRailsf59c3aff9d52
diff --git a/companions/ai-memory-importer/src/agentmemory/export/tests.rs b/companions/ai-memory-importer/src/agentmemory/export/tests.rsindex c3d51cb4..25340a7a 100644--- a/companions/ai-memory-importer/src/agentmemory/export/tests.rs+++ b/companions/ai-memory-importer/src/agentmemory/export/tests.rs@@ -269,7 +269,7 @@ fn colliding_basenames_split_by_cwd() {#[test]fn text_is_redacted_before_the_plan_exists() {let mut export = fixture_export();- export["memories"][0]["content"] = json!("key: sk-1234567890abcdefghijklmnop end");+ export["memories"][0]["content"] = json!(concat!("key: sk-", "1234567890abcdefghijklmnop end")); // split for secret scannerslet plan = plan_fixture(&export, &fixture_mapping(), true);let all = format!("{:?}{}",diff --git a/companions/ai-memory-importer/src/agentmemory/vault.rs b/companions/ai-memory-importer/src/agentmemory/vault.rsindex 5464b814..32c38906 100644--- a/companions/ai-memory-importer/src/agentmemory/vault.rs+++ b/companions/ai-memory-importer/src/agentmemory/vault.rs@@ -495,7 +495,8 @@ pub(crate) mod tests {put(td.path(),"memories/m.md",- "---\nid: \"ghp_1234567890abcdefghijklmnopqrstuvwxyzAB\"\n---\n# M",+ // Split so secret scanners do not flag the fixture.+ concat!("---\nid: \"ghp_", "1234567890abcdefghijklmnopqrstuvwxyzAB\"\n---\n# M"),);assert!(plan(td.path(), &dest(), DEFAULT_DEST_PREFIX).is_err());diff --git a/crates/ai-memory-cli/src/commands/agentmemory_residue.rs b/crates/ai-memory-cli/src/commands/agentmemory_residue.rsindex 32b748a5..a741a633 100644--- a/crates/ai-memory-cli/src/commands/agentmemory_residue.rs+++ b/crates/ai-memory-cli/src/commands/agentmemory_residue.rs@@ -576,20 +576,19 @@ mod tests {.collect();let findings = scan(home.path(), repo.path(), &project_mcp_configs(repo.path()));- let mut paths: Vec<&str> = findings.iter().map(|f| f.path.as_str()).collect();+ // Compare as paths, not display strings: on Windows the scanner joins+ // `.cursor/rules` and `memory.mdc` with `\\`, which `Path` treats as+ // the same separator as `/`.+ let mut paths: Vec<PathBuf> = findings.iter().map(|f| PathBuf::from(&f.path)).collect();paths.sort_unstable();- let expect = |base: &Path, rel: &str| base.join(rel).display().to_string();let mut expected = [- expect(repo.path(), "AGENTS.md"),- expect(repo.path(), ".cursor/rules/memory.mdc"),- expect(repo.path(), ".mcp.json"),- expect(home.path(), ".gemini/GEMINI.md"),+ repo.path().join("AGENTS.md"),+ repo.path().join(".cursor/rules/memory.mdc"),+ repo.path().join(".mcp.json"),+ home.path().join(".gemini/GEMINI.md"),];expected.sort();- assert_eq!(- paths,- expected.iter().map(String::as_str).collect::<Vec<_>>()- );+ assert_eq!(paths, expected);for (path, bytes) in before {assert_eq!(std::fs::read(&path).unwrap(),diff --git a/crates/ai-memory-cli/src/commands/auth_enable.rs b/crates/ai-memory-cli/src/commands/auth_enable.rsindex 3497a8b8..52a78eea 100644--- a/crates/ai-memory-cli/src/commands/auth_enable.rs+++ b/crates/ai-memory-cli/src/commands/auth_enable.rs@@ -518,10 +518,17 @@ mod tests {path.display());}+ // Compare canonical paths: the token path comes from the canonical+ // data dir, which differs from the walked temp path on macOS+ // (`/var` -> `/private/var`) and Windows (`\\?\` and 8.3 names).+ let canonical = |p: &Path| std::fs::canonicalize(p).unwrap_or_else(|_| p.to_path_buf());+ let allowed_paths = [+ canonical(&first.token_path),+ canonical(&crate::config::hook_auth_token_path_in(&data_dir)),+ canonical(&crate::config::hook_auth_header_path_in(&data_dir)),+ ];for (path, text) in files_under(&data_dir) {- let allowed = path == first.token_path- || path == crate::config::hook_auth_token_path_in(&data_dir)- || path == crate::config::hook_auth_header_path_in(&data_dir);+ let allowed = allowed_paths.contains(&canonical(&path));assert!(allowed || !text.contains(&token),"token copied to an unexpected file {}",diff --git a/crates/ai-memory-mcp/tests/suite/admin_metrics.rs b/crates/ai-memory-mcp/tests/suite/admin_metrics.rsindex 8feb834b..153af370 100644--- a/crates/ai-memory-mcp/tests/suite/admin_metrics.rs+++ b/crates/ai-memory-mcp/tests/suite/admin_metrics.rs@@ -27,8 +27,9 @@ use tempfile::TempDir;use tower::ServiceExt;const ROOT: &str = "root-token-for-metrics";-const SECRET_QUERY: &str = "sk-ant-api03-QUERYplanted0123456789abcdefXYZ";-const SECRET_HOOK: &str = "ghp_HOOKplanted0123456789abcdefghijklmnop";+// Split with `concat!` so secret scanners do not flag the planted canaries.+const SECRET_QUERY: &str = concat!("sk-ant-", "api03-QUERYplanted0123456789abcdefXYZ");+const SECRET_HOOK: &str = concat!("ghp_", "HOOKplanted0123456789abcdefghijklmnop");const SECRET_PROJECT: &str = "proj-AKIAPROJECTPLANTED7777";struct Harness {