Skip to content

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

Rust

test(store,web): cover the expired-page listings

Vinícius DS Andradee5fdfe3c0b23
diff --git a/crates/ai-memory-store/src/lib.rs b/crates/ai-memory-store/src/lib.rs
index 5b3c1059..bf6c62b1 100644
--- a/crates/ai-memory-store/src/lib.rs
+++ b/crates/ai-memory-store/src/lib.rs
@@ -4852,6 +4852,49 @@ mod tests {
assert!(paths.contains(&"y.md"));
}
+ #[tokio::test]
+ async fn reader_list_unexpired_pages_hides_only_the_expired_ones() {
+ let tmp = TempDir::new().unwrap();
+ let store = Store::open(tmp.path()).unwrap();
+ let ws = store
+ .writer
+ .get_or_create_workspace("default")
+ .await
+ .unwrap();
+ let proj = store
+ .writer
+ .get_or_create_project(ws, "scratch", None)
+ .await
+ .unwrap();
+ let now = jiff::Timestamp::now().as_second();
+ let at = |seconds: i64| Some(jiff::Timestamp::from_second(seconds).unwrap());
+ for (path, expires_at) in [
+ ("expired.md", at(now - 60)),
+ ("future.md", at(now + 3_600)),
+ ("live.md", None),
+ ] {
+ let mut page = sample_page(ws, proj, path, "body");
+ page.expires_at = expires_at;
+ store.writer.upsert_page(page).await.unwrap();
+ }
+
+ let paths = |pages: Vec<PageSummary>| -> Vec<String> {
+ pages.into_iter().map(|p| p.path).collect()
+ };
+ // The full listing keeps the expired page for the callers that
+ // copy or audit every current page.
+ assert_eq!(
+ paths(store.reader.list_pages("default", "scratch").await.unwrap()),
+ ["expired.md", "future.md", "live.md"]
+ );
+ // The reader-facing listing drops it, and only it: a TTL still
+ // ahead and no TTL at all both stay.
+ assert_eq!(
+ paths(store.reader.list_unexpired_pages("default", "scratch").await.unwrap()),
+ ["future.md", "live.md"]
+ );
+ }
+
#[tokio::test]
async fn reader_page_kinds_follow_canonical_paths_across_surfaces() {
const CASES: [(&str, &str); 9] = [
diff --git a/crates/ai-memory-web/tests/suite/routes.rs b/crates/ai-memory-web/tests/suite/routes.rs
index 1225f9ff..86df5e6c 100644
--- a/crates/ai-memory-web/tests/suite/routes.rs
+++ b/crates/ai-memory-web/tests/suite/routes.rs
@@ -5050,6 +5050,130 @@ async fn page_sidebar_shows_links_and_hides_superseded_and_expired_neighbours()
assert!(!source.contains("On this page"), "{source}");
}
+/// Seed a live page, one whose TTL passed and one whose TTL is still ahead,
+/// all under `notes/`.
+async fn seed_expiry_mix(
+ wiki: &Wiki,
+ ws: ai_memory_core::WorkspaceId,
+ proj: ai_memory_core::ProjectId,
+) {
+ wiki.write_page(wiki_req(
+ ws,
+ proj,
+ "notes/live.md",
+ "# Live Note\n\nStill current.",
+ ))
+ .await
+ .unwrap();
+ for (path, body, expires_at) in [
+ ("notes/expired.md", "# Expired Note\n\nPast its date.", "2000-01-01"),
+ ("notes/future.md", "# Future Note\n\nNot yet.", "2999-01-01"),
+ ] {
+ let mut request = wiki_req(ws, proj, path, body);
+ request.frontmatter = serde_json::json!({"kind": "fact", "expires_at": expires_at});
+ wiki.write_page(request).await.unwrap();
+ }
+}
+
+#[tokio::test]
+async fn project_tree_and_namespace_listing_hide_expired_pages() {
+ let (_tmp, store, wiki) = setup().await;
+ let ws = store
+ .writer
+ .get_or_create_workspace("default")
+ .await
+ .unwrap();
+ let proj = store
+ .writer
+ .get_or_create_project(ws, "scratch", None)
+ .await
+ .unwrap();
+ seed_expiry_mix(&wiki, ws, proj).await;
+ let mut only_expired = wiki_req(ws, proj, "gone/only.md", "# Only Gone\n\nPast its date.");
+ only_expired.frontmatter = serde_json::json!({"kind": "fact", "expires_at": "2000-01-01"});
+ wiki.write_page(only_expired).await.unwrap();
+ let app = router(store.reader.clone(), wiki.clone());
+
+ // The sidebar tree and the recent list: a TTL still ahead is kept.
+ let (status, project) = get_body(&app, "/w/default/scratch").await;
+ assert_eq!(status, StatusCode::OK);
+ assert!(
+ project.contains("Live Note") && project.contains("Future Note"),
+ "{project}"
+ );
+ assert!(!project.contains("Expired Note"), "{project}");
+ assert!(!project.contains("Only Gone"), "{project}");
+
+ let (status, namespace) = get_body(&app, "/w/default/scratch/p/notes/").await;
+ assert_eq!(status, StatusCode::OK);
+ assert!(
+ namespace.contains("Live Note") && namespace.contains("Future Note"),
+ "{namespace}"
+ );
+ assert!(!namespace.contains("Expired Note"), "{namespace}");
+ // A namespace left with no unexpired page lists nothing, like an empty one.
+ let (status, _) = get_body(&app, "/w/default/scratch/p/gone/").await;
+ assert_eq!(status, StatusCode::NOT_FOUND);
+
+ // An exact-path read is not a listing: the expired page still opens.
+ let (status, page) = get_body(&app, "/w/default/scratch/p/notes/expired.md").await;
+ assert_eq!(status, StatusCode::OK);
+ assert!(page.contains("Expired Note"), "{page}");
+}
+
+#[tokio::test]
+async fn api_page_lists_hide_expired_pages_like_the_incremental_recent_form() {
+ let (_tmp, store, wiki) = setup().await;
+ let ws = store
+ .writer
+ .get_or_create_workspace("default")
+ .await
+ .unwrap();
+ let proj = store
+ .writer
+ .get_or_create_project(ws, "scratch", None)
+ .await
+ .unwrap();
+ seed_expiry_mix(&wiki, ws, proj).await;
+ let app = api_router(store.reader.clone(), wiki.clone());
+
+ let paths = |pages: &Value| -> Vec<String> {
+ pages
+ .as_array()
+ .unwrap()
+ .iter()
+ .map(|page| page["path"].as_str().unwrap().to_owned())
+ .collect()
+ };
+ let base = "/workspaces/default/projects/scratch";
+ let (status, pages) = get_body(&app, &format!("{base}/pages")).await;
+ assert_eq!(status, StatusCode::OK);
+ let listed = paths(&serde_json::from_str::<Value>(&pages).unwrap());
+ assert_eq!(listed, ["notes/future.md", "notes/live.md"], "{pages}");
+
+ // Both forms of the recent endpoint agree: the legacy array and the
+ // incremental object list the same pages.
+ let (status, legacy) = get_body(&app, &format!("{base}/recent?limit=10")).await;
+ assert_eq!(status, StatusCode::OK);
+ let mut legacy = paths(&serde_json::from_str::<Value>(&legacy).unwrap());
+ legacy.sort();
+ assert_eq!(legacy, ["notes/future.md", "notes/live.md"]);
+ let (status, incremental) = get_body(
+ &app,
+ &format!("{base}/recent?updated_since=1970-01-01T00:00:00Z&limit=10"),
+ )
+ .await;
+ assert_eq!(status, StatusCode::OK);
+ let incremental: Value = serde_json::from_str(&incremental).unwrap();
+ let mut incremental = paths(&incremental["pages"]);
+ incremental.sort();
+ assert_eq!(incremental, legacy);
+
+ // The single-page read keeps answering for the expired page.
+ let (status, _) = get_body(&app, &format!("{base}/pages/notes/expired.md")).await;
+ assert_eq!(status, StatusCode::OK);
+}
+
#[tokio::test]
async fn page_sidebar_caps_each_group_at_ten() {
let (_tmp, store, wiki) = setup().await;