The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(memory): add deletion test fixtures
Steven Enamakel5748e4db2cbc
diff --git a/crates/openhuman-core/src/memory/deletion_tests.rs b/crates/openhuman-core/src/memory/deletion_tests.rsnew file mode 100644index 0000000000..3710741b8e--- /dev/null+++ b/crates/openhuman-core/src/memory/deletion_tests.rs@@ -0,0 +1,100 @@+use super::*;++use tinymemory_api::{MemoryMeta, Role, StoreItem, Turn};++use crate::memory::test_fixtures::{bind_reference, config_in, stored};++fn conversation(thread_id: &str, text: &str) -> StoreItem {+ StoreItem::Conversation {+ turns: vec![Turn::new(Role::User, text.to_string())],+ meta: MemoryMeta {+ thread_id: Some(thread_id.to_string()),+ ..MemoryMeta::default()+ },+ }+}++fn thread(id: &str) -> PendingDeletion {+ PendingDeletion::Thread {+ thread_id: id.to_string(),+ }+}++#[tokio::test]+async fn a_deleted_threads_conversation_is_forgotten_for_good() {+ let tmp = tempfile::tempdir().unwrap();+ let config = config_in(&tmp);+ let engine = bind_reference(&config);+ engine.store(conversation("t-gone", "secret plan")).await.unwrap();+ engine.store(conversation("t-kept", "keep me")).await.unwrap();++ assert_eq!(forget_thread(&config, "t-gone").await, 1);++ let left = stored(&engine, MetaFilter::default()).await;+ assert_eq!(left.len(), 1);+ assert_eq!(left[0].meta.thread_id.as_deref(), Some("t-kept"));+ assert!(pending(&config.workspace_dir).is_empty());+}++#[tokio::test]+async fn a_thread_deleted_while_signed_out_is_forgotten_on_the_next_sign_in() {+ let tmp = tempfile::tempdir().unwrap();+ let config = config_in(&tmp);+ // Memory off: no credential, no engine.+ assert_eq!(forget_thread(&config, "t-1").await, 0);+ assert_eq!(pending(&config.workspace_dir), vec![thread("t-1")]);+ // Nothing runs while memory stays off, and nothing is lost.+ assert_eq!(drain(&config).await, 0);+ assert_eq!(pending(&config.workspace_dir), vec![thread("t-1")]);++ // Signed in: the engine is reachable and holds the thread's memory.+ let engine = bind_reference(&config);+ engine.store(conversation("t-1", "from before")).await.unwrap();+ assert_eq!(drain(&config).await, 1);+ assert!(stored(&engine, MetaFilter::default()).await.is_empty());+ assert!(pending(&config.workspace_dir).is_empty());+}++#[tokio::test]+async fn a_failed_forget_is_kept_for_the_next_drain() {+ let tmp = tempfile::tempdir().unwrap();+ let config = config_in(&tmp);+ crate::memory::test_fixtures::RefusingEngine::out_of_credits().bind(&config);+ assert_eq!(forget_thread(&config, "t-2").await, 0);+ assert_eq!(pending(&config.workspace_dir), vec![thread("t-2")]);+ assert_eq!(drain(&config).await, 0);+ assert_eq!(pending(&config.workspace_dir), vec![thread("t-2")]);+}++#[test]+fn a_deletion_is_queued_once() {+ let tmp = tempfile::tempdir().unwrap();+ enqueue(tmp.path(), thread("t"));+ enqueue(tmp.path(), thread("t"));+ enqueue(+ tmp.path(),+ PendingDeletion::Connection {+ connection_id: "c".into(),+ toolkit: Some("gmail".into()),+ },+ );+ assert_eq!(pending(tmp.path()).len(), 2);+}++#[test]+fn an_unparsable_queue_is_set_aside_not_lost() {+ let tmp = tempfile::tempdir().unwrap();+ let file = path(tmp.path());+ std::fs::create_dir_all(file.parent().unwrap()).unwrap();+ std::fs::write(&file, "not json").unwrap();+ assert!(pending(tmp.path()).is_empty());+ assert!(file.with_extension("json.corrupt").exists());+}++#[tokio::test]+async fn a_blank_thread_id_queues_nothing() {+ let tmp = tempfile::tempdir().unwrap();+ let config = config_in(&tmp);+ assert_eq!(forget_thread(&config, " ").await, 0);+ assert!(pending(&config.workspace_dir).is_empty());+}diff --git a/crates/openhuman-core/src/memory/test_fixtures.rs b/crates/openhuman-core/src/memory/test_fixtures.rsindex 56edf9fd04..aa5a0b89a8 100644--- a/crates/openhuman-core/src/memory/test_fixtures.rs+++ b/crates/openhuman-core/src/memory/test_fixtures.rs@@ -133,3 +133,110 @@ impl MemoryEngine for RefusingEngine {Err(self.error.clone())}}++/// The reference engine, recording which deletions it was asked for, and+/// optionally refusing to erase the way an engine without erasure does.+pub(crate) struct RecordingEngine {+ pub(crate) inner: ReferenceEngine,+ /// `"erase"` / `"forget"`, in call order.+ pub(crate) calls: std::sync::Mutex<Vec<&'static str>>,+ erase_unsupported: bool,+}++impl RecordingEngine {+ /// Records and passes every call through.+ pub(crate) fn new() -> Self {+ Self {+ inner: ReferenceEngine::new(),+ calls: std::sync::Mutex::new(Vec::new()),+ erase_unsupported: false,+ }+ }++ /// Records, and refuses every erase with `Unsupported`.+ pub(crate) fn without_erase() -> Self {+ Self {+ erase_unsupported: true,+ ..Self::new()+ }+ }++ /// Binds `engine` to `config`'s workspace.+ pub(crate) fn bind(engine: &Arc<Self>, config: &Config) {+ crate::memory::engine::install_test_engine(&config.workspace_dir, engine.clone());+ }++ /// The recorded calls.+ pub(crate) fn calls(&self) -> Vec<&'static str> {+ self.calls.lock().unwrap().clone()+ }+}++#[async_trait::async_trait]+impl MemoryEngine for RecordingEngine {+ fn descriptor(&self) -> &tinymemory_api::EngineDescriptor {+ self.inner.descriptor()+ }++ async fn health(&self) -> tinymemory_api::EngineHealth {+ self.inner.health().await+ }++ async fn recall(+ &self,+ req: tinymemory_api::RecallRequest,+ ) -> tinymemory_api::Result<tinymemory_api::RecallAnswer> {+ self.inner.recall(req).await+ }++ async fn fetch(+ &self,+ req: tinymemory_api::FetchRequest,+ ) -> tinymemory_api::Result<tinymemory_api::FetchPage> {+ self.inner.fetch(req).await+ }++ async fn store(+ &self,+ item: tinymemory_api::StoreItem,+ ) -> tinymemory_api::Result<tinymemory_api::StoreReceipt> {+ self.inner.store(item).await+ }++ async fn forget(+ &self,+ target: tinymemory_api::ForgetTarget,+ ) -> tinymemory_api::Result<tinymemory_api::ForgetReport> {+ self.calls.lock().unwrap().push("forget");+ self.inner.forget(target).await+ }++ async fn list(&self, req: ListRequest) -> tinymemory_api::Result<tinymemory_api::ListPage> {+ self.inner.list(req).await+ }++ async fn export(+ &self,+ req: ListRequest,+ ) -> tinymemory_api::Result<tinymemory_api::ExportPage> {+ self.inner.export(req).await+ }++ async fn consolidate(+ &self,+ req: tinymemory_api::ConsolidateRequest,+ ) -> tinymemory_api::Result<tinymemory_api::ConsolidateReceipt> {+ self.inner.consolidate(req).await+ }++ async fn erase(+ &self,+ req: tinymemory_api::EraseRequest,+ ) -> tinymemory_api::Result<tinymemory_api::EraseReport> {+ self.calls.lock().unwrap().push("erase");+ if self.erase_unsupported {+ return Err(tinymemory_api::Error::Unsupported("no erase".into()));+ }+ self.inner.erase(req).await+ }+}