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
test(cron): cover agent scope config and policy reuse
Steven Enamakel60f87f7b7560
diff --git a/crates/openhuman-core/src/cron/scheduler.rs b/crates/openhuman-core/src/cron/scheduler.rsindex ad5f27e295..77ae699654 100644--- a/crates/openhuman-core/src/cron/scheduler.rs+++ b/crates/openhuman-core/src/cron/scheduler.rs@@ -113,9 +113,10 @@ pub(crate) async fn tick_agents(last_emitted_health: &mut Option<bool>) {/// and autonomy policy. Its jobs wait for the host to derive it again.async fn tick_agent_scope(last_emitted_health: &mut Option<bool>) {use crate::core::runtime::CoreContext;- let (Some(context), Some(config)) =- (CoreContext::current(), CoreContext::current_embedder_config())- else {+ let (Some(context), Some(config)) = (+ CoreContext::current(),+ CoreContext::current_embedder_config(),+ ) else {tracing::debug!("[cron:scheduler] skipping an agent scope: its context has no configuration of its own");diff --git a/crates/openhuman-core/src/cron/scheduler_tests.rs b/crates/openhuman-core/src/cron/scheduler_tests.rsindex 80184d947d..d062c3c985 100644--- a/crates/openhuman-core/src/cron/scheduler_tests.rs+++ b/crates/openhuman-core/src/cron/scheduler_tests.rs@@ -314,24 +314,59 @@ async fn a_pipeline_reports_its_last_stage_rather_than_pipefail() {);}+fn agent_context_with_config(+ agent: &str,+ config: Config,+) -> Arc<crate::core::runtime::CoreContext> {+ use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};+ CoreContext::for_test(DomainSet::full(), None).derive_with(+ ContextOverlay::new(config, DomainSet::full(), Default::default()).session_agent(agent),+ )+}+#[tokio::test]async fn an_agent_pass_polls_with_its_own_config_and_reports_health() {let tmp = TempDir::new().unwrap();let config = test_config(&tmp).await;+ let context = agent_context_with_config("cron-test-agent", config);let mut health = None;- tick_agent_scope(&config, &mut health).await;+ crate::core::runtime::CoreContext::scope(context, tick_agent_scope(&mut health)).await;assert_eq!(health, Some(true), "a successful poll reports healthy");}+#[tokio::test]+async fn an_agent_pass_without_its_own_config_is_skipped() {+ use crate::core::runtime::{CoreContext, DomainSet};+ // `for_agent` swaps only the identity: no configuration of the agent's own.+ let fallback = CoreContext::for_test(DomainSet::full(), None);+ let mut health = None;+ CoreContext::scope(+ fallback.for_agent("cron-test-recorded"),+ tick_agent_scope(&mut health),+ )+ .await;+ assert_eq!(health, None, "nothing ran, so nothing was reported");+}++#[tokio::test]+async fn an_agent_keeps_its_policy_across_ticks_until_re_derived() {+ let tmp = TempDir::new().unwrap();+ let config = test_config(&tmp).await;+ let first = agent_context_with_config("cron-test-policy", config.clone());+ let a = agent_policy(&first, &config);+ let b = agent_policy(&first, &config);+ assert!(Arc::ptr_eq(&a, &b), "the same context keeps one policy");+ let second = agent_context_with_config("cron-test-policy", config.clone());+ assert!(!Arc::ptr_eq(&a, &agent_policy(&second, &config)));+}+#[tokio::test]async fn tick_agents_without_a_backend_leaves_the_health_tracker_alone() {// The lib test binary installs no storage backend, so no agent is visited.if crate::storage::installed().is_some() {return;}- let tmp = TempDir::new().unwrap();- let config = test_config(&tmp).await;let mut health = Some(false);- tick_agents(&config, &mut health).await;+ tick_agents(&mut health).await;assert_eq!(health, Some(false));}diff --git a/crates/openhuman-core/src/security/devices/owner_tests.rs b/crates/openhuman-core/src/security/devices/owner_tests.rsindex 4a4575c241..5c5df21dc6 100644--- a/crates/openhuman-core/src/security/devices/owner_tests.rs+++ b/crates/openhuman-core/src/security/devices/owner_tests.rs@@ -17,22 +17,26 @@ async fn a_pending_pairing_names_its_agent() {assert_eq!(owner_of("owner-test-pending", Some(&pending)).await+ .unwrap().as_deref(),Some("agent-7"));let local = session(None);- assert_eq!(owner_of("owner-test-pending", Some(&local)).await, None);+ assert_eq!(owner_of("owner-test-pending", Some(&local)).await, Ok(None));}#[tokio::test]async fn a_remembered_owner_is_used_without_a_lookup() {remember("owner-test-cached", Some("agent-9".to_string()));assert_eq!(- owner_of("owner-test-cached", None).await.as_deref(),+ owner_of("owner-test-cached", None)+ .await+ .unwrap()+ .as_deref(),Some("agent-9"));remember("owner-test-local", None);- assert_eq!(owner_of("owner-test-local", None).await, None);+ assert_eq!(owner_of("owner-test-local", None).await, Ok(None));}#[test]@@ -62,7 +66,7 @@ async fn a_device_found_in_the_local_scope_belongs_to_local_and_is_remembered());let owner =crate::core::runtime::CoreContext::scope(context, owner_of("owner-test-found", None)).await;- assert_eq!(owner, None);+ assert_eq!(owner, Ok(None));assert_eq!(cached("owner-test-found"), Some(None));}@@ -76,6 +80,6 @@ async fn a_channel_no_scope_knows_is_local_and_not_remembered() {let owner =crate::core::runtime::CoreContext::scope(context, owner_of("owner-test-missing", None)).await;- assert_eq!(owner, None);+ assert_eq!(owner, Ok(None));assert_eq!(cached("owner-test-missing"), None);}diff --git a/crates/openhuman-core/src/storage/agents_tests.rs b/crates/openhuman-core/src/storage/agents_tests.rsindex 83c18ffdde..85effe5078 100644--- a/crates/openhuman-core/src/storage/agents_tests.rs+++ b/crates/openhuman-core/src/storage/agents_tests.rs@@ -128,3 +128,10 @@ fn without_a_fallback_only_live_contexts_are_visited() {.iter().any(|(id, _)| id == "agents-test-no-fallback"));}++#[test]+fn registering_forgets_agents_whose_contexts_are_all_gone() {+ drop(agent_context("agents-test-gone"));+ let _other = agent_context("agents-test-other-live");+ assert!(!LIVE.lock().unwrap().contains_key("agents-test-gone"));+}