Skip to content

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

Rust

test(store): cover dangling_cross_project_links target resolution and expiry

Vinícius DS Andrade39da67e60890
diff --git a/crates/ai-memory-store/tests/suite/related_walk.rs b/crates/ai-memory-store/tests/suite/related_walk.rs
index d41e43b2..473ed413 100644
--- a/crates/ai-memory-store/tests/suite/related_walk.rs
+++ b/crates/ai-memory-store/tests/suite/related_walk.rs
@@ -848,3 +848,156 @@ 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);
}
+
+/// `dangling_cross_project_links` returns declared dependencies on pages in
+/// another project that do not resolve to an existing, latest, unexpired page.
+/// If the target was tombstoned (soft-deleted), expired, or never existed, it
+/// is reported as dangling. Targets that are live or have future TTL do not
+/// dangle. An expired source page is omitted entirely.
+#[tokio::test]
+async fn dangling_cross_project_links_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();
+ let lib = store
+ .writer
+ .get_or_create_project(ws, "lib".to_string(), None)
+ .await
+ .unwrap();
+
+ store
+ .writer
+ .upsert_page(page_with_links(ws, lib, "notes/live_target.md", vec![]))
+ .await
+ .unwrap();
+
+ let tombstoned_target_id = store
+ .writer
+ .upsert_page(page_with_links(
+ ws,
+ lib,
+ "notes/tombstoned_target.md",
+ vec![],
+ ))
+ .await
+ .unwrap();
+
+ store
+ .writer
+ .upsert_page(with_expiry(
+ page_with_links(ws, lib, "notes/expired_target.md", vec![]),
+ expired_at(),
+ ))
+ .await
+ .unwrap();
+
+ store
+ .writer
+ .upsert_page(with_expiry(
+ page_with_links(ws, lib, "notes/future_target.md", vec![]),
+ future_at(),
+ ))
+ .await
+ .unwrap();
+
+ store
+ .writer
+ .upsert_page(page_with_links(
+ ws,
+ app,
+ "notes/source.md",
+ vec![
+ cross_project_link("ghost", "notes/missing.md"),
+ cross_project_link("lib", "notes/live_target.md"),
+ cross_project_link("lib", "notes/tombstoned_target.md"),
+ cross_project_link("lib", "notes/expired_target.md"),
+ cross_project_link("lib", "notes/future_target.md"),
+ cross_project_link("lib", "notes/missing_target.md"),
+ ],
+ ))
+ .await
+ .unwrap();
+
+ store
+ .writer
+ .upsert_page(with_expiry(
+ page_with_links(
+ ws,
+ app,
+ "notes/expired_source.md",
+ vec![cross_project_link("lib", "notes/live_target.md")],
+ ),
+ expired_at(),
+ ))
+ .await
+ .unwrap();
+
+ let soft_deleted = store
+ .writer
+ .soft_delete_for_decay_if_latest(
+ ws,
+ lib,
+ PagePath::new("notes/tombstoned_target.md").unwrap(),
+ tombstoned_target_id,
+ )
+ .await
+ .unwrap();
+ assert!(soft_deleted, "tombstone soft delete succeeded");
+
+ let dangling = store
+ .reader
+ .dangling_cross_project_links(ws, app)
+ .await
+ .unwrap();
+
+ assert!(
+ !dangling
+ .iter()
+ .any(|d| d.from_path == "notes/expired_source.md"),
+ "expired source page must not emit dangling links"
+ );
+
+ let summary: Vec<(String, String, String, bool)> = dangling
+ .into_iter()
+ .map(|d| (d.from_path, d.project, d.path, d.project_exists))
+ .collect();
+
+ assert_eq!(
+ summary,
+ vec![
+ (
+ "notes/source.md".to_string(),
+ "ghost".to_string(),
+ "notes/missing.md".to_string(),
+ false,
+ ),
+ (
+ "notes/source.md".to_string(),
+ "lib".to_string(),
+ "notes/expired_target.md".to_string(),
+ true,
+ ),
+ (
+ "notes/source.md".to_string(),
+ "lib".to_string(),
+ "notes/missing_target.md".to_string(),
+ true,
+ ),
+ (
+ "notes/source.md".to_string(),
+ "lib".to_string(),
+ "notes/tombstoned_target.md".to_string(),
+ true,
+ ),
+ ]
+ );
+}