Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

style: apply rustfmt formatting across relay and thread tests

Steven Enamakel7a8bebf15f71
diff --git a/crates/openhuman-core/src/channels/providers/relay/channel_tests.rs b/crates/openhuman-core/src/channels/providers/relay/channel_tests.rs
index 09a826b68d..511549c10a 100644
--- a/crates/openhuman-core/src/channels/providers/relay/channel_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/channel_tests.rs
@@ -28,24 +28,25 @@ fn the_outbound_event_names_the_chat_and_carries_the_text() {
let wire = serde_json::to_value(sink().outbound_event(&SendMessage::new("x", "-100")))
.expect("serialize");
- assert!(wire.get("agent").is_none(), "the routing stamp is not on the wire");
+ assert!(
+ wire.get("agent").is_none(),
+ "the routing stamp is not on the wire"
+ );
}
#[tokio::test]
async fn send_publishes_under_the_callers_stamp_and_records_the_text() {
let mut events = crate::web_chat::subscribe_web_channel_events();
- let context = crate::core::runtime::CoreContext::for_test(
- crate::core::runtime::DomainSet::full(),
- None,
- )
- .derive_with(
- crate::core::runtime::ContextOverlay::new(
- crate::config::Config::default(),
- crate::core::runtime::DomainSet::full(),
- Default::default(),
- )
- .session_agent("u-relay-test"),
- );
+ let context =
+ crate::core::runtime::CoreContext::for_test(crate::core::runtime::DomainSet::full(), None)
+ .derive_with(
+ crate::core::runtime::ContextOverlay::new(
+ crate::config::Config::default(),
+ crate::core::runtime::DomainSet::full(),
+ Default::default(),
+ )
+ .session_agent("u-relay-test"),
+ );
let channel = Arc::new(RelayChannel::new(
"telegram",
"gw-stamp",
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rs
index 36cb158eb2..e0530bd4c0 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs
@@ -104,7 +104,8 @@ pub(crate) async fn run_relay_turn(
%error,
"[channels::relay] could not build the turn"
);
- let reply = "⚠️ This chat's assistant is not available right now. Please try again later.";
+ let reply =
+ "⚠️ This chat's assistant is not available right now. Please try again later.";
let _ = crate::channels::traits::Channel::send(
channel.as_ref(),
&crate::channels::SendMessage::new(reply, &params.chat_id),
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
index 0d5202acbe..0f18a22d52 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
@@ -1,7 +1,7 @@
+use super::super::channel::CHANNEL_OUTBOUND_EVENT;
use super::*;
use crate::agent::bus::{mock_agent_run_turn, AgentTurnRequest, AgentTurnResponse};
use crate::agent::turn_origin::AgentTurnOrigin;
-use super::super::channel::CHANNEL_OUTBOUND_EVENT;
use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};
use std::sync::Mutex;
@@ -98,7 +98,9 @@ async fn a_relayed_turn_runs_as_an_external_channel_and_keeps_its_thread() {
);
assert!(contents.contains(&"answer 1"), "{contents:?}");
assert!(
- contents.last().is_some_and(|c| c.contains("second question")),
+ contents
+ .last()
+ .is_some_and(|c| c.contains("second question")),
"{contents:?}"
);
@@ -142,8 +144,12 @@ async fn invalid_or_repeated_messages_start_no_turn() {
let p = params("m1", "hello");
let thread = p.thread_id();
- store::record_inbound(&workspace, &p, &thread).await.unwrap();
- let outcome = channel_relay_inbound(p).await.expect("duplicate is not an error");
+ store::record_inbound(&workspace, &p, &thread)
+ .await
+ .unwrap();
+ let outcome = channel_relay_inbound(p)
+ .await
+ .expect("duplicate is not an error");
let value = outcome.into_cli_compatible_json().unwrap();
let text = value.to_string();
assert!(text.contains("\"duplicate\":true"), "{text}");
diff --git a/crates/openhuman-core/src/channels/providers/relay/params.rs b/crates/openhuman-core/src/channels/providers/relay/params.rs
index 9ecf9ecab8..e878f17911 100644
--- a/crates/openhuman-core/src/channels/providers/relay/params.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/params.rs
@@ -73,7 +73,11 @@ impl RelayInboundParams {
if self.text.len() > MAX_TEXT_BYTES {
return Err(format!("text must be at most {MAX_TEXT_BYTES} bytes"));
}
- if self.attachments.as_ref().is_some_and(|list| !list.is_empty()) {
+ if self
+ .attachments
+ .as_ref()
+ .is_some_and(|list| !list.is_empty())
+ {
return Err("attachments are not supported by the relay yet".to_string());
}
Ok(())
@@ -94,9 +98,7 @@ impl RelayInboundParams {
/// The `/events` client id replies go to.
pub fn client_id(&self) -> &str {
- self.client_id
- .as_deref()
- .unwrap_or(DEFAULT_RELAY_CLIENT_ID)
+ self.client_id.as_deref().unwrap_or(DEFAULT_RELAY_CLIENT_ID)
}
/// A display title for a new thread.
diff --git a/crates/openhuman-core/src/channels/providers/relay/params_tests.rs b/crates/openhuman-core/src/channels/providers/relay/params_tests.rs
index 1b3bc1f446..a800d4cc85 100644
--- a/crates/openhuman-core/src/channels/providers/relay/params_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/params_tests.rs
@@ -28,7 +28,12 @@ fn the_thread_id_is_a_reserved_channel_id() {
assert_eq!(id, "channel:telegram/42/-100123");
assert_eq!(
id,
- crate::channels::bus::derive_inbound_thread_id("telegram", Some("42"), Some("-100123"), None),
+ crate::channels::bus::derive_inbound_thread_id(
+ "telegram",
+ Some("42"),
+ Some("-100123"),
+ None
+ ),
"the backend-relayed inbound path's derivation"
);
assert!(
@@ -78,7 +83,12 @@ fn ids_cannot_forge_another_chats_thread() {
assert!(validate_id("chat_id", bad).is_err(), "{bad:?}");
}
assert!(validate_id("chat_id", &"9".repeat(MAX_ID_LEN + 1)).is_err());
- for ok in ["-100123", "+15551234567", "[email protected]", "iMessage;+;chat1"] {
+ for ok in [
+ "-100123",
+ "+15551234567",
+ "iMessage;+;chat1",
+ ] {
validate_id("chat_id", ok).unwrap_or_else(|e| panic!("{ok}: {e}"));
}
}
@@ -95,9 +105,15 @@ fn every_field_is_checked() {
"sender_name",
Box::new(|p| p.sender_name = Some("a".repeat(MAX_SENDER_NAME_CHARS + 1))),
),
- ("sender_name", Box::new(|p| p.sender_name = Some("a\nb".into()))),
+ (
+ "sender_name",
+ Box::new(|p| p.sender_name = Some("a\nb".into())),
+ ),
("text", Box::new(|p| p.text = " ".into())),
- ("text", Box::new(|p| p.text = "x".repeat(MAX_TEXT_BYTES + 1))),
+ (
+ "text",
+ Box::new(|p| p.text = "x".repeat(MAX_TEXT_BYTES + 1)),
+ ),
(
"attachments",
Box::new(|p| p.attachments = Some(vec![json!({"url": "https://x"})])),
diff --git a/crates/openhuman-core/src/channels/providers/relay/schemas.rs b/crates/openhuman-core/src/channels/providers/relay/schemas.rs
index 73da9d93c7..04629aae3a 100644
--- a/crates/openhuman-core/src/channels/providers/relay/schemas.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/schemas.rs
@@ -95,16 +95,13 @@ fn handle_relay_inbound(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let params: RelayInboundParams = serde_json::from_value(Value::Object(params))
.map_err(|e| format!("invalid params: {e}"))?;
- channel_relay_inbound(params).await?.into_cli_compatible_json()
+ channel_relay_inbound(params)
+ .await?
+ .into_cli_compatible_json()
})
}
-fn field(
- name: &'static str,
- ty: TypeSchema,
- comment: &'static str,
- required: bool,
-) -> FieldSchema {
+fn field(name: &'static str, ty: TypeSchema, comment: &'static str, required: bool) -> FieldSchema {
FieldSchema {
name,
ty,
diff --git a/crates/openhuman-core/src/channels/providers/relay/schemas_tests.rs b/crates/openhuman-core/src/channels/providers/relay/schemas_tests.rs
index 52436db182..c696065b47 100644
--- a/crates/openhuman-core/src/channels/providers/relay/schemas_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/schemas_tests.rs
@@ -33,6 +33,8 @@ fn the_controller_is_registered() {
async fn malformed_params_are_refused_before_any_work() {
let mut params = Map::new();
params.insert("channel".into(), Value::String("telegram".into()));
- let err = handle_relay_inbound(params).await.expect_err("missing fields");
+ let err = handle_relay_inbound(params)
+ .await
+ .expect_err("missing fields");
assert!(err.contains("invalid params"), "{err}");
}
diff --git a/crates/openhuman-core/src/channels/providers/relay/store_tests.rs b/crates/openhuman-core/src/channels/providers/relay/store_tests.rs
index 391f573113..b34786d9c6 100644
--- a/crates/openhuman-core/src/channels/providers/relay/store_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/store_tests.rs
@@ -17,7 +17,10 @@ async fn an_inbound_message_is_recorded_once() {
let tmp = tempfile::tempdir().unwrap();
let p = params("m1", "hello");
let thread = p.thread_id();
- assert_eq!(record_inbound(tmp.path(), &p, &thread).await, Ok(Recorded::New));
+ assert_eq!(
+ record_inbound(tmp.path(), &p, &thread).await,
+ Ok(Recorded::New)
+ );
assert_eq!(
record_inbound(tmp.path(), &p, &thread).await,
Ok(Recorded::Duplicate),
diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
index 2586e84631..377dddfc0f 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
@@ -6,7 +6,9 @@ use super::super::supervision::spawn_supervised_listener;
use super::credentials::{hydrate_channel_credentials, RuntimeProxyClients};
use super::relay::start_relay_runtime;
use super::turn_parts::{build_channel_turn_parts, runtime_context, PromptToolDescs};
-use crate::channels::context::{DEFAULT_CHANNEL_INITIAL_BACKOFF_SECS, DEFAULT_CHANNEL_MAX_BACKOFF_SECS};
+use crate::channels::context::{
+ DEFAULT_CHANNEL_INITIAL_BACKOFF_SECS, DEFAULT_CHANNEL_MAX_BACKOFF_SECS,
+};
use crate::channels::traits;
use crate::config::Config;
use crate::core::bus::BUS;
diff --git a/crates/openhuman-core/src/threads/store/bus_tests.rs b/crates/openhuman-core/src/threads/store/bus_tests.rs
index 9e49e7bd21..efd851b150 100644
--- a/crates/openhuman-core/src/threads/store/bus_tests.rs
+++ b/crates/openhuman-core/src/threads/store/bus_tests.rs
@@ -525,7 +525,10 @@ async fn claimed_channel_turns_are_left_to_their_caller() {
}
let threads = crate::threads::store::list_threads(temp.path().to_path_buf()).expect("threads");
- assert!(threads.is_empty(), "a claimed turn is not mirrored: {threads:?}");
+ assert!(
+ threads.is_empty(),
+ "a claimed turn is not mirrored: {threads:?}"
+ );
}
#[test]
@@ -540,5 +543,9 @@ fn the_claim_list_is_bounded() {
assert!(claimed.contains("telegram", "m2"));
assert!(claimed.contains("telegram", "m4"));
assert!(!claimed.contains("discord", "m4"), "keyed by channel too");
- assert_eq!(claimed.keys.len(), 3, "a repeated claim is not stored twice");
+ assert_eq!(
+ claimed.keys.len(),
+ 3,
+ "a repeated claim is not stored twice"
+ );
}
diff --git a/crates/openhuman-core/src/threads/store/mod.rs b/crates/openhuman-core/src/threads/store/mod.rs
index 41df175466..63da832a20 100644
--- a/crates/openhuman-core/src/threads/store/mod.rs
+++ b/crates/openhuman-core/src/threads/store/mod.rs
@@ -31,8 +31,8 @@ pub mod blocking;
mod bus;
use tinyagents_session::threads as store;
-pub use bus::register_conversation_persistence_subscriber;
pub(crate) use bus::claim_channel_turn;
+pub use bus::register_conversation_persistence_subscriber;
pub use store::{
append_message, delete_messages_from, delete_thread, ensure_thread, get_messages,
is_deterministic_message_id, list_threads, purge_threads, reply_run_id, run_reply_message_id,
diff --git a/crates/openhuman-core/src/user_agents/surface_tests.rs b/crates/openhuman-core/src/user_agents/surface_tests.rs
index 4fe3fed194..2cf5295c58 100644
--- a/crates/openhuman-core/src/user_agents/surface_tests.rs
+++ b/crates/openhuman-core/src/user_agents/surface_tests.rs
@@ -142,7 +142,8 @@ fn delete_purge_and_the_channel_relay_are_open_to_users() {
#[test]
fn users_still_cannot_mint_channel_threads() {
// The relay derives `channel:` ids itself; a user choosing one is refused.
- let relayed = crate::channels::bus::derive_inbound_thread_id("telegram", Some("1"), Some("2"), None);
+ let relayed =
+ crate::channels::bus::derive_inbound_thread_id("telegram", Some("1"), Some("2"), None);
assert!(relayed.starts_with("channel:"), "{relayed}");
assert!(validate_user_thread_id(&relayed).is_err());
}
diff --git a/tests/saas_mode_e2e.rs b/tests/saas_mode_e2e.rs
index 9cc61526cf..e985708fe6 100644
--- a/tests/saas_mode_e2e.rs
+++ b/tests/saas_mode_e2e.rs
@@ -987,7 +987,9 @@ fn a_profile_holds_web_and_relayed_channel_threads() {
assert_eq!(event["structured"]["channel"], "telegram", "{event}");
assert_eq!(event["structured"]["chat_id"], "777", "{event}");
assert!(
- event["full_response"].as_str().is_some_and(|t| !t.is_empty()),
+ event["full_response"]
+ .as_str()
+ .is_some_and(|t| !t.is_empty()),
"{event}"
);
assert!(event.get("agent").is_none(), "no routing stamp on the wire");
@@ -1034,7 +1036,10 @@ fn a_profile_holds_web_and_relayed_channel_threads() {
// Bob's stream carried none of alice's events.
std::thread::sleep(Duration::from_secs(1));
let leaked: Vec<String> = bob_events.try_iter().collect();
- assert!(leaked.is_empty(), "bob must see none of alice's events: {leaked:?}");
+ assert!(
+ leaked.is_empty(),
+ "bob must see none of alice's events: {leaked:?}"
+ );
// No relayed turn lands in the operator workspace.
let operator_index = d