Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
test(store): cover contradiction_edges target resolution and expiry
Vinícius DS Andradedf9132f188f4
diff --git a/crates/ai-memory-consolidate/tests/suite/typed_edges.rs b/crates/ai-memory-consolidate/tests/suite/typed_edges.rsindex f78dfc17..03eed69b 100644--- a/crates/ai-memory-consolidate/tests/suite/typed_edges.rs+++ b/crates/ai-memory-consolidate/tests/suite/typed_edges.rs@@ -188,6 +188,75 @@ async fn a_contradiction_to_a_deleted_page_reports_the_stale_declaration() {assert!(finding.message.contains("does not resolve"));}+#[tokio::test]+async fn a_contradiction_to_a_soft_deleted_page_reports_the_stale_declaration() {+ let tmp = TempDir::new().unwrap();+ let store = Store::open(tmp.path()).unwrap();+ let (ws, proj) = scope(&store).await;+ let wiki = Wiki::new(tmp.path(), store.writer.clone()).unwrap();++ let target_id = wiki+ .write_page(req(+ ws,+ proj,+ "decisions/tombstoned.md",+ "old policy",+ serde_json::json!({}),+ ))+ .await+ .unwrap();++ wiki.write_page(req(+ ws,+ proj,+ "notes/disagreement.md",+ "contradicts tombstoned",+ serde_json::json!({"relations": {"contradicts": ["decisions/tombstoned.md"]}}),+ ))+ .await+ .unwrap();++ let soft_deleted = store+ .writer+ .soft_delete_for_decay_if_latest(+ ws,+ proj,+ PagePath::new("decisions/tombstoned.md").unwrap(),+ target_id,+ )+ .await+ .unwrap();+ assert!(soft_deleted);++ let report = run_lint(+ &store.reader,+ &wiki,+ None,+ ws,+ proj,+ LintOptions {+ dry_run: true,+ use_llm: false,+ decay_lambda: 0.02,+ embedding: None,+ contradiction_band_min: ai_memory_consolidate::DEFAULT_CONTRADICTION_SIM_LOW,+ contradiction_band_max: ai_memory_consolidate::DEFAULT_CONTRADICTION_SIM_HIGH,+ },+ )+ .await+ .unwrap();+ let finding = report+ .findings+ .iter()+ .find(|f| f.kind == "contradiction")+ .expect("unresolved contradicts still lints");+ assert!(finding.message.contains("does not resolve"));+ assert_eq!(+ finding.pages,+ vec!["notes/disagreement.md", "decisions/tombstoned.md"]+ );+}+// ── 2.0.1: lint reports are one superseding page, not a daily pile ──/// A page old enough (and cold enough) to trigger the rule-baseddiff --git a/crates/ai-memory-store/tests/suite/related_walk.rs b/crates/ai-memory-store/tests/suite/related_walk.rsindex d41e43b2..f17f8098 100644--- a/crates/ai-memory-store/tests/suite/related_walk.rs+++ b/crates/ai-memory-store/tests/suite/related_walk.rs@@ -20,7 +20,7 @@//! returned nor walked through. The seed lookup is an exact-path read//! and still starts from an expired page.-use ai_memory_core::{NewPage, NewUser, PagePath, ProjectId, Tier, UserId, WorkspaceId};+use ai_memory_core::{NewPage, NewUser, PagePath, ProjectId, Relation, Tier, UserId, WorkspaceId};use ai_memory_store::{AccessMode, GrantLevel, RELATED_WALK_MAX_DEPTH, RELATED_WALK_MAX_NODES, Store,};@@ -57,6 +57,15 @@ fn same_project_link(path: &str) -> ai_memory_core::LinkTarget {}}+fn contradiction_link(path: &str) -> ai_memory_core::LinkTarget {+ ai_memory_core::LinkTarget {+ workspace: None,+ project: None,+ path: PagePath::new(path).unwrap(),+ relation: Some(Relation::Contradicts),+ }+}+fn cross_project_link(project: &str, path: &str) -> ai_memory_core::LinkTarget {ai_memory_core::LinkTarget {workspace: None,@@ -848,3 +857,149 @@ async fn page_links_preview_caps_in_sql_and_counts_only_readable_neighbours() {let cut_root: Vec<&str> = root.backlinks.iter().map(|p| p.path.as_str()).collect();assert_eq!(cut_root, head);}++/// `contradiction_edges` returns declared contradicts edges from latest+/// unexpired pages. A target edge resolves only when pointing at an existing,+/// latest, and unexpired page. If the target was tombstoned, expired, or never+/// existed, `resolved` evaluates to false. An expired source page is omitted+/// entirely from contradiction edges.+#[tokio::test]+async fn contradiction_edges_require_latest_unexpired_target() {+ let tmp = tempfile::tempdir().unwrap();+ let store = Store::open(tmp.path()).unwrap();+ let ws = store+ .writer+ .get_or_create_workspace("default".to_string())+ .await+ .unwrap();+ let app = store+ .writer+ .get_or_create_project(ws, "app".to_string(), None)+ .await+ .unwrap();++ store+ .writer+ .upsert_page(page_with_links(ws, app, "notes/live_target.md", vec![]))+ .await+ .unwrap();++ let tombstoned_target_id = store+ .writer+ .upsert_page(page_with_links(+ ws,+ app,+ "notes/tombstoned_target.md",+ vec![],+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(with_expiry(+ page_with_links(ws, app, "notes/expired_target.md", vec![]),+ expired_at(),+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(with_expiry(+ page_with_links(ws, app, "notes/future_target.md", vec![]),+ future_at(),+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(page_with_links(+ ws,+ app,+ "notes/source.md",+ vec![+ contradiction_link("notes/live_target.md"),+ contradiction_link("notes/tombstoned_target.md"),+ contradiction_link("notes/expired_target.md"),+ contradiction_link("notes/future_target.md"),+ contradiction_link("notes/missing_target.md"),+ ],+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(with_expiry(+ page_with_links(+ ws,+ app,+ "notes/expired_source.md",+ vec![contradiction_link("notes/live_target.md")],+ ),+ expired_at(),+ ))+ .await+ .unwrap();++ let soft_deleted = store+ .writer+ .soft_delete_for_decay_if_latest(+ ws,+ app,+ PagePath::new("notes/tombstoned_target.md").unwrap(),+ tombstoned_target_id,+ )+ .await+ .unwrap();+ assert!(soft_deleted, "tombstone soft delete succeeded");++ let edges = store+ .reader+ .contradiction_edges(ws, app)+ .await+ .unwrap();++ assert!(+ !edges.iter().any(|e| e.from_path == "notes/expired_source.md"),+ "expired source page must not emit contradiction edges"+ );++ let pairs: Vec<(String, String, bool)> = edges+ .into_iter()+ .map(|e| (e.from_path, e.to_path, e.resolved))+ .collect();++ assert_eq!(+ pairs,+ vec![+ (+ "notes/source.md".to_string(),+ "notes/expired_target.md".to_string(),+ false,+ ),+ (+ "notes/source.md".to_string(),+ "notes/future_target.md".to_string(),+ true,+ ),+ (+ "notes/source.md".to_string(),+ "notes/live_target.md".to_string(),+ true,+ ),+ (+ "notes/source.md".to_string(),+ "notes/missing_target.md".to_string(),+ false,+ ),+ (+ "notes/source.md".to_string(),+ "notes/tombstoned_target.md".to_string(),+ false,+ ),+ ]+ );+}