Skip to content

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

test: simplify test assertions and extract type aliases

Steven Enamakelfd36f735bd45
diff --git a/crates/openhuman-core/src/channels/callback_slot_tests.rs b/crates/openhuman-core/src/channels/callback_slot_tests.rs
index 67570c5d95..f7b3822d8e 100644
--- a/crates/openhuman-core/src/channels/callback_slot_tests.rs
+++ b/crates/openhuman-core/src/channels/callback_slot_tests.rs
@@ -97,14 +97,12 @@ async fn reactions_and_threads_without_a_callback_answer_the_unavailable_sentine
let reaction = backend
.send_reaction(&channels, "telegram", serde_json::json!({"emoji": "+1"}))
.await
- .err()
- .expect("no callback");
+ .expect_err("no callback");
assert!(reaction.to_string().starts_with(sentinel), "{reaction}");
let listed = backend
.list_threads(&channels, "telegram", None)
.await
- .err()
- .expect("no callback");
+ .expect_err("no callback");
assert!(listed.to_string().starts_with(sentinel), "{listed}");
}
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs
index bf6d113625..c81d8aee21 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs
@@ -108,9 +108,15 @@ async fn typing_task_runs_under_the_handed_context_not_the_active_one() {
let cancellation = tokio_util::sync::CancellationToken::new();
// The caller's own scope is Ravi's; the typing task was handed Asha's.
let waiter = CoreContext::scope(ravi, async {
- spawn_typing_task(&asha, channel, "recipient".into(), cancellation.clone())
+ Some(spawn_typing_task(
+ &asha,
+ channel,
+ "recipient".into(),
+ cancellation.clone(),
+ ))
})
- .await;
+ .await
+ .expect("typing task was started");
let seen = tokio::time::timeout(std::time::Duration::from_secs(2), receiver)
.await
.unwrap()
diff --git a/crates/openhuman-core/src/inference/registry_tests.rs b/crates/openhuman-core/src/inference/registry_tests.rs
index 8c4c6cd81d..0b43c58347 100644
--- a/crates/openhuman-core/src/inference/registry_tests.rs
+++ b/crates/openhuman-core/src/inference/registry_tests.rs
@@ -8,6 +8,8 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
use tinyinference_llm::model::{ModelRequest, ModelResponse};
+type SeenModelRequests = Arc<Mutex<Vec<(String, Option<String>, Option<String>)>>>;
+
struct FakeModel;
#[async_trait]
@@ -21,7 +23,7 @@ impl ChatModel<()> for FakeModel {
}
}
-fn fake_entry(seen: Arc<Mutex<Vec<(String, Option<String>, Option<String>)>>>) -> ChatModelEntry {
+fn fake_entry(seen: SeenModelRequests) -> ChatModelEntry {
ChatModelEntry {
build: Arc::new(move |request| {
seen.lock().unwrap().push((
diff --git a/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
index e7b33bbaa9..714b39eedf 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
@@ -176,10 +176,11 @@ fn compress_declares_explicit_as_an_enum_of_the_accepted_kinds() {
#[tokio::test]
async fn every_tokenjuice_method_answers_component_disabled_when_juice_is_off() {
+ type ControllerHandler = fn(DispatchCtx, Map<String, Value>) -> ControllerFuture;
let mut set = crate::core::runtime::ComponentSet::all();
set.juice = false;
let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(set);
- let handlers: [fn(DispatchCtx, Map<String, Value>) -> ControllerFuture; 8] = [
+ let handlers: [ControllerHandler; 8] = [
handle_detect,
handle_compress,
handle_cache_stats,
diff --git a/crates/openhuman-core/src/sandbox/native_jail_tests.rs b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
index 0a11ed1e8a..43ba95590d 100644
--- a/crates/openhuman-core/src/sandbox/native_jail_tests.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
@@ -264,7 +264,7 @@ fn openhumans_own_credential_files_are_denied_when_present() {
let denied = credential_denials(
crate::security::credentials::credential_files(&config),
root.path(),
- &[scratch.clone()],
+ std::slice::from_ref(&scratch),
)
.unwrap();
diff --git a/crates/openhuman-core/src/sandbox/schemas_tests.rs b/crates/openhuman-core/src/sandbox/schemas_tests.rs
index 4e710396cf..32daaf345d 100644
--- a/crates/openhuman-core/src/sandbox/schemas_tests.rs
+++ b/crates/openhuman-core/src/sandbox/schemas_tests.rs
@@ -223,10 +223,11 @@ async fn handle_validate_policy_errors_instead_of_passing_when_tinybox_is_unavai
#[tokio::test]
async fn every_sandbox_method_answers_component_disabled_when_sandbox_is_off() {
+ type ControllerHandler = fn(DispatchCtx, Map<String, Value>) -> ControllerFuture;
let mut set = crate::core::runtime::ComponentSet::all();
set.sandbox = false;
let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(set);
- let handlers: [fn(DispatchCtx, Map<String, Value>) -> ControllerFuture; 4] = [
+ let handlers: [ControllerHandler; 4] = [
handle_status,
handle_resolve_policy,
handle_cleanup_orphans,