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 for desktop notifications
Steven Enamakel73caffe504c5
diff --git a/crates/openhuman-core/src/desktop/notifications/store_documents.rs b/crates/openhuman-core/src/desktop/notifications/store_documents.rsindex ea99a925d8..5f6b9e82d3 100644--- a/crates/openhuman-core/src/desktop/notifications/store_documents.rs+++ b/crates/openhuman-core/src/desktop/notifications/store_documents.rs@@ -44,7 +44,7 @@ use crate::storage::documents::{compare_and_swap, text, Repo, CAS_ATTEMPTS};use crate::storage::{DocumentStore, DocumentStoreExt, StorageError};pub(super) const NOTIFICATIONS: &str = "integration_notifications";-const DEDUP: &str = "notification_dedup";+pub(super) const DEDUP: &str = "notification_dedup";pub(super) const SETTINGS: &str = "notification_settings";pub(super) const CORE: &str = "core_notifications";@@ -194,7 +194,7 @@ fn to_notification(stored: &Versioned<Value>) -> IntegrationNotification {/// The dedup document id for one piece of content. Each part is length/// prefixed, so no two distinct tuples hash the same input.-fn dedup_id(provider: &str, account_id: Option<&str>, title: &str, body: &str) -> String {+pub(super) fn dedup_id(provider: &str, account_id: Option<&str>, title: &str, body: &str) -> String {let mut hasher = Sha256::new();for part in [Some(provider), account_id, Some(title), Some(body)] {match part {diff --git a/crates/openhuman-core/src/desktop/notifications/store_tests.rs b/crates/openhuman-core/src/desktop/notifications/store_tests.rsindex 01e08b0ced..0879719d7a 100644--- a/crates/openhuman-core/src/desktop/notifications/store_tests.rs+++ b/crates/openhuman-core/src/desktop/notifications/store_tests.rs@@ -76,14 +76,41 @@ fn exists_recent_returns_true_without_account_id_when_matching() {// ── exists_recent: negative cases (expired window) ─────────────────────────+/// Files an arrival of the content `secs_ago` seconds in the past, as the+/// store would have when the notification came in then.+fn stamp_arrival(config: &Config, n: &IntegrationNotification, secs_ago: i64) {+ let opened = crate::storage::local::open("notifications::test", &config.workspace_dir).unwrap();+ let docs = std::sync::Arc::clone(opened.scoped().unwrap().documents());+ let id = super::super::store_documents::dedup_id(+ &n.provider,+ n.account_id.as_deref(),+ &n.title,+ &n.body,+ );+ let last_ms = (Utc::now() - Duration::seconds(secs_ago)).timestamp_millis();+ crate::storage::block_on(async move {+ docs.ensure_collection(&tinystoragedrivers::CollectionSpec::new(+ super::super::store_documents::DEDUP,+ ))+ .await?;+ docs.put(+ super::super::store_documents::DEDUP,+ &id,+ serde_json::json!({ "last_ms": last_ms }),+ tinystoragedrivers::Precondition::None,+ )+ .await+ })+ .unwrap();+}+#[test]fn exists_recent_returns_false_for_entries_older_than_60s() {let dir = TempDir::new().unwrap();let config = test_config(&dir);- let mut n = sample_notification_with("old-1", "slack", Some("acct-1"), "Hello", "World");- n.received_at = Utc::now() - Duration::seconds(61);- insert(&config, &n).unwrap();+ let n = sample_notification_with("old-1", "slack", Some("acct-1"), "Hello", "World");+ stamp_arrival(&config, &n, 61);assert!(!exists_recent(&config, "slack", Some("acct-1"), "Hello", "World").unwrap(),@@ -91,6 +118,17 @@ fn exists_recent_returns_false_for_entries_older_than_60s() {);}+#[test]+fn exists_recent_returns_true_for_content_that_arrived_just_now() {+ let dir = TempDir::new().unwrap();+ let config = test_config(&dir);++ let n = sample_notification_with("new-1", "slack", Some("acct-1"), "Hello", "World");+ insert(&config, &n).unwrap();++ assert!(exists_recent(&config, "slack", Some("acct-1"), "Hello", "World").unwrap());+}+#[test]fn exists_recent_returns_false_for_entry_exactly_at_60s_boundary() {// received_at = now - 60s is outside the `>= -60 seconds` window in SQLite.@@ -258,14 +296,13 @@ fn insert_if_not_recent_after_expiry_inserts_again() {let dir = TempDir::new().unwrap();let config = test_config(&dir);- // Write an expired duplicate directly (bypass insert_if_not_recent to- // set received_at in the past).- let mut old = sample_notification_with("old-id", "slack", None, "Alert", "Server down");- old.received_at = Utc::now() - Duration::seconds(120);+ // The same content arrived two minutes ago.+ let old = sample_notification_with("old-id", "slack", None, "Alert", "Server down");insert(&config, &old).unwrap();+ stamp_arrival(&config, &old, 120);// Now insert_if_not_recent should allow the same content because the- // prior entry is older than 60 s.+ // prior arrival is older than 60 s.let fresh = sample_notification_with("fresh-id", "slack", None, "Alert", "Server down");assert!(insert_if_not_recent(&config, &fresh).unwrap(),