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(inference): add tests for cloud embedding adapter
Steven Enamakel4cc8076ee2c6
diff --git a/crates/openhuman-core/src/inference/embedding_host/cloud_adapter_tests.rs b/crates/openhuman-core/src/inference/embedding_host/cloud_adapter_tests.rsindex d3683a4439..5ef5276437 100644--- a/crates/openhuman-core/src/inference/embedding_host/cloud_adapter_tests.rs+++ b/crates/openhuman-core/src/inference/embedding_host/cloud_adapter_tests.rs@@ -169,3 +169,129 @@ async fn api_key_is_refused_over_plaintext_non_loopback() {"{err}");}++/// Drains `rx` until the cloud-embedding disclosure for `marker` arrives.+/// Tolerates unrelated events: the bus is process-wide.+async fn find_embedding_disclosure(+ rx: &mut tinybus::events::EventReceiver<crate::core::events::DomainEvent>,+ marker: &str,+) -> (Option<String>, Option<String>, Option<String>) {+ loop {+ match rx.recv().await {+ Some(crate::core::events::DomainEvent::ExternalTransferPending {+ descriptor,+ thread_id,+ client_id,+ request_id,+ }) if descriptor.service == marker => return (thread_id, client_id, request_id),+ Some(_) => continue,+ None => panic!("the bus closed before the disclosure arrived"),+ }+ }+}++fn unreachable_embedder(model: &str) -> OpenHumanCloudEmbeddingModel {+ OpenHumanCloudEmbeddingModel::new(+ Some("http://127.0.0.1:0".into()),+ Some(std::env::temp_dir().join("openhuman_embeddings_routing_state")),+ false,+ model,+ DEFAULT_CLOUD_EMBEDDING_DIMENSIONS,+ )+}++/// A cloud-embedding call made during a web-chat turn discloses its egress to+/// that chat. The chat rides the embedder explicitly (built for the turn from+/// its approval context); it is not read from the running task, which is why+/// this call, awaited on a plain test task, still routes.+#[tokio::test]+async fn a_cloud_embedding_call_in_a_chat_turn_discloses_to_that_chat() {+ crate::core::bus::init().await.expect("bus init");+ let mut rx = crate::core::bus::BUS.get().unwrap().receiver();+ let marker = "embed-routed-to-the-turns-chat";+ let chat = ApprovalChatContext {+ thread_id: "thread-embed".into(),+ client_id: "client-embed".into(),+ request_id: Some("req-embed".into()),+ };+ let embedder = unreachable_embedder(marker).routed_to(Some(chat));++ // The transport has nowhere to go; the disclosure precedes it.+ let _ = embedder+ .embed(&["what did I say about invoices?".to_string()])+ .await;++ let (thread_id, client_id, request_id) = find_embedding_disclosure(&mut rx, marker).await;+ assert_eq!(thread_id.as_deref(), Some("thread-embed"));+ assert_eq!(client_id.as_deref(), Some("client-embed"));+ assert_eq!(request_id.as_deref(), Some("req-embed"));+}++/// An embedder built with no chat (background sync, the embedding RPC) still+/// discloses, unrouted, and a blank or empty batch discloses nothing because+/// nothing leaves.+#[tokio::test]+async fn an_unrouted_embedder_discloses_without_a_chat() {+ crate::core::bus::init().await.expect("bus init");+ let mut rx = crate::core::bus::BUS.get().unwrap().receiver();+ let marker = "embed-without-a-chat";+ let embedder = unreachable_embedder(marker);++ let _ = embedder.embed(&[]).await;+ let _ = embedder.embed(&[" ".to_string()]).await;+ let _ = embedder.embed(&["real text".to_string()]).await;++ // The first disclosure for this marker is the third call's: the empty and+ // blank batches published nothing.+ let (thread_id, client_id, request_id) = find_embedding_disclosure(&mut rx, marker).await;+ assert_eq!((thread_id, client_id, request_id), (None, None, None));+ assert!(+ tokio::time::timeout(+ std::time::Duration::from_millis(200),+ find_embedding_disclosure(&mut rx, marker)+ )+ .await+ .is_err(),+ "only the batch that leaves is disclosed"+ );+}++/// `routed_to` re-routes a shared embedder per turn without touching the+/// original: each turn's disclosure reaches its own chat.+#[tokio::test]+async fn routing_is_per_embedder_not_shared() {+ crate::core::bus::init().await.expect("bus init");+ let mut rx = crate::core::bus::BUS.get().unwrap().receiver();+ let marker = "embed-routed-per-turn";+ let base = unreachable_embedder(marker);+ let chat = |thread: &str| ApprovalChatContext {+ thread_id: thread.into(),+ client_id: "c".into(),+ request_id: None,+ };++ let _ = base+ .routed_to(Some(chat("thread-a")))+ .embed(&["a".into()])+ .await;+ assert_eq!(+ find_embedding_disclosure(&mut rx, marker)+ .await+ .0+ .as_deref(),+ Some("thread-a")+ );+ let _ = base+ .routed_to(Some(chat("thread-b")))+ .embed(&["b".into()])+ .await;+ assert_eq!(+ find_embedding_disclosure(&mut rx, marker)+ .await+ .0+ .as_deref(),+ Some("thread-b")+ );+ let _ = base.embed(&["c".into()]).await;+ assert_eq!(find_embedding_disclosure(&mut rx, marker).await.0, None);+}