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(ops): add client tests for ops module
Steven Enamakel8224f9ffb667
diff --git a/crates/openhuman-core/src/modules/ops.rs b/crates/openhuman-core/src/modules/ops.rsindex d16336eaf3..d8e620218b 100644--- a/crates/openhuman-core/src/modules/ops.rs+++ b/crates/openhuman-core/src/modules/ops.rs@@ -395,3 +395,7 @@ mod tests;#[cfg(test)]#[path = "ops_components_tests.rs"]mod components_tests;++#[cfg(test)]+#[path = "ops_client_tests.rs"]+mod client_tests;diff --git a/crates/openhuman-core/src/modules/ops_client_tests.rs b/crates/openhuman-core/src/modules/ops_client_tests.rsindex ca4c5da1bf..9b691dce78 100644--- a/crates/openhuman-core/src/modules/ops_client_tests.rs+++ b/crates/openhuman-core/src/modules/ops_client_tests.rs@@ -1,19 +1,34 @@+//! Composition tests for [`super::client`]: the tinybus client, the registry and+//! the shared Sentry reporter wired together. The client's own behaviour (tuple+//! arity, confidentiality, error classification, object clients, deadlines) is+//! tested in `tinybus::module`.+use super::*;+use tinybus::module::ModuleCallError;#[tokio::test]async fn a_disabled_client_is_unavailable_before_core_startup() {let mut config = Config::default();config.modules.enabled = false;- let result = ModuleClient::new(config)+ let result = client(config).call::<serde_json::Value>("tinyhosts", "Providers", ()).await;assert_eq!(result, Err(ModuleCallError::Unavailable));}+#[tokio::test]+async fn confidential_calls_do_not_fall_back_when_disabled() {+ let mut config = Config::default();+ config.modules.enabled = false;+ let result = client(config)+ .call_confidential::<serde_json::Value>("tinywallet", "SignTransaction", ("secret-value",))+ .await;+ assert_eq!(result, Err(ModuleCallError::Unavailable));+}+#[tokio::test]async fn unknown_modules_are_not_loaded_or_reported_using_untrusted_ids() {- let client = ModuleClient::new(Config::default());- let result = client+ let result = client(Config::default()).call::<serde_json::Value>("private-user-path-and-token", "Anything", ()).await;assert_eq!(result, Err(ModuleCallError::Unavailable));@@ -23,29 +38,6 @@ async fn unknown_modules_are_not_loaded_or_reported_using_untrusted_ids() {.contains("private-user-path-and-token"));}-#[cfg(not(feature = "modules"))]-#[tokio::test]-async fn a_client_without_the_loader_never_falls_back_to_an_implementation() {- let result = ModuleClient::new(Config::default())- .call::<serde_json::Value>("tinyhosts", "Providers", ())- .await;- assert_eq!(result, Err(ModuleCallError::Unavailable));-}--#[cfg(feature = "modules")]-#[test]-fn remote_fault_text_is_not_part_of_the_public_error() {- let error = tinybus::Error::MethodFailed {- name: "private-provider".to_string(),- message: "secret-token /home/private-user document content".to_string(),- };- assert_eq!(classify(&error).0, ModuleCallError::ModuleFault);- assert_eq!(- classify(&error).0.to_string(),- "MODULE_CALL_REPORTED: module execution failed"- );-}-#[test]fn subsequent_product_reports_are_demoted() {for error in [@@ -60,76 +52,42 @@ fn subsequent_product_reports_are_demoted() {}}-#[tokio::test]-async fn confidential_calls_do_not_fall_back_when_disabled() {- let mut config = Config::default();- config.modules.enabled = false;- let result = ModuleClient::new(config)- .call_confidential::<serde_json::Value>("tinywallet", "SignTransaction", ("secret-value",))- .await;- assert_eq!(result, Err(ModuleCallError::Unavailable));-}--#[cfg(feature = "modules")]-#[test]-fn wire_unknown_method_is_an_incompatible_contract() {- let error = tinybus::Error::MethodFailed {- name: tinybus::Error::UNKNOWN_METHOD.to_string(),- message: "private-response-content".to_string(),- };- assert_eq!(classify(&error).0, ModuleCallError::IncompatibleContract);- assert_eq!(- classify(&tinybus::Error::ConnectionClosed).0,- ModuleCallError::TransportFailed- );-}--#[cfg(feature = "modules")]-#[derive(Clone)]-struct BusFixture(std::sync::Arc<std::sync::atomic::AtomicUsize>);--#[cfg(feature = "modules")]-#[tinybus::interface(name = "test.ModuleClient")]-impl BusFixture {- async fn sum(&self, left: u32, right: u32) -> tinybus::Result<u32> {- self.0.fetch_add(1, std::sync::atomic::Ordering::SeqCst);- Ok(left + right)- }-- async fn fault(&self) -> tinybus::Result<()> {- Err(tinybus::Error::MethodFailed {- name: "test.ProviderFault".to_string(),- message: "secret-value /home/private-user/payload".to_string(),- })- }-- async fn unavailable(&self) -> tinybus::Result<()> {- Err(tinybus::Error::ModuleUnavailable {- module: "test.ModuleClient".to_string(),- state: "faulted".to_string(),- detail: "module stopped accepting calls".to_string(),- })- }-- async fn malformed_json(&self) -> tinybus::Result<String> {- Ok("{ private response data".to_owned())- }+#[cfg(feature = "crash-reporting")]+mod reported {+ use super::*;+ use tinybus::{broker::Broker, transport::memory::MemoryBus, Connection, ObjectPath};- async fn delayed(&self) -> tinybus::Result<()> {- tokio::time::sleep(std::time::Duration::from_millis(100)).await;- Ok(())+ #[derive(Clone)]+ struct BusFixture;++ #[tinybus::interface(name = "test.ModuleClient")]+ impl BusFixture {+ async fn sum(&self, left: u32, right: u32) -> tinybus::Result<u32> {+ Ok(left + right)+ }++ async fn fault(&self) -> tinybus::Result<()> {+ Err(tinybus::Error::MethodFailed {+ name: "test.ProviderFault".to_string(),+ message: "secret-value /home/private-user/payload".to_string(),+ })+ }++ async fn unavailable(&self) -> tinybus::Result<()> {+ Err(tinybus::Error::ModuleUnavailable {+ module: "test.ModuleClient".to_string(),+ state: "faulted".to_string(),+ detail: "module stopped accepting calls".to_string(),+ })+ }++ async fn malformed_json(&self) -> tinybus::Result<String> {+ Ok("{ private response data".to_owned())+ }}-}-#[cfg(all(feature = "modules", feature = "crash-reporting"))]-#[test]-fn independent_invocation_faults_report_separately_around_a_success() {- use tinybus::{broker::Broker, transport::memory::MemoryBus, Connection, ObjectPath};- let runtime = tokio::runtime::Builder::new_current_thread()- .enable_all()- .build()- .unwrap();- let proxy = runtime.block_on(async {+ /// A proxy to the fixture object, and the service that must outlive it.+ async fn fixture() -> (tinybus::Proxy, Connection) {let bus = MemoryBus::new();Broker::new().spawn(bus.clone());let service = Connection::connect(bus.connect().await.unwrap())@@ -139,10 +97,7 @@ fn independent_invocation_faults_report_separately_around_a_success() {.await.unwrap();service- .serve_at(- ObjectPath::new("/test/ModuleClient").unwrap(),- BusFixture(std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0))),- )+ .serve_at(ObjectPath::new("/test/ModuleClient").unwrap(), BusFixture).await.unwrap();service.request_name("test.ModuleClient").await.unwrap();@@ -154,308 +109,116 @@ fn independent_invocation_faults_report_separately_around_a_success() {).unwrap();(proxy, service)- });- let (proxy, _service) = proxy;- let record = registry::find("tinysearch").unwrap();- let events = sentry::test::with_captured_events(|| {- runtime.block_on(async {- assert_eq!(- invoke_proxy::<()>(record, &proxy, "Fault", (), false).await,- Err(ModuleCallError::ModuleFault)- );+ }++ fn current_thread() -> tokio::runtime::Runtime {+ tokio::runtime::Builder::new_current_thread()+ .enable_all()+ .build()+ .unwrap()+ }++ #[test]+ fn independent_invocation_faults_report_separately_around_a_success() {+ let runtime = current_thread();+ let (proxy, _service) = runtime.block_on(fixture());+ let client = fixture_client(proxy);+ let events = sentry::test::with_captured_events(|| {+ runtime.block_on(async {+ let fault = || client.call::<()>("tinysearch", "Fault", ());+ assert_eq!(fault().await, Err(ModuleCallError::ModuleFault));+ assert_eq!(+ client.call::<u32>("tinysearch", "Sum", (20, 22)).await,+ Ok(42)+ );+ assert_eq!(fault().await, Err(ModuleCallError::ModuleFault));+ });+ });+ assert_eq!(events.len(), 2, "{events:?}");+ for event in &events {assert_eq!(- invoke_proxy::<u32>(record, &proxy, "Sum", (20, 22), false).await,- Ok(42)+ event.tags.get("reason_code").map(String::as_str),+ Some("module_fault"));+ let captured = format!("{event:?}");+ assert!(!captured.contains("secret-value"));+ assert!(!captured.contains("/home/private-user"));+ }+ }++ #[test]+ fn cached_native_module_unavailability_is_reported_once() {+ let runtime = current_thread();+ let (proxy, _service) = runtime.block_on(fixture());+ let client = fixture_client(proxy);+ let events = sentry::test::with_captured_events(|| {+ runtime.block_on(async {+ for _ in 0..2 {+ assert_eq!(+ client.call::<()>("tinybox", "Unavailable", ()).await,+ Err(ModuleCallError::Unavailable)+ );+ }+ });+ });+ assert_eq!(events.len(), 1, "{events:?}");+ assert_eq!(+ events[0].tags.get("reason_code").map(String::as_str),+ Some("module_unavailable")+ );+ }++ #[test]+ fn malformed_inner_json_from_a_real_bus_reply_is_reported_as_a_sanitized_fault() {+ let runtime = current_thread();+ let (proxy, _service) = runtime.block_on(fixture());+ let client = fixture_client(proxy);+ let events = sentry::test::with_captured_events(|| {assert_eq!(- invoke_proxy::<()>(record, &proxy, "Fault", (), false).await,+ runtime.block_on(client.call_json::<serde_json::Value>(+ "tinyconnectors",+ "MalformedJson",+ ()+ )),Err(ModuleCallError::ModuleFault));});- });-- assert_eq!(events.len(), 2, "{events:?}");- for event in &events {+ assert_eq!(events.len(), 1, "{events:?}");assert_eq!(- event.tags.get("reason_code").map(String::as_str),+ events[0].tags.get("reason_code").map(String::as_str),Some("module_fault"));- let captured = format!("{event:?}");- assert!(!captured.contains("secret-value"));- assert!(!captured.contains("/home/private-user"));+ assert!(!format!("{events:?}").contains("private response data"));}-}-#[cfg(all(feature = "modules", feature = "crash-reporting"))]-#[test]-fn cached_native_module_unavailability_is_reported_once() {- use tinybus::{broker::Broker, transport::memory::MemoryBus, Connection, ObjectPath};- let runtime = tokio::runtime::Builder::new_current_thread()- .enable_all()- .build()- .unwrap();- let proxy = runtime.block_on(async {- let bus = MemoryBus::new();- Broker::new().spawn(bus.clone());- let service = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- let caller = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- service- .serve_at(- ObjectPath::new("/test/ModuleClient").unwrap(),- BusFixture(std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0))),- )- .await- .unwrap();- service.request_name("test.ModuleClient").await.unwrap();- let proxy = caller- .proxy(- "test.ModuleClient",- "/test/ModuleClient",- "test.ModuleClient",- )- .unwrap();- (proxy, service)- });- let (proxy, _service) = proxy;- let record = registry::find("tinybox").unwrap();- let events = sentry::test::with_captured_events(|| {- runtime.block_on(async {- for _ in 0..2 {- assert_eq!(- invoke_proxy::<()>(record, &proxy, "Unavailable", (), false).await,- Err(ModuleCallError::Unavailable)- );- }+ #[test]+ fn unknown_module_failures_emit_only_safe_registry_metadata() {+ let events = sentry::test::with_captured_events(|| {+ current_thread().block_on(async {+ let client = client(Config::default());+ for _ in 0..2 {+ let error = client+ .call::<serde_json::Value>(+ "private-token /home/private-user",+ "secret-member",+ ("private-content",),+ )+ .await+ .unwrap_err();+ assert_eq!(error, ModuleCallError::Unavailable);+ assert!(!error.to_string().contains("private"));+ }+ });});- });-- assert_eq!(events.len(), 1, "{events:?}");- assert_eq!(- events[0].tags.get("reason_code").map(String::as_str),- Some("module_unavailable")- );-}--#[cfg(feature = "modules")]-#[tokio::test]-async fn bus_calls_preserve_tuple_arity_and_never_downgrade_confidentiality() {- use tinybus::{broker::Broker, transport::memory::MemoryBus, Connection, ObjectPath};- let bus = MemoryBus::new();- Broker::new().spawn(bus.clone());- let service = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- let caller = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- let calls = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));- service- .serve_at(- ObjectPath::new("/test/ModuleClient").unwrap(),- BusFixture(calls.clone()),- )- .await- .unwrap();- service.request_name("test.ModuleClient").await.unwrap();- let proxy = caller- .proxy(- "test.ModuleClient",- "/test/ModuleClient",- "test.ModuleClient",- )- .unwrap();- let record = registry::find("tinysearch").unwrap();- assert_eq!(- invoke_proxy::<u32>(record, &proxy, "Sum", (20_u32, 22_u32), false).await,- Ok(42)- );- assert_eq!(- invoke_proxy::<u32>(record, &proxy, "Sum", (20_u32, 22_u32), true).await,- Err(ModuleCallError::TransportFailed)- );- assert_eq!(calls.load(std::sync::atomic::Ordering::SeqCst), 1);- assert_eq!(- invoke_proxy::<()>(record, &proxy, "Fault", (), false).await,- Err(ModuleCallError::ModuleFault)- );- assert_eq!(- invoke_proxy::<()>(record, &proxy, "MissingMember", (), false).await,- Err(ModuleCallError::IncompatibleContract)- );-}--#[cfg(feature = "modules")]-#[tokio::test]-async fn private_object_clients_dispatch_only_to_the_configured_object() {- use tinybus::{broker::Broker, transport::memory::MemoryBus, Connection, ObjectPath};- let bus = MemoryBus::new();- Broker::new().spawn(bus.clone());- let service = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- let caller = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- let root_calls = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));- let child_calls = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));- service- .serve_at(- ObjectPath::new("/test/ModuleClient").unwrap(),- BusFixture(root_calls.clone()),- )- .await- .unwrap();- service- .serve_at(- ObjectPath::new("/test/ModuleClient/workspace_1").unwrap(),- BusFixture(child_calls.clone()),- )- .await- .unwrap();- service.request_name("test.ModuleClient").await.unwrap();- let proxy = caller- .proxy(- "test.ModuleClient",- "/test/ModuleClient/workspace_1",- "test.ModuleClient",- )- .unwrap();- let record = registry::find("tinysearch").unwrap();- let object = ModuleObjectClient { record, proxy };-- assert_eq!(object.call::<u32>("Sum", (20_u32, 22_u32)).await, Ok(42));- assert_eq!(root_calls.load(std::sync::atomic::Ordering::SeqCst), 0);- assert_eq!(child_calls.load(std::sync::atomic::Ordering::SeqCst), 1);-}--#[cfg(feature = "modules")]-#[test]-fn configured_client_timeout_overrides_the_default_for_fixture_calls() {- use tinybus::{broker::Broker, transport::memory::MemoryBus, Connection, ObjectPath};- let runtime = tokio::runtime::Builder::new_current_thread()- .enable_all()- .build()- .unwrap();- let (proxy, _service) = runtime.block_on(async {- let bus = MemoryBus::new();- Broker::new().spawn(bus.clone());- let service = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- let caller = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- service- .serve_at(- ObjectPath::new("/test/ModuleClient").unwrap(),- BusFixture(std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0))),- )- .await- .unwrap();- service.request_name("test.ModuleClient").await.unwrap();- let proxy = caller- .proxy(- "test.ModuleClient",- "/test/ModuleClient",- "test.ModuleClient",- )- .unwrap();- (proxy, service)- });- let client = crate::modules::ops::fixture_client(proxy).with_timeout(std::time::Duration::from_millis(5));- let result = runtime.block_on(client.call::<()>("tinysearch", "Delayed", ()));- assert_eq!(result, Err(ModuleCallError::TransportFailed));-}--#[cfg(all(feature = "modules", feature = "crash-reporting"))]-#[test]-fn malformed_inner_json_from_a_real_bus_reply_is_reported_as_a_sanitized_fault() {- use tinybus::{broker::Broker, transport::memory::MemoryBus, Connection, ObjectPath};- let runtime = tokio::runtime::Builder::new_current_thread()- .enable_all()- .build()- .unwrap();- let (proxy, _service) = runtime.block_on(async {- let bus = MemoryBus::new();- Broker::new().spawn(bus.clone());- let service = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- let caller = Connection::connect(bus.connect().await.unwrap())- .await- .unwrap();- service- .serve_at(- ObjectPath::new("/test/ModuleClient").unwrap(),- BusFixture(std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0))),- )- .await- .unwrap();- service.request_name("test.ModuleClient").await.unwrap();- let proxy = caller- .proxy(- "test.ModuleClient",- "/test/ModuleClient",- "test.ModuleClient",- )- .unwrap();- (proxy, service)- });- let client = crate::modules::ops::fixture_client(proxy);- let events = sentry::test::with_captured_events(|| {+ assert_eq!(events.len(), 1, "{events:?}");assert_eq!(- runtime.block_on(client.call_json::<serde_json::Value>(- "tinysearch",- "MalformedJson",- ()- )),- Err(ModuleCallError::ModuleFault)+ events[0].tags.get("module").map(String::as_str),+ Some("unregistered"));- });- assert_eq!(events.len(), 1, "{events:?}");- assert_eq!(- events[0].tags.get("reason_code").map(String::as_str),- Some("module_fault")- );- let captured = format!("{events:?}");- assert!(!captured.contains("private response data"));-}--#[cfg(feature = "crash-reporting")]-#[test]-fn unknown_module_failures_emit_only_safe_registry_metadata() {- let events = sentry::test::with_captured_events(|| {- let runtime = tokio::runtime::Builder::new_current_thread()- .build()- .unwrap();- runtime.block_on(async {- let client = ModuleClient::new(Config::default());- for _ in 0..2 {- let error = client- .call::<serde_json::Value>(- "private-token /home/private-user",- "secret-member",- ("private-content",),- )- .await- .unwrap_err();- assert_eq!(error, ModuleCallError::Unavailable);- assert!(!error.to_string().contains("private"));- }- });- });- assert_eq!(events.len(), 1, "{events:?}");- assert_eq!(- events[0].tags.get("module").map(String::as_str),- Some("unregistered")- );- assert_eq!(- events[0].tags.get("reason_code").map(String::as_str),- Some("unknown_module")- );- assert!(!format!("{events:?}").contains("private"));+ assert_eq!(+ events[0].tags.get("reason_code").map(String::as_str),+ Some("unknown_module")+ );+ assert!(!format!("{events:?}").contains("private"));+ }}