Skip to content

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

test: pass scoped context into dispatch ctx in schema tests

Steven Enamakeld1c46b346737
diff --git a/crates/openhuman-core/src/desktop/control/schemas_tests.rs b/crates/openhuman-core/src/desktop/control/schemas_tests.rs
index 5466dd8347..17c645baad 100644
--- a/crates/openhuman-core/src/desktop/control/schemas_tests.rs
+++ b/crates/openhuman-core/src/desktop/control/schemas_tests.rs
@@ -36,8 +36,8 @@ fn scoped_context(computer: bool) -> (tempfile::TempDir, std::sync::Arc<CoreCont
#[tokio::test]
async fn pending_lists_actions_while_the_computer_component_is_on() {
let (_dir, context) = scoped_context(true);
- CoreContext::scope(context, async {
- let value = (controller("pending").handler)(DispatchCtx::process_default(), Map::new())
+ CoreContext::scope(context.clone(), async {
+ let value = (controller("pending").handler)(DispatchCtx::new(context.clone()), Map::new())
.await
.unwrap();
assert!(value.is_array());
@@ -48,9 +48,9 @@ async fn pending_lists_actions_while_the_computer_component_is_on() {
#[tokio::test]
async fn every_desktop_controller_answers_component_disabled_when_computer_is_off() {
let (_dir, context) = scoped_context(false);
- CoreContext::scope(context, async {
+ CoreContext::scope(context.clone(), async {
for function in ["status", "probe", "pending"] {
- let error = (controller(function).handler)(DispatchCtx::process_default(), Map::new())
+ let error = (controller(function).handler)(DispatchCtx::new(context.clone()), Map::new())
.await
.unwrap_err();
assert!(
@@ -60,14 +60,14 @@ async fn every_desktop_controller_answers_component_disabled_when_computer_is_of
}
let mut params = Map::new();
params.insert("enabled".to_owned(), Value::Bool(true));
- let error = (controller("set_enabled").handler)(DispatchCtx::process_default(), params)
+ let error = (controller("set_enabled").handler)(DispatchCtx::new(context.clone()), params)
.await
.unwrap_err();
assert!(error.contains("COMPONENT_DISABLED:computer"), "{error}");
let mut params = Map::new();
params.insert("confirmation_id".to_owned(), Value::String("id".to_owned()));
params.insert("approve".to_owned(), Value::Bool(true));
- let error = (controller("confirm").handler)(DispatchCtx::process_default(), params)
+ let error = (controller("confirm").handler)(DispatchCtx::new(context.clone()), params)
.await
.unwrap_err();
assert!(error.contains("COMPONENT_DISABLED:computer"), "{error}");
@@ -119,13 +119,13 @@ async fn controllers_use_scoped_config_for_disabled_desktop_and_reject_unknown_c
config.workspace_dir = dir.path().to_path_buf();
let context = CoreContext::for_test_with_config(DomainSet::full(), config);
- CoreContext::scope(context, async {
- let status = (controller("status").handler)(DispatchCtx::process_default(), Map::new())
+ CoreContext::scope(context.clone(), async {
+ let status = (controller("status").handler)(DispatchCtx::new(context.clone()), Map::new())
.await
.unwrap();
assert_eq!(status["enabled"], false);
- let probe = (controller("probe").handler)(DispatchCtx::process_default(), Map::new())
+ let probe = (controller("probe").handler)(DispatchCtx::new(context.clone()), Map::new())
.await
.unwrap();
assert_eq!(probe["ok"], false);
@@ -133,7 +133,7 @@ async fn controllers_use_scoped_config_for_disabled_desktop_and_reject_unknown_c
let mut params = Map::new();
params.insert("enabled".to_owned(), Value::Bool(false));
- let disabled = (controller("set_enabled").handler)(DispatchCtx::process_default(), params)
+ let disabled = (controller("set_enabled").handler)(DispatchCtx::new(context.clone()), params)
.await
.unwrap();
assert_eq!(disabled["enabled"], false);
@@ -144,7 +144,7 @@ async fn controllers_use_scoped_config_for_disabled_desktop_and_reject_unknown_c
Value::String("missing".to_owned()),
);
params.insert("approve".to_owned(), Value::Bool(true));
- let error = (controller("confirm").handler)(DispatchCtx::process_default(), params)
+ let error = (controller("confirm").handler)(DispatchCtx::new(context.clone()), params)
.await
.unwrap_err();
assert!(error.contains("missing or expired"));
diff --git a/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
index 9a920a0008..e7b33bbaa9 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
@@ -205,9 +205,9 @@ async fn tokenjuice_methods_are_not_gated_when_juice_is_on() {
let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(
crate::core::runtime::ComponentSet::all(),
);
- crate::core::runtime::context::CoreContext::scope(ctx, async {
+ crate::core::runtime::context::CoreContext::scope(ctx.clone(), async {
// Gate passes; the handler then fails on its own missing param.
- let err = handle_detect(DispatchCtx::process_default(), Map::new())
+ let err = handle_detect(DispatchCtx::new(ctx.clone()), Map::new())
.await
.unwrap_err();
assert!(!err.contains("COMPONENT_DISABLED"), "{err}");
diff --git a/crates/openhuman-core/src/memory/schemas_tests.rs b/crates/openhuman-core/src/memory/schemas_tests.rs
index 16570d2dc9..20b15511be 100644
--- a/crates/openhuman-core/src/memory/schemas_tests.rs
+++ b/crates/openhuman-core/src/memory/schemas_tests.rs
@@ -57,8 +57,8 @@ fn object(value: Value) -> Map<String, Value> {
async fn call(config: &Config, function: &str, params: Value) -> Result<Value, String> {
let handler = handler_for(function);
let ctx = CoreContext::for_test_with_config(DomainSet::full(), config.clone());
- CoreContext::scope(ctx, async move {
- handler(DispatchCtx::process_default(), object(params)).await
+ CoreContext::scope(ctx.clone(), async move {
+ handler(DispatchCtx::new(ctx.clone()), object(params)).await
})
.await
}
diff --git a/crates/openhuman-core/src/modules/schemas_tests.rs b/crates/openhuman-core/src/modules/schemas_tests.rs
index 2d0f650ce6..58fe13c640 100644
--- a/crates/openhuman-core/src/modules/schemas_tests.rs
+++ b/crates/openhuman-core/src/modules/schemas_tests.rs
@@ -60,8 +60,8 @@ async fn computer_status_handler_returns_serialized_status() {
let ctx =
CoreContext::for_test_with_config(DomainSet::full(), crate::config::Config::default());
- let status = CoreContext::scope(ctx, async {
- super::handle_computer_status(DispatchCtx::process_default(), Map::new()).await
+ let status = CoreContext::scope(ctx.clone(), async {
+ super::handle_computer_status(DispatchCtx::new(ctx.clone()), Map::new()).await
})
.await
.expect("computer status should serialize");
@@ -81,16 +81,16 @@ async fn forgetting_sites_reports_how_many_went() {
}
let ctx = CoreContext::for_test_with_config(DomainSet::full(), config);
- let (one, every) = CoreContext::scope(ctx, async {
+ let (one, every) = CoreContext::scope(ctx.clone(), async {
let mut one = Map::new();
one.insert(
"site".to_string(),
Value::String("https://www.shop.test/cart".to_string()),
);
- let one = super::handle_browser_forget_sites(DispatchCtx::process_default(), one).await;
+ let one = super::handle_browser_forget_sites(DispatchCtx::new(ctx.clone()), one).await;
(
one,
- super::handle_browser_forget_sites(DispatchCtx::process_default(), Map::new()).await,
+ super::handle_browser_forget_sites(DispatchCtx::new(ctx.clone()), Map::new()).await,
)
})
.await;
diff --git a/crates/openhuman-core/src/sandbox/schemas_tests.rs b/crates/openhuman-core/src/sandbox/schemas_tests.rs
index eb257662ed..4e710396cf 100644
--- a/crates/openhuman-core/src/sandbox/schemas_tests.rs
+++ b/crates/openhuman-core/src/sandbox/schemas_tests.rs
@@ -30,8 +30,8 @@ fn registered_controllers_match_schemas() {
#[tokio::test]
async fn handle_status_returns_json() {
let ctx = scoped_ctx(crate::config::Config::default());
- let result = CoreContext::scope(ctx, async {
- handle_status(DispatchCtx::process_default(), Map::new()).await
+ let result = CoreContext::scope(ctx.clone(), async {
+ handle_status(DispatchCtx::new(ctx.clone()), Map::new()).await
})
.await;
assert!(result.is_ok());
@@ -42,8 +42,8 @@ async fn handle_resolve_policy_none() {
let mut params = Map::new();
params.insert("sandbox_mode".into(), Value::String("none".into()));
let ctx = scoped_ctx(crate::config::Config::default());
- let result = CoreContext::scope(ctx, async {
- handle_resolve_policy(DispatchCtx::process_default(), params).await
+ let result = CoreContext::scope(ctx.clone(), async {
+ handle_resolve_policy(DispatchCtx::new(ctx.clone()), params).await
})
.await;
assert!(result.is_ok());
@@ -55,8 +55,8 @@ async fn handle_resolve_policy_sandboxed_remote() {
params.insert("sandbox_mode".into(), Value::String("sandboxed".into()));
params.insert("is_remote".into(), Value::Bool(true));
let ctx = scoped_ctx(crate::config::Config::default());
- let result = CoreContext::scope(ctx, async {
- handle_resolve_policy(DispatchCtx::process_default(), params).await
+ let result = CoreContext::scope(ctx.clone(), async {
+ handle_resolve_policy(DispatchCtx::new(ctx.clone()), params).await
})
.await;
assert!(result.is_ok());
@@ -90,8 +90,8 @@ async fn handle_resolve_policy_honors_loaded_docker_runtime() {
params.insert("sandbox_mode".into(), Value::String("sandboxed".into()));
params.insert("is_remote".into(), Value::Bool(false));
- let val = CoreContext::scope(ctx, async {
- handle_resolve_policy(DispatchCtx::process_default(), params).await
+ let val = CoreContext::scope(ctx.clone(), async {
+ handle_resolve_policy(DispatchCtx::new(ctx.clone()), params).await
})
.await
.expect("resolve_policy should succeed under the scoped config");
@@ -130,8 +130,8 @@ async fn handle_status_honors_loaded_docker_runtime() {
params.insert("backend".into(), Value::String("local".into()));
params.insert("is_remote".into(), Value::Bool(false));
- let val = CoreContext::scope(ctx, async {
- handle_status(DispatchCtx::process_default(), params).await
+ let val = CoreContext::scope(ctx.clone(), async {
+ handle_status(DispatchCtx::new(ctx.clone()), params).await
})
.await
.expect("status should succeed under the scoped config");
@@ -163,8 +163,8 @@ async fn handle_resolve_policy_uses_loaded_action_dir() {
let mut params = Map::new();
params.insert("sandbox_mode".into(), Value::String("none".into()));
- let val = CoreContext::scope(ctx, async {
- handle_resolve_policy(DispatchCtx::process_default(), params).await
+ let val = CoreContext::scope(ctx.clone(), async {
+ handle_resolve_policy(DispatchCtx::new(ctx.clone()), params).await
})
.await
.expect("resolve_policy should succeed under the scoped config");
@@ -211,8 +211,8 @@ async fn handle_validate_policy_errors_instead_of_passing_when_tinybox_is_unavai
let mut config = crate::config::Config::default();
config.modules.enabled = false;
let ctx = scoped_ctx(config);
- let result = CoreContext::scope(ctx, async {
- handle_validate_policy(DispatchCtx::process_default(), docker_policy_params("/")).await
+ let result = CoreContext::scope(ctx.clone(), async {
+ handle_validate_policy(DispatchCtx::new(ctx.clone()), docker_policy_params("/")).await
})
.await;
let err = result.unwrap_err();
@@ -248,8 +248,8 @@ async fn sandbox_methods_are_not_gated_when_sandbox_is_on() {
let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(
crate::core::runtime::ComponentSet::all(),
);
- crate::core::runtime::context::CoreContext::scope(ctx, async {
- let err = handle_validate_policy(DispatchCtx::process_default(), Map::new())
+ crate::core::runtime::context::CoreContext::scope(ctx.clone(), async {
+ let err = handle_validate_policy(DispatchCtx::new(ctx.clone()), Map::new())
.await
.unwrap_err();
assert!(!err.contains("COMPONENT_DISABLED"), "{err}");