Skip to content

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

test(cron): update scheduler tests for scoped web events

Steven Enamakel2b4f8b5b72ca
diff --git a/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs b/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs
index 714a36b771..052be539f7 100644
--- a/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs
@@ -13,15 +13,17 @@ async fn deliver_if_configured_skips_empty_mode() {
let config = test_config(&tmp).await;
let mut job = test_job("echo ok");
job.delivery.mode = "".into();
- assert!(deliver_if_configured(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &job,
- "output",
- true
- )
- .await
- .is_ok());
+ assert!(
+ deliver_if_configured(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &job,
+ "output",
+ true
+ )
+ .await
+ .is_ok()
+ );
}
#[tokio::test]
@@ -79,15 +81,17 @@ async fn deliver_if_configured_proactive_mode_succeeds() {
to: None,
best_effort: true,
};
- assert!(deliver_if_configured(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &job,
- "hello",
- true
- )
- .await
- .is_ok());
+ assert!(
+ deliver_if_configured(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &job,
+ "hello",
+ true
+ )
+ .await
+ .is_ok()
+ );
}
// ──────────────────────────────────────────────────────────────────────
@@ -648,15 +652,17 @@ async fn deliver_if_configured_failure_skips_chat_but_alerts() {
let config = test_config(&tmp).await;
let job = proactive_job();
// Failed run (non-empty canned error): no chat injection, but still alerts.
- assert!(deliver_if_configured(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &job,
- "Something went wrong.",
- false
- )
- .await
- .is_ok());
+ assert!(
+ deliver_if_configured(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &job,
+ "Something went wrong.",
+ false
+ )
+ .await
+ .is_ok()
+ );
assert_eq!(cron_alerts(&config).await, 1);
}
@@ -666,15 +672,17 @@ async fn deliver_if_configured_empty_failure_alerts_with_fallback_body() {
let config = test_config(&tmp).await;
let job = proactive_job();
// Empty failed run: still surfaces in /notifications with a fallback body.
- assert!(deliver_if_configured(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &job,
- "",
- false
- )
- .await
- .is_ok());
+ assert!(
+ deliver_if_configured(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &job,
+ "",
+ false
+ )
+ .await
+ .is_ok()
+ );
let items =
crate::desktop::notifications::store::list(&config, 10, 0, Some("cron"), None).unwrap();
assert_eq!(items.len(), 1);
diff --git a/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs b/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
index 604e53b6a9..076706508f 100644
--- a/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
@@ -3,13 +3,13 @@
//! are honoured and a system job's handler result is what gets recorded.
use super::*;
-use crate::cron::system_job_handlers::{register, SystemJobContext};
+use crate::cron::system_job_handlers::{SystemJobContext, register};
use crate::cron::system_jobs::ensure_system_job;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
use tempfile::TempDir;
-use tinyflows_bus::schedule::types::Schedule;
use tinyflows_bus::schedule::JobPolicy;
+use tinyflows_bus::schedule::types::Schedule;
/// Stores `policy` on the job.
fn set_policy(config: &Config, job_id: &str, policy: JobPolicy) -> anyhow::Result<()> {
@@ -167,10 +167,12 @@ async fn a_system_job_handler_error_is_recorded_as_the_run_result() {
dispatcher.drain().await;
let stored = cron::get_job(&config, &job.id).unwrap();
assert_eq!(stored.last_status.as_deref(), Some("error"));
- assert!(stored
- .last_output
- .unwrap_or_default()
- .contains("handler failed"));
+ assert!(
+ stored
+ .last_output
+ .unwrap_or_default()
+ .contains("handler failed")
+ );
}
#[tokio::test]
@@ -285,10 +287,12 @@ async fn a_flow_schedule_job_fires_through_the_trigger_sink() {
let stored = cron::get_job(&config, &job.id).unwrap();
assert_eq!(stored.last_status.as_deref(), Some("ok"));
- assert!(stored
- .last_output
- .unwrap_or_default()
- .contains("flow schedule tick emitted for flow flow-missing-for-sink"));
+ assert!(
+ stored
+ .last_output
+ .unwrap_or_default()
+ .contains("flow schedule tick emitted for flow flow-missing-for-sink")
+ );
assert!(stored.next_run > Utc::now(), "the recurrence moved on");
}
diff --git a/crates/openhuman-core/src/cron/scheduler_frequency_tests.rs b/crates/openhuman-core/src/cron/scheduler_frequency_tests.rs
index 2cdec04d24..a78f9a998b 100644
--- a/crates/openhuman-core/src/cron/scheduler_frequency_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_frequency_tests.rs
@@ -1,24 +1,26 @@
use super::*;
+use tinyflows_bus::schedule::MIN_AGENT_JOB_INTERVAL;
+use tinyflows_bus::schedule::TooFrequent;
use tinyflows_bus::schedule::types::JobType;
use tinyflows_bus::schedule::types::Schedule;
-use tinyflows_bus::schedule::TooFrequent;
-use tinyflows_bus::schedule::MIN_AGENT_JOB_INTERVAL;
#[tokio::test]
async fn deliver_if_configured_empty_success_skips_chat_and_alert() {
let tmp = TempDir::new().unwrap();
let config = test_config(&tmp).await;
let job = proactive_job();
// Successful but empty: nothing delivered anywhere.
- assert!(deliver_if_configured(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &job,
- "",
- true
- )
- .await
- .is_ok());
+ assert!(
+ deliver_if_configured(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &job,
+ "",
+ true
+ )
+ .await
+ .is_ok()
+ );
assert_eq!(cron_alerts(&config).await, 0);
}
@@ -37,16 +39,24 @@ fn publish_cron_user_error_broadcasts_metadata_only_for_each_kind() {
publish_cron_user_error(kind);
let ev = next_user_error(&mut rx, kind);
// Broadcast to the "system" room every connected socket auto-joins.
- assert_eq!(ev.client_id, "system");
- // Stable kind token mirrors the frontend `UserErrorKind` discriminator.
- assert_eq!(ev.error_type.as_deref(), Some(kind));
- assert_eq!(ev.error_source.as_deref(), Some("cron"));
- // Metadata-only: a `user_error` NEVER carries the raw provider body
- // (CLAUDE.md) and is thread-less (no chat context).
- assert!(ev.message.is_none(), "user_error must not carry a raw body");
- assert!(ev.full_response.is_none());
- assert!(ev.thread_id.is_empty(), "cron user_error is thread-less");
- assert!(ev.request_id.is_empty());
+ assert_eq!(ev.context().client_id, "system");
+ assert!(
+ ev.context().thread_id.is_empty(),
+ "cron user_error is thread-less"
+ );
+ assert!(ev.context().request_id.is_empty());
+ match ev.wire_event() {
+ crate::web_chat::WebChannelEvent::UserError {
+ error_type,
+ error_source,
+ ..
+ } => {
+ // Stable kind token mirrors the frontend `UserErrorKind` discriminator.
+ assert_eq!(error_type.as_deref(), Some(kind));
+ assert_eq!(error_source.as_deref(), Some("cron"));
+ }
+ other => panic!("expected user_error, got {}", other.event_name()),
+ }
}
}
diff --git a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
index b87778bc15..1cfc88d8c2 100644
--- a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
@@ -253,8 +253,7 @@ fn is_local_provider_unreachable_failure_matches_raw_no_models_loaded_body() {
#[test]
fn is_local_provider_unreachable_failure_checks_output_when_raw_is_generic() {
- let output =
- "Your local inference server (e.g. LM Studio) is running but has no model loaded. \
+ let output = "Your local inference server (e.g. LM Studio) is running but has no model loaded. \
Load a model, then try again.";
assert!(
is_local_provider_unreachable_failure(
@@ -440,11 +439,13 @@ async fn scheduler_flow_runs_active_hours_job_and_reschedules_inside_window() {
let stored = cron::get_job(&config, &job.id).unwrap();
assert_eq!(stored.last_status.as_deref(), Some("ok"));
- assert!(stored
- .last_output
- .as_deref()
- .unwrap_or_default()
- .contains("active-hours-fired"));
+ assert!(
+ stored
+ .last_output
+ .as_deref()
+ .unwrap_or_default()
+ .contains("active-hours-fired")
+ );
assert_eq!(
stored.schedule,
Schedule::Cron {
@@ -551,15 +552,17 @@ async fn deliver_if_configured_skips_non_announce_mode() {
let job = test_job("echo ok");
// Default delivery mode is not "announce", so nothing is published.
- assert!(deliver_if_configured(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &job,
- "x",
- true
- )
- .await
- .is_ok());
+ assert!(
+ deliver_if_configured(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &job,
+ "x",
+ true
+ )
+ .await
+ .is_ok()
+ );
}
#[tokio::test]
@@ -616,15 +619,17 @@ async fn deliver_if_configured_publishes_event_for_announce_mode() {
assert_eq!(received.load(Ordering::SeqCst), 1);
// Also verify the function itself succeeds.
- assert!(deliver_if_configured(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &job,
- "hello",
- true
- )
- .await
- .is_ok());
+ assert!(
+ deliver_if_configured(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &job,
+ "hello",
+ true
+ )
+ .await
+ .is_ok()
+ );
}
#[test]
diff --git a/crates/openhuman-core/src/cron/scheduler_host_agent_tests.rs b/crates/openhuman-core/src/cron/scheduler_host_agent_tests.rs
index f043e64c3d..f332c3b1ba 100644
--- a/crates/openhuman-core/src/cron/scheduler_host_agent_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_host_agent_tests.rs
@@ -109,11 +109,13 @@ fn a_cron_job_for_a_host_agent_builds_with_its_host_tools_and_context() {
belt_builds.load(Ordering::SeqCst) > 0,
"the host belt was built"
);
- assert!(built
- .agent
- .visible_tool_specs_arc()
- .iter()
- .any(|spec| spec.name == "cron_host_marker"));
+ assert!(
+ built
+ .agent
+ .visible_tool_specs_arc()
+ .iter()
+ .any(|spec| spec.name == "cron_host_marker")
+ );
}
#[test]
@@ -134,9 +136,11 @@ fn an_id_the_host_does_not_know_falls_back_to_the_registries() {
host_agents::clear_if(&installed);
let built = built.expect("the orchestrator builds from the registries");
assert!(built.context.is_none());
- assert!(!built
- .agent
- .visible_tool_specs_arc()
- .iter()
- .any(|spec| spec.name == "cron_host_marker"));
+ assert!(
+ !built
+ .agent
+ .visible_tool_specs_arc()
+ .iter()
+ .any(|spec| spec.name == "cron_host_marker")
+ );
}
diff --git a/crates/openhuman-core/src/cron/scheduler_tests.rs b/crates/openhuman-core/src/cron/scheduler_tests.rs
index f06e88bbe3..15438c2c4e 100644
--- a/crates/openhuman-core/src/cron/scheduler_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_tests.rs
@@ -1,4 +1,4 @@
-use super::agent_run::{build_agent_for_cron_job, run_agent_job, EMPTY_AGENT_OUTPUT};
+use super::agent_run::{EMPTY_AGENT_OUTPUT, build_agent_for_cron_job, run_agent_job};
use super::*;
use crate::config::Config;
use crate::security::SecurityPolicy;
@@ -86,14 +86,18 @@ async fn cron_alerts(config: &Config) -> usize {
/// #4169); only a terminal `Empty`/`Closed` — the matching event genuinely was
/// not published — panics.
fn next_user_error(
- rx: &mut tokio::sync::broadcast::Receiver<crate::web_chat::WebChannelEvent>,
+ rx: &mut tokio::sync::broadcast::Receiver<crate::web_chat::ScopedWebEvent>,
kind: &str,
-) -> crate::web_chat::WebChannelEvent {
+) -> crate::web_chat::ScopedWebEvent {
use tokio::sync::broadcast::error::TryRecvError;
loop {
match rx.try_recv() {
- Ok(ev) if ev.event == "user_error" && ev.error_type.as_deref() == Some(kind) => {
- break ev
+ Ok(ev)
+ if matches!(ev.wire_event(), crate::web_chat::WebChannelEvent::UserError {
+ error_type: Some(error_type), ..
+ } if error_type == kind) =>
+ {
+ break ev;
}
Ok(_) => continue,
// Receiver fell behind a concurrent flood — the dropped slots can't
diff --git a/crates/openhuman-rpc/src/server/http/events_tests.rs b/crates/openhuman-rpc/src/server/http/events_tests.rs
index 2ab1661a44..7f3c853e54 100644
--- a/crates/openhuman-rpc/src/server/http/events_tests.rs
+++ b/crates/openhuman-rpc/src/server/http/events_tests.rs
@@ -1,10 +1,10 @@
use axum::body::to_bytes;
use axum::extract::Query;
-use axum::http::{header, HeaderMap, StatusCode};
+use axum::http::{HeaderMap, StatusCode, header};
use super::{
- active_workspace_handle, domain_event_payload, domain_event_stream_unavailable,
- domain_events_handler, events_handler, webhook_events_handler, EventsQuery,
+ EventsQuery, active_workspace_handle, domain_event_payload, domain_event_stream_unavailable,
+ domain_events_handler, events_handler, webhook_events_handler,
};
#[test]
@@ -98,7 +98,7 @@ async fn events_bind_token_is_client_bound_and_single_use() {
#[tokio::test]
async fn events_stream_forwards_only_the_bound_client() {
- use crate::core_host::web_chat::{publish_web_channel_event, WebChannelEvent};
+ use crate::core_host::web_chat::{WebChannelEvent, publish_web_channel_event};
use tokio_stream::StreamExt;
let token = crate::core_host::core::event_bind_tokens::issue("stream-client", None)