Skip to content

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

test(runtime): cover component-disabled gating across handlers

Steven Enamakeld98fad21ec20
diff --git a/crates/openhuman-core/src/core/runtime/components.rs b/crates/openhuman-core/src/core/runtime/components.rs
index 3c8eca18ec..09f3958bcd 100644
--- a/crates/openhuman-core/src/core/runtime/components.rs
+++ b/crates/openhuman-core/src/core/runtime/components.rs
@@ -187,10 +187,7 @@ pub fn component_disabled(name: &str) -> StructuredRpcError {
/// Refuse an RPC handler with the encoded `COMPONENT_DISABLED:<name>` error
/// when the config it loaded has `name` switched off. For handlers that load
/// their own config and so cannot read the ambient scope.
-pub fn require_config(
- config: &crate::config::Config,
- name: &str,
-) -> Result<(), String> {
+pub fn require_config(config: &crate::config::Config, name: &str) -> Result<(), String> {
if config.components.get(name).unwrap_or(true) {
Ok(())
} else {
diff --git a/crates/openhuman-core/src/core/runtime/components_tests.rs b/crates/openhuman-core/src/core/runtime/components_tests.rs
index cbd3d7eca7..b484306ec7 100644
--- a/crates/openhuman-core/src/core/runtime/components_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/components_tests.rs
@@ -145,3 +145,13 @@ fn channels_off_names_the_typed_error_and_owns_the_channels_group() {
Some("channels")
);
}
+
+#[test]
+fn require_config_refuses_with_the_typed_error_only_when_the_flag_is_off() {
+ let mut config = crate::config::Config::default();
+ assert!(require_config(&config, "computer").is_ok());
+ config.components.computer = false;
+ let err = require_config(&config, "computer").unwrap_err();
+ assert!(err.contains("COMPONENT_DISABLED:computer"), "{err}");
+ assert!(require_config(&config, "search").is_ok());
+}
diff --git a/crates/openhuman-core/src/desktop/control/ops_tests.rs b/crates/openhuman-core/src/desktop/control/ops_tests.rs
index 09aca84ee4..23b12f1315 100644
--- a/crates/openhuman-core/src/desktop/control/ops_tests.rs
+++ b/crates/openhuman-core/src/desktop/control/ops_tests.rs
@@ -332,3 +332,23 @@ fn approval_bypass_requires_a_registered_desktop_tool_and_disabled_setting() {
config.desktop.approvals_enabled = true;
assert!(!approval_bypass_decision(&config, &goal));
}
+
+#[test]
+fn component_off_overrides_local_consent() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = Config::default();
+ config.workspace_dir = dir.path().to_path_buf();
+ save(&config, true).unwrap();
+ assert!(enabled(&config));
+ config.components.computer = false;
+ assert!(!enabled(&config), "component off must disable despite consent");
+}
+
+#[test]
+fn component_on_without_local_consent_stays_disabled() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = Config::default();
+ config.workspace_dir = dir.path().to_path_buf();
+ assert!(config.components.computer);
+ assert!(!enabled(&config));
+}
diff --git a/crates/openhuman-core/src/modules/accessibility_tests.rs b/crates/openhuman-core/src/modules/accessibility_tests.rs
index 2274c2fd32..03b3e253b9 100644
--- a/crates/openhuman-core/src/modules/accessibility_tests.rs
+++ b/crates/openhuman-core/src/modules/accessibility_tests.rs
@@ -249,3 +249,17 @@ async fn released_module_serves_permissions_and_confidential_target_validation()
assert!(matches!(client.globe_start().await,
Err(AccessibilityError::Operation(error)) if error.code == "PLATFORM_NOT_SUPPORTED"));
}
+
+#[tokio::test]
+async fn component_off_refuses_before_reaching_the_module() {
+ let mut config = Config::default();
+ config.components.computer = false;
+ let client = AccessibilityClient::new(&config);
+ assert!(!client.computer_enabled());
+ match client.permissions().await {
+ Err(AccessibilityError::Operation(error)) => {
+ assert_eq!(error.message, "COMPONENT_DISABLED:computer");
+ }
+ other => panic!("expected COMPONENT_DISABLED, got {other:?}"),
+ }
+}
diff --git a/crates/openhuman-core/src/tools/ops_tests_execution_and_serde_tests.rs b/crates/openhuman-core/src/tools/ops_tests_execution_and_serde_tests.rs
index 97eb3d96d9..22f0e3a402 100644
--- a/crates/openhuman-core/src/tools/ops_tests_execution_and_serde_tests.rs
+++ b/crates/openhuman-core/src/tools/ops_tests_execution_and_serde_tests.rs
@@ -38,6 +38,40 @@ fn all_tools_includes_browser_when_enabled() {
assert!(names.contains(&"proxy_config"));
}
+#[test]
+fn computer_component_off_unregisters_desktop_and_browser_tools() {
+ let tmp = TempDir::new().unwrap();
+ let security = Arc::new(SecurityPolicy::default());
+ let browser = BrowserConfig {
+ enabled: true,
+ allowed_domains: vec!["example.com".into()],
+ session_name: None,
+ ..BrowserConfig::default()
+ };
+ let http = crate::config::HttpRequestConfig::default();
+ let cfg = test_config(&tmp);
+ let mut root = Config::default();
+ root.components.computer = false;
+
+ let tools = all_tools(
+ Arc::new(root),
+ &security,
+ AuditLogger::disabled(),
+ &browser,
+ &http,
+ tmp.path(),
+ &HashMap::new(),
+ &cfg,
+ );
+ let names: Vec<&str> = tools.iter().map(|t| t.name()).collect();
+ assert!(!names.contains(&"browser_open"), "{names:?}");
+ assert!(!names.contains(&"browser"), "{names:?}");
+ assert!(
+ !names.iter().any(|name| name.starts_with("desktop_")),
+ "{names:?}"
+ );
+}
+
#[test]
fn default_tools_all_have_descriptions() {
let security = Arc::new(SecurityPolicy::default());