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(notifications): add document store notification tests
Steven Enamakelaf4c134ca5d5
diff --git a/crates/openhuman-core/src/desktop/notifications/rpc.rs b/crates/openhuman-core/src/desktop/notifications/rpc.rsindex f7092dae9b..bc7eb65535 100644--- a/crates/openhuman-core/src/desktop/notifications/rpc.rs+++ b/crates/openhuman-core/src/desktop/notifications/rpc.rs@@ -88,7 +88,7 @@ pub async fn handle_ingest(params: Map<String, Value>) -> Result<Value, String>// Spawn background triage — the ingest RPC returns immediately.let id_for_triage = id.clone();let config_for_triage = config.clone();- tokio::spawn(async move {+ crate::core::runtime::spawn_scoped(async move {let envelope = TriggerEnvelope {source: TriggerSource::WebviewIntegration {provider: req.provider.clone(),diff --git a/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs b/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rsindex 4f670bb210..2f06c88eba 100644--- a/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs+++ b/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs@@ -2,6 +2,8 @@ use super::*;use crate::desktop::notifications::types::CoreNotificationCategory;use crate::storage::{MemoryStorage, Scope, StorageBackend};+const WS: &str = "/workspace/a";+fn docs_in(storage: &MemoryStorage, scope: &str) -> Docs {Docs::over(&storage.for_scope(&Scope::new(scope).unwrap()).unwrap())}@@ -88,13 +90,62 @@ fn identical_content_within_a_minute_is_skipped() {#[test]fn content_older_than_the_window_is_not_a_duplicate() {let store = docs();- store.insert(¬e("a", "slack", "hi", 120), false).unwrap();+ let dedup = dedup_id("slack", Some("acct"), "New message", "hi");+ let stale = (Utc::now() - Duration::seconds(120)).timestamp_millis();+ store+ .0+ .run(|docs| async move {+ docs.put(DEDUP, &dedup, json!({ "last_ms": stale }), Precondition::Absent)+ .await+ .map(|_| ())+ })+ .unwrap();assert!(!store.exists_recent("slack", Some("acct"), "New message", "hi").unwrap());assert!(store.insert(¬e("b", "slack", "hi", 0), true).unwrap());}+#[test]+fn dedup_follows_arrival_not_the_notifications_own_timestamp() {+ let store = docs();+ // A delayed event (stamped two minutes ago) and a future-dated one both+ // arrived now, so identical content right after is a duplicate either way.+ assert!(store.insert(¬e("a", "slack", "late", 120), true).unwrap());+ assert!(!store.insert(¬e("b", "slack", "late", 0), true).unwrap());+ assert!(store.insert(¬e("c", "slack", "future", -3600), true).unwrap());+ assert!(!store.insert(¬e("d", "slack", "future", 0), true).unwrap());+}++#[test]+fn a_failed_insert_releases_its_dedup_claim() {+ let store = docs();+ store.insert(¬e("taken", "slack", "first", 0), false).unwrap();+ // Same id, new content: the claim succeeds, the notification put fails.+ assert!(store.insert(¬e("taken", "slack", "second", 0), true).is_err());+ assert!(+ !store+ .exists_recent("slack", Some("acct"), "New message", "second")+ .unwrap(),+ "the claim was rolled back"+ );+ assert!(store.insert(¬e("fresh", "slack", "second", 0), true).unwrap());+}++#[test]+fn workspaces_keep_core_notifications_apart() {+ let store = docs();+ assert!(store.insert_core_notification("/workspace/a", &event("e", 1)).unwrap());+ assert!(store.insert_core_notification("/workspace/b", &event("e", 2)).unwrap());+ let a = store.list_core_notifications("/workspace/a", false, 10).unwrap();+ assert_eq!(a.len(), 1);+ assert_eq!(a[0].timestamp_ms, 1);+ assert!(store.mark_core_notification_read("/workspace/a", "e").unwrap());+ assert_eq!(store.unread_core_notification_count("/workspace/a").unwrap(), 0);+ assert_eq!(store.unread_core_notification_count("/workspace/b").unwrap(), 1);+ assert!(!store.mark_core_notification_read("/workspace/c", "e").unwrap());+}+#[test]fn concurrent_duplicates_insert_once() {let store = docs();