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(cron): add bus host tests and handler coverage
Steven Enamakelb208081ca3f5
diff --git a/crates/openhuman-core/src/cron/bus_host_tests.rs b/crates/openhuman-core/src/cron/bus_host_tests.rsindex e6c95abebb..0e45527cf1 100644--- a/crates/openhuman-core/src/cron/bus_host_tests.rs+++ b/crates/openhuman-core/src/cron/bus_host_tests.rs@@ -4,6 +4,7 @@use super::*;use crate::cron::handlers::{kind_handler, register_kind, JobKindHandler, JobOutcome, JobRunContext,+ KIND_REGISTRY_TEST_LOCK,};use async_trait::async_trait;use std::sync::atomic::{AtomicUsize, Ordering};@@ -88,6 +89,7 @@ impl JobKindHandler for Marker {#[tokio::test]async fn execute_runs_the_registered_handler_and_reports_a_retryable_failure() {+ let _kinds = KIND_REGISTRY_TEST_LOCK.lock().await;let tmp = TempDir::new().unwrap();let config = config(&tmp);let (_host, proxy) = host(&config, false).await;@@ -114,6 +116,7 @@ async fn execute_runs_the_registered_handler_and_reports_a_retryable_failure() {#[tokio::test]async fn a_permanent_handler_outcome_stops_the_retry_loop() {+ let _kinds = KIND_REGISTRY_TEST_LOCK.lock().await;let tmp = TempDir::new().unwrap();let config = config(&tmp);let (_host, proxy) = host(&config, false).await;@@ -137,6 +140,7 @@ async fn a_permanent_handler_outcome_stops_the_retry_loop() {#[tokio::test]async fn an_agent_only_scheduler_refuses_shell_jobs_before_running_anything() {+ let _kinds = KIND_REGISTRY_TEST_LOCK.lock().await;let tmp = TempDir::new().unwrap();let config = config(&tmp);let (_host, proxy) = host(&config, true).await;diff --git a/crates/openhuman-core/src/cron/handlers.rs b/crates/openhuman-core/src/cron/handlers.rsindex ec159b9548..89021b9ec4 100644--- a/crates/openhuman-core/src/cron/handlers.rs+++ b/crates/openhuman-core/src/cron/handlers.rs@@ -145,6 +145,18 @@ fn write() -> std::sync::RwLockWriteGuard<'static, Registry> {REGISTRY.write().unwrap_or_else(PoisonError::into_inner)}+/// Serialises the tests that swap a kind handler in the process-wide registry.+///+/// A test registers a decorator that hands every other job to the handler it+/// replaced, reading that handler with [`kind_handler`] before it calls+/// [`register_kind`]. Two such tests running in parallel can both read the same+/// handler, so the second one's decorator bypasses the first's and a job lands+/// on the wrong handler. Hold this for the whole read, register and use, and+/// declare it before the [`KindRegistration`] so the registration drops first.+#[cfg(test)]+pub(crate) static KIND_REGISTRY_TEST_LOCK: tokio::sync::Mutex<()> =+ tokio::sync::Mutex::const_new(());+/// Keeps a kind handler registered while held; dropping it restores the handler/// it replaced, unless a later registration has replaced this one.#[must_use = "the handler is unregistered when the registration drops"]diff --git a/crates/openhuman-core/src/cron/handlers_tests.rs b/crates/openhuman-core/src/cron/handlers_tests.rsindex cb3a50d97b..f4aa428a75 100644--- a/crates/openhuman-core/src/cron/handlers_tests.rs+++ b/crates/openhuman-core/src/cron/handlers_tests.rs@@ -44,6 +44,7 @@ fn every_job_kind_has_a_default_handler() {#[test]fn a_later_registration_wins_and_dropping_restores_in_order() {+ let _kinds = KIND_REGISTRY_TEST_LOCK.blocking_lock();let default = kind_handler(&JobType::Flow).unwrap();let first: Arc<dyn JobKindHandler> = tagged("first");let second: Arc<dyn JobKindHandler> = tagged("second");@@ -66,6 +67,7 @@ fn a_later_registration_wins_and_dropping_restores_in_order() {#[tokio::test]async fn the_registered_handler_decides_the_outcome() {+ let _kinds = KIND_REGISTRY_TEST_LOCK.lock().await;let handler = tagged("custom");let calls = Arc::clone(&handler.calls);let _guard = register_kind(JobType::Flow, handler);