Skip to content

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

test(agent): add host env to turn assembly fixtures

Steven Enamakel94822f092c7b
diff --git a/crates/openhuman-core/src/agent/orchestration/ops_tests.rs b/crates/openhuman-core/src/agent/orchestration/ops_tests.rs
index 8090b92a09..94431c1024 100644
--- a/crates/openhuman-core/src/agent/orchestration/ops_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/ops_tests.rs
@@ -47,6 +47,7 @@ fn parent_context(model: Arc<dyn ChatModel<()>>) -> ParentExecutionContext {
session_parent_prefix: None,
on_progress: None,
run_queue: None,
+ host_env: Default::default(),
}
}
diff --git a/crates/openhuman-core/src/agent/session_store/mod_tests.rs b/crates/openhuman-core/src/agent/session_store/mod_tests.rs
index 2b41c5903e..91cccbc8c0 100644
--- a/crates/openhuman-core/src/agent/session_store/mod_tests.rs
+++ b/crates/openhuman-core/src/agent/session_store/mod_tests.rs
@@ -113,10 +113,8 @@ fn derived_overlay(
overlay = overlay.session_agent(agent);
}
if let Some(provider) = provider {
- let overrides = crate::agent::host_overrides::HostOverrides {
- session_store: Some(provider),
- ..Default::default()
- };
+ let mut overrides = crate::agent::host_overrides::HostOverrides::default();
+ overrides.session_store = Some(provider);
overlay = overlay.host_overrides(Arc::new(overrides));
}
CoreContext::for_test(DomainSet::full(), None).derive_with(overlay)
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly_tests.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly_tests.rs
index a2f156cfdb..93dc363596 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly_tests.rs
@@ -86,6 +86,8 @@ fn assembled_with(
&[],
TurnContextMiddleware::default(),
Vec::new(),
+ Vec::new(),
+ None,
None,
None,
false,
@@ -204,6 +206,8 @@ async fn run_slow_first_byte_turn(
&[],
TurnContextMiddleware::default(),
Vec::new(),
+ Vec::new(),
+ None,
None,
None,
false,
diff --git a/crates/openhuman-core/src/agent/turn_env.rs b/crates/openhuman-core/src/agent/turn_env.rs
index 3c35524223..37681d78fc 100644
--- a/crates/openhuman-core/src/agent/turn_env.rs
+++ b/crates/openhuman-core/src/agent/turn_env.rs
@@ -57,3 +57,7 @@ impl std::fmt::Debug for HostTurnEnv {
.finish()
}
}
+
+#[cfg(test)]
+#[path = "turn_env_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/agent/turn_env_tests.rs b/crates/openhuman-core/src/agent/turn_env_tests.rs
new file mode 100644
index 0000000000..7b31dcc389
--- /dev/null
+++ b/crates/openhuman-core/src/agent/turn_env_tests.rs
@@ -0,0 +1,91 @@
+use super::*;
+use crate::agent::stop_hooks::BudgetStopHook;
+use crate::agent::tinyagents::host::OpenHumanRunContext;
+use std::sync::Arc;
+use std::time::Duration;
+
+fn full_env() -> (HostTurnEnv, CancellationToken) {
+ let token = CancellationToken::new();
+ let mut hooks = HookScope::default();
+ hooks.push_stop(Arc::new(BudgetStopHook::new(2.0)));
+ let env = HostTurnEnv {
+ spawn_depth_limit: Some(1),
+ cancellation: Some(token.clone()),
+ turn_deadline: Some(TurnDeadline::starting_now(Duration::from_secs(900))),
+ tool_call_limit: Some(5),
+ hooks,
+ ..Default::default()
+ };
+ (env, token)
+}
+
+/// A bare run context carries nothing from the surrounding task: the env is
+/// the only way a host value reaches a turn.
+#[test]
+fn a_run_context_without_an_env_carries_no_host_policy() {
+ let context = OpenHumanRunContext::new();
+ assert!(context.model_budget.is_none());
+ assert!(context.max_spawn_depth.is_none());
+ assert!(context.turn_deadline.is_none());
+ assert!(context.tool_call_limit.is_none());
+ assert!(context.stop_hooks.is_empty());
+ assert!(context.tool_hooks.is_empty());
+ assert!(!context.cancellation.is_cancelled());
+}
+
+#[test]
+fn the_env_reaches_the_run_context() {
+ let (env, _) = full_env();
+ let context = OpenHumanRunContext::new().with_host_env(&env);
+ assert_eq!(context.max_spawn_depth, Some(1));
+ assert_eq!(context.tool_call_limit, Some(5));
+ assert!(context.turn_deadline.is_some());
+ assert_eq!(context.stop_hooks.len(), 1);
+}
+
+/// A sub-agent fork inherits the host env, and the caller's cancellation
+/// cascades into it.
+#[test]
+fn sub_agent_forks_inherit_the_env_and_the_callers_cancellation() {
+ let (env, token) = full_env();
+ let context = OpenHumanRunContext::new().with_host_env(&env);
+ let child = context.child();
+ assert_eq!(child.max_spawn_depth, Some(1));
+ assert_eq!(child.tool_call_limit, Some(5));
+ assert_eq!(child.stop_hooks.len(), 1);
+ assert!(child.turn_deadline.is_some());
+ assert!(!child.cancellation.is_cancelled());
+ token.cancel();
+ assert!(context.cancellation.is_cancelled());
+ assert!(child.cancellation.is_cancelled());
+}
+
+/// The env is a plain value: it survives await points and a `tokio::spawn`,
+/// which an ambient task scope would silently lose.
+#[tokio::test]
+async fn the_env_survives_await_points_and_spawned_tasks() {
+ let (env, token) = full_env();
+ let context = OpenHumanRunContext::new().with_host_env(&env);
+ tokio::task::yield_now().await;
+ let seen = tokio::spawn(async move {
+ tokio::task::yield_now().await;
+ (
+ context.max_spawn_depth,
+ context.tool_call_limit,
+ context.cancellation.is_cancelled(),
+ )
+ });
+ token.cancel();
+ assert_eq!(seen.await.unwrap(), (Some(1), Some(5), true));
+}
+
+/// A detached background child keeps the policy but is not cancelled by the
+/// interactive turn's Stop.
+#[test]
+fn detached_children_keep_policy_but_not_the_turns_cancellation() {
+ let (env, token) = full_env();
+ let detached = OpenHumanRunContext::new().with_host_env(&env).detached_child();
+ assert_eq!(detached.tool_call_limit, Some(5));
+ token.cancel();
+ assert!(!detached.cancellation.is_cancelled());
+}
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops_tests.rs b/crates/openhuman-core/src/inference/host_runtime/ops_tests.rs
index cd13a47862..d2d17c5331 100644
--- a/crates/openhuman-core/src/inference/host_runtime/ops_tests.rs
+++ b/crates/openhuman-core/src/inference/host_runtime/ops_tests.rs
@@ -322,6 +322,7 @@ async fn agent_chat_for_rejects_an_unknown_agent_id() {
None,
None,
None,
+ crate::inference::host_runtime::ops::AgentChatEnv::default(),
)
.await
.expect_err("an unknown agent id must be refused");