Skip to content

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

test(cron): record callback addresses for manual runs in tests

Steven Enamakelf6700abc7fcd
diff --git a/crates/openhuman-core/src/cron/bus_host.rs b/crates/openhuman-core/src/cron/bus_host.rs
index 96288bb0ad..d488c4de89 100644
--- a/crates/openhuman-core/src/cron/bus_host.rs
+++ b/crates/openhuman-core/src/cron/bus_host.rs
@@ -261,6 +261,27 @@ pub(crate) struct HostRegistration {
static MANUAL_HOSTS: std::sync::LazyLock<std::sync::Mutex<HashMap<String, HostRegistration>>> =
std::sync::LazyLock::new(Default::default);
+#[cfg(test)]
+static TEST_CALLBACK_ADDRESSES: std::sync::LazyLock<
+ std::sync::Mutex<HashMap<String, CallbackAddress>>,
+> = std::sync::LazyLock::new(Default::default);
+
+#[cfg(test)]
+pub(crate) fn record_callback_address_for_test(run_id: &str, address: CallbackAddress) {
+ TEST_CALLBACK_ADDRESSES
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .insert(run_id.to_string(), address);
+}
+
+#[cfg(test)]
+pub(crate) fn take_callback_address_for_test(run_id: &str) -> Option<CallbackAddress> {
+ TEST_CALLBACK_ADDRESSES
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .remove(run_id)
+}
+
/// Keep a detached run's callback served until its terminal projection.
pub(crate) fn retain_manual_host(run_id: &str, host: HostRegistration) {
MANUAL_HOSTS
diff --git a/crates/openhuman-core/src/cron/scheduler/dispatcher.rs b/crates/openhuman-core/src/cron/scheduler/dispatcher.rs
index afd91d288a..c1941c4063 100644
--- a/crates/openhuman-core/src/cron/scheduler/dispatcher.rs
+++ b/crates/openhuman-core/src/cron/scheduler/dispatcher.rs
@@ -51,6 +51,8 @@ pub(crate) async fn run_job_now(
));
let binding = Binding::new(ctx, config, security);
let host = bus_host::register(binding.clone()).await.map_err(|e| anyhow!(e))?;
+ #[cfg(test)]
+ bus_host::record_callback_address_for_test(&run_id, host.address());
let scope = binding
.within(async { DocScope::current(config) })
.await?;