Skip to content

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

test(core): add coverage for config migration, ops components, and sandbox

Steven Enamakelfee55c0b84a4
diff --git a/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs b/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs
index 1457fffcc9..1c372568a1 100644
--- a/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs
@@ -162,3 +162,23 @@ fn explicit_components_voice_wins_over_legacy_voice_switches() {
);
assert!(c.components.voice);
}
+
+#[test]
+fn sandbox_enabled_false_maps_to_components_sandbox() {
+ for raw in ["[sandbox]\nenabled = false\n", "[security.sandbox]\nenabled = false\n"] {
+ let c = migrated(raw, None);
+ assert!(!c.components.sandbox, "{raw}");
+ assert_eq!(c.sandbox.enabled.or(c.security.sandbox.enabled), Some(false), "old key kept");
+ }
+}
+
+#[test]
+fn sandbox_auto_or_on_or_explicit_component_keeps_the_component_on() {
+ for raw in [
+ "[sandbox]\nenabled = true\n",
+ "[sandbox]\nbackend = \"auto\"\n",
+ "[sandbox]\nenabled = false\n[components]\nsandbox = true\n",
+ ] {
+ assert!(migrated(raw, None).components.sandbox, "{raw}");
+ }
+}
diff --git a/crates/openhuman-core/src/modules/ops_components_tests.rs b/crates/openhuman-core/src/modules/ops_components_tests.rs
index e483896c4e..4729a5b01e 100644
--- a/crates/openhuman-core/src/modules/ops_components_tests.rs
+++ b/crates/openhuman-core/src/modules/ops_components_tests.rs
@@ -100,3 +100,16 @@ async fn voice_off_refuses_tinyvoice_before_download_or_load() {
assert_eq!(status.state, ModuleState::Disabled);
assert!(status.source.is_none());
}
+
+#[tokio::test]
+async fn a_disabled_sandbox_never_loads_the_tinybox_module() {
+ let config = config_without("sandbox");
+ let err = ensure_loaded_within(&config, "tinybox", None)
+ .await
+ .unwrap_err();
+ assert_eq!(err, LoadError::Disabled("sandbox"));
+ assert_eq!(err.into_message(), "COMPONENT_DISABLED:sandbox");
+ let statuses = list(&config);
+ let status = statuses.iter().find(|s| s.id == "tinybox").unwrap();
+ assert_eq!(status.state, ModuleState::Disabled);
+}
diff --git a/crates/openhuman-core/src/sandbox/ops_tests.rs b/crates/openhuman-core/src/sandbox/ops_tests.rs
index 764e6c5166..c5a02135f4 100644
--- a/crates/openhuman-core/src/sandbox/ops_tests.rs
+++ b/crates/openhuman-core/src/sandbox/ops_tests.rs
@@ -294,3 +294,43 @@ fn sandbox_off_value_keeps_sandbox_on_otherwise() {
assert!(!sandbox_off_value(v), "{v:?} must leave the sandbox on");
}
}
+
+// ── [components] sandbox = false ──────────────────────────────────────
+
+#[tokio::test]
+async fn sandbox_off_component_forces_the_unsandboxed_fallback_and_no_module_load() {
+ let mut set = crate::core::runtime::ComponentSet::all();
+ set.sandbox = false;
+ let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(set);
+ crate::core::runtime::context::CoreContext::scope(ctx, async {
+ assert!(sandbox_component_off());
+ assert!(sandbox_disabled_by_host());
+ assert!(!command_requires_sandbox(Some(SandboxMode::Sandboxed))
+ .await
+ .unwrap());
+ })
+ .await;
+}
+
+#[tokio::test]
+async fn sandbox_component_is_on_without_a_context_or_when_enabled() {
+ assert!(!sandbox_component_off());
+ let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(
+ crate::core::runtime::ComponentSet::all(),
+ );
+ crate::core::runtime::context::CoreContext::scope(ctx, async {
+ assert!(!sandbox_component_off());
+ })
+ .await;
+}
+
+#[test]
+fn config_disables_sandbox_for_legacy_flag_or_component() {
+ let mut config = crate::config::Config::default();
+ assert!(!config_disables_sandbox(&config));
+ config.sandbox.enabled = Some(false);
+ assert!(config_disables_sandbox(&config));
+ config.sandbox.enabled = None;
+ config.components.sandbox = false;
+ assert!(config_disables_sandbox(&config));
+}
diff --git a/crates/openhuman-core/src/sandbox/schemas_tests.rs b/crates/openhuman-core/src/sandbox/schemas_tests.rs
index a9476afba8..fa3e9193be 100644
--- a/crates/openhuman-core/src/sandbox/schemas_tests.rs
+++ b/crates/openhuman-core/src/sandbox/schemas_tests.rs
@@ -203,3 +203,38 @@ async fn handle_validate_policy_dangerous() {
let val = result.unwrap();
assert_eq!(val.get("valid").and_then(|v| v.as_bool()), Some(false));
}
+
+// ── [components] sandbox = false ──────────────────────────────────────
+
+#[tokio::test]
+async fn every_sandbox_method_answers_component_disabled_when_sandbox_is_off() {
+ let mut set = crate::core::runtime::ComponentSet::all();
+ set.sandbox = false;
+ let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(set);
+ let handlers: [fn(Map<String, Value>) -> ControllerFuture; 4] = [
+ handle_status,
+ handle_resolve_policy,
+ handle_cleanup_orphans,
+ handle_validate_policy,
+ ];
+ crate::core::runtime::context::CoreContext::scope(ctx, async {
+ for handler in handlers {
+ let err = handler(Map::new()).await.unwrap_err();
+ let decoded = crate::core::StructuredRpcError::decode(&err).expect("typed error");
+ assert_eq!(decoded.message, "COMPONENT_DISABLED:sandbox");
+ }
+ })
+ .await;
+}
+
+#[tokio::test]
+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(Map::new()).await.unwrap_err();
+ assert!(!err.contains("COMPONENT_DISABLED"), "{err}");
+ })
+ .await;
+}