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
chore(threads): remove unused imports in channel projection
Steven Enamakel050e4a304f3d
diff --git a/crates/openhuman-core/src/threads/channel_projection.rs b/crates/openhuman-core/src/threads/channel_projection.rsindex 5c467d63cd..cbc5182546 100644--- a/crates/openhuman-core/src/threads/channel_projection.rs+++ b/crates/openhuman-core/src/threads/channel_projection.rs@@ -7,17 +7,15 @@//! guesses from a sender, recent message, or equality between provider and row//! identifiers.-use std::sync::Arc;-use anyhow::{Context, Result, anyhow};use serde::{Deserialize, Serialize};use serde_json::{Value, json};use sha2::{Digest, Sha256};-use tinystoragedrivers::{CollectionSpec, ErrorKind, Precondition, Scope};+use tinystoragedrivers::{CollectionSpec, ErrorKind, Precondition};use tinychannels_bus::{ChannelRef, ConversationRef};use crate::core::runtime::{DispatchCtx, Tenant, tenant::tenant_key};-use crate::storage::{self, StorageBackend, documents::Repo};+use crate::storage::{self, documents::Repo};const DOMAIN: &str = "threads::channel_projection";const COLLECTION: &str = "thread_channel_messages";diff --git a/crates/openhuman-core/src/threads/channel_projection_tests.rs b/crates/openhuman-core/src/threads/channel_projection_tests.rsnew file mode 100644index 0000000000..a66b3254e3--- /dev/null+++ b/crates/openhuman-core/src/threads/channel_projection_tests.rs@@ -0,0 +1,89 @@+use super::*;+use std::sync::Arc;+use crate::storage::{Scope, StorageBackend};+use tinychannels_bus::ConversationKind;++fn repo(backend: &Arc<dyn StorageBackend>) -> Repo {+ Repo::on(backend, &Scope::local(), DOMAIN, collections).unwrap()+}++fn key(+ tenant_key: &str,+ account_id: Option<&str>,+ conversation_id: &str,+ topic_id: Option<&str>,+ provider_message_id: &str,+) -> MessageBindingKey {+ MessageBindingKey {+ tenant_key: tenant_key.to_owned(),+ channel: ChannelRef {+ id: "telegram".into(),+ account_id: account_id.map(str::to_owned),+ },+ conversation: ConversationRef {+ kind: ConversationKind::Thread,+ id: conversation_id.into(),+ scope_id: Some("workspace-1".into()),+ parent_id: Some("group-1".into()),+ thread_id: Some("thread-address-1".into()),+ topic_id: topic_id.map(str::to_owned),+ },+ provider_message_id: provider_message_id.into(),+ }+}++#[test]+fn provider_receipt_maps_to_the_exact_thread_and_row_after_restart() {+ let backend: Arc<dyn StorageBackend> = Arc::new(crate::storage::MemoryStorage::new());+ let first = repo(&backend);+ let binding = key("tenant-agent-a", Some("account-1"), "conversation-1", Some("topic-1"), "provider-17");++ bind_in(&first, binding.clone(), "channel:thread-a").unwrap();+ assert_eq!(resolve_in(&first, &binding).unwrap(), None, "a provider receipt is not a persisted UI row");+ bind_row_in(&first, binding.clone(), "channel:thread-a", "user:row-9").unwrap();++ // A fresh Repository simulates process restart against the same backend.+ let restarted = repo(&backend);+ assert_eq!(+ resolve_in(&restarted, &binding).unwrap(),+ Some(ProjectedMessageTarget {+ thread_id: "channel:thread-a".into(),+ row_id: "user:row-9".into(),+ })+ );+}++#[test]+fn provider_receipts_are_scoped_by_tenant_account_and_full_conversation() {+ let backend: Arc<dyn StorageBackend> = Arc::new(crate::storage::MemoryStorage::new());+ let repo = repo(&backend);+ let original = key("tenant-agent-a", Some("account-1"), "conversation-1", Some("topic-1"), "provider-17");+ bind_in(&repo, original.clone(), "channel:thread-a").unwrap();+ bind_row_in(&repo, original.clone(), "channel:thread-a", "row-a").unwrap();++ for other in [+ key("tenant-agent-b", Some("account-1"), "conversation-1", Some("topic-1"), "provider-17"),+ key("tenant-agent-a", Some("account-2"), "conversation-1", Some("topic-1"), "provider-17"),+ key("tenant-agent-a", Some("account-1"), "conversation-1", Some("topic-2"), "provider-17"),+ key("tenant-agent-a", Some("account-1"), "conversation-2", Some("topic-1"), "provider-17"),+ key("tenant-agent-a", Some("account-1"), "conversation-1", Some("topic-1"), "provider-18"),+ ] {+ assert_eq!(resolve_in(&repo, &other).unwrap(), None);+ }+}++#[test]+fn sender_scoped_threads_can_share_a_conversation_without_overwriting() {+ let backend: Arc<dyn StorageBackend> = Arc::new(crate::storage::MemoryStorage::new());+ let repo = repo(&backend);+ let alice = key("tenant", Some("account"), "group", Some("topic"), "alice-message");+ let bob = key("tenant", Some("account"), "group", Some("topic"), "bob-message");++ bind_in(&repo, alice.clone(), "channel:alice").unwrap();+ bind_in(&repo, bob.clone(), "channel:bob").unwrap();+ bind_row_in(&repo, alice.clone(), "channel:alice", "row-alice").unwrap();+ bind_row_in(&repo, bob.clone(), "channel:bob", "row-bob").unwrap();+ assert_eq!(resolve_in(&repo, &alice).unwrap().unwrap().thread_id, "channel:alice");+ assert_eq!(resolve_in(&repo, &bob).unwrap().unwrap().thread_id, "channel:bob");+ assert!(bind_in(&repo, alice, "channel:other").is_err());+}