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(modules): move module resolution tests into their own file
Steven Enamakeldee789451209
diff --git a/crates/openhuman-core/src/modules/ops.rs b/crates/openhuman-core/src/modules/ops.rsindex 9fd2e4766f..4a83048f3a 100644--- a/crates/openhuman-core/src/modules/ops.rs+++ b/crates/openhuman-core/src/modules/ops.rs@@ -399,3 +399,7 @@ mod components_tests;#[cfg(test)]#[path = "ops_client_tests.rs"]mod client_tests;++#[cfg(test)]+#[path = "ops_resolver_tests.rs"]+mod resolver_tests;diff --git a/crates/openhuman-core/src/modules/ops_resolver_tests.rs b/crates/openhuman-core/src/modules/ops_resolver_tests.rsnew file mode 100644index 0000000000..ab6d69b376--- /dev/null+++ b/crates/openhuman-core/src/modules/ops_resolver_tests.rs@@ -0,0 +1,118 @@+//! Host-level regression tests for the resolver adapter: a faulted module is+//! never retried in the process, and `modules.list` keeps its wire shape.++use crate::config::Config;+use crate::modules::ops::{self, list};+use crate::modules::registry;+use crate::modules::types::ModuleState;+use tinybus::module::LoadError;++/// A config with modules on but downloads off, so nothing reaches the network.+fn offline_config() -> Config {+ let mut config = Config::default();+ config.modules.enabled = true;+ config.modules.allow_download = false;+ config+}++/// A faulted module stays faulted until the process restarts: tinybus never+/// unloads a library, so a retry would pay a download and a `dlopen` to reach+/// the same error. The cached outcome wins over whatever configuration the+/// later caller holds.+#[tokio::test]+async fn a_faulted_module_is_not_retried_in_process() {+ use crate::config::schema::ModuleOverride;+ const MODULE: &str = "tinysearch";+ let table = tinybus::module::resolution::global();+ table.forget(MODULE);++ let missing = tempfile::tempdir().unwrap().path().join("absent-module.so");+ let mut faulting = Config::default();+ faulting.modules.enabled = true;+ faulting.modules.overrides.push(ModuleOverride::with_path(+ MODULE,+ missing.to_string_lossy().into_owned(),+ ));+ let first = ops::ensure_loaded_within(&faulting, MODULE, None)+ .await+ .unwrap_err();+ let LoadError::Failed(first) = first else {+ panic!("a missing local artifact is a terminal failure: {first:?}");+ };+ assert!(first.contains("local artifact"), "{first}");+ assert!(first.contains("restart the app to try again"), "{first}");+ assert_eq!(ops::state_of(MODULE), ModuleState::Failed);++ // A later caller whose configuration would take a different rung (downloads+ // off, no override) still gets the cached outcome, not a second attempt.+ let mut offline = Config::default();+ offline.modules.enabled = true;+ offline.modules.allow_download = false;+ for _ in 0..3 {+ let again = ops::ensure_loaded_within(&offline, MODULE, None)+ .await+ .unwrap_err();+ assert_eq!(again, LoadError::Failed(first.clone()));+ }+ let status = list(&offline).into_iter().find(|m| m.id == MODULE).unwrap();+ assert_eq!(status.state, ModuleState::Failed);+ assert_eq!(status.detail.as_deref(), Some(first.as_str()));+ table.forget(MODULE);+}++/// `modules.list` is a wire contract: the field names and the snake_case state+/// and source spellings are what clients parse.+#[test]+fn modules_list_output_keeps_its_wire_shape() {+ let config = offline_config();+ let statuses = list(&config);+ assert_eq!(statuses.len(), registry::ALL.len());+ for (status, record) in statuses.iter().zip(registry::ALL) {+ assert_eq!(status.id, record.id);+ assert_eq!(status.description, record.description);+ assert_eq!(status.version, record.version);+ assert_eq!(status.bus_name, record.bus_name);+ let wire = serde_json::to_value(status).unwrap();+ let object = wire.as_object().unwrap();+ let allowed = [+ "id",+ "description",+ "version",+ "bus_name",+ "state",+ "source",+ "detail",+ ];+ for key in object.keys() {+ assert!(allowed.contains(&key.as_str()), "unexpected field {key}");+ }+ for key in ["id", "description", "version", "bus_name", "state"] {+ assert!(object.contains_key(key), "missing field {key}");+ }+ let state = object["state"].as_str().unwrap();+ assert!(+ [+ "available",+ "loading",+ "ready",+ "failed",+ "unsupported",+ "disabled"+ ]+ .contains(&state),+ "{state}"+ );+ if let Some(source) = object.get("source") {+ assert!(+ ["release", "linked", "source", "local_file"].contains(&source.as_str().unwrap()),+ "{source}"+ );+ }+ }+ let mut disabled = offline_config();+ disabled.modules.enabled = false;+ let wire = serde_json::to_value(&list(&disabled)[0]).unwrap();+ assert_eq!(wire["state"], "unsupported");+ assert_eq!(wire["detail"], "modules are disabled in configuration");+ assert!(wire.get("source").is_none());+}diff --git a/crates/openhuman-core/src/modules/ops_tests.rs b/crates/openhuman-core/src/modules/ops_tests.rsindex 0b8579dbb9..e29059d7ec 100644--- a/crates/openhuman-core/src/modules/ops_tests.rs+++ b/crates/openhuman-core/src/modules/ops_tests.rs@@ -702,105 +702,3 @@ fn the_ahead_warning_is_silent_for_released_modules_other_ids_and_release_builds// A release build never warns.assert!(pin_ahead_warning("tinydocs", ModuleSource::Source, Some("tinydocs"), false).is_none());}--/// A faulted module stays faulted until the process restarts: tinybus never-/// unloads a library, so a retry would pay a download and a `dlopen` to reach-/// the same error. The cached outcome wins over whatever configuration the-/// later caller holds.-#[tokio::test]-async fn a_faulted_module_is_not_retried_in_process() {- use crate::config::schema::ModuleOverride;- const MODULE: &str = "tinysearch";- let table = tinybus::module::resolution::global();- table.forget(MODULE);-- let missing = tempfile::tempdir().unwrap().path().join("absent-module.so");- let mut faulting = Config::default();- faulting.modules.enabled = true;- faulting.modules.overrides.push(ModuleOverride::with_path(- MODULE,- missing.to_string_lossy().into_owned(),- ));- let first = ops::ensure_loaded_within(&faulting, MODULE, None)- .await- .unwrap_err();- let LoadError::Failed(first) = first else {- panic!("a missing local artifact is a terminal failure: {first:?}");- };- assert!(first.contains("local artifact"), "{first}");- assert!(first.contains("restart the app to try again"), "{first}");- assert_eq!(ops::state_of(MODULE), ModuleState::Failed);-- // A later caller whose configuration would take a different rung (downloads- // off, no override) still gets the cached outcome, not a second attempt.- let mut offline = Config::default();- offline.modules.enabled = true;- offline.modules.allow_download = false;- for _ in 0..3 {- let again = ops::ensure_loaded_within(&offline, MODULE, None)- .await- .unwrap_err();- assert_eq!(again, LoadError::Failed(first.clone()));- }- let status = list(&offline).into_iter().find(|m| m.id == MODULE).unwrap();- assert_eq!(status.state, ModuleState::Failed);- assert_eq!(status.detail.as_deref(), Some(first.as_str()));- table.forget(MODULE);-}--/// `modules.list` is a wire contract: the field names and the snake_case state-/// and source spellings are what clients parse.-#[test]-fn modules_list_output_keeps_its_wire_shape() {- let config = offline_config();- let statuses = list(&config);- assert_eq!(statuses.len(), registry::ALL.len());- for (status, record) in statuses.iter().zip(registry::ALL) {- assert_eq!(status.id, record.id);- assert_eq!(status.description, record.description);- assert_eq!(status.version, record.version);- assert_eq!(status.bus_name, record.bus_name);- let wire = serde_json::to_value(status).unwrap();- let object = wire.as_object().unwrap();- let allowed = [- "id",- "description",- "version",- "bus_name",- "state",- "source",- "detail",- ];- for key in object.keys() {- assert!(allowed.contains(&key.as_str()), "unexpected field {key}");- }- for key in ["id", "description", "version", "bus_name", "state"] {- assert!(object.contains_key(key), "missing field {key}");- }- let state = object["state"].as_str().unwrap();- assert!(- [- "available",- "loading",- "ready",- "failed",- "unsupported",- "disabled"- ]- .contains(&state),- "{state}"- );- if let Some(source) = object.get("source") {- assert!(- ["release", "linked", "source", "local_file"].contains(&source.as_str().unwrap()),- "{source}"- );- }- }- let mut disabled = offline_config();- disabled.modules.enabled = false;- let wire = serde_json::to_value(&list(&disabled)[0]).unwrap();- assert_eq!(wire["state"], "unsupported");- assert_eq!(wire["detail"], "modules are disabled in configuration");- assert!(wire.get("source").is_none());-}diff --git a/crates/openhuman-core/src/storage/import/tinyflows_cron_tests.rs b/crates/openhuman-core/src/storage/import/tinyflows_cron_tests.rsindex 2dccce1330..490a7a558f 100644--- a/crates/openhuman-core/src/storage/import/tinyflows_cron_tests.rs+++ b/crates/openhuman-core/src/storage/import/tinyflows_cron_tests.rs@@ -20,7 +20,8 @@ fn copy_tree(from: &Path, to: &Path) {#[test]fn run_with_imports_legacy_cron_jobs_whatever_the_flows_gate() {let dir = tempfile::TempDir::new().unwrap();- let fixtures = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/storage/import/fixtures/tinyflows/workspace");+ let fixtures = Path::new(env!("CARGO_MANIFEST_DIR"))+ .join("src/storage/import/fixtures/tinyflows/workspace");copy_tree(&fixtures, dir.path());let config = Config {workspace_dir: dir.path().to_path_buf(),@@ -39,7 +40,10 @@ fn run_with_imports_legacy_cron_jobs_whatever_the_flows_gate() {}let docs = Arc::clone(backend.for_scope(&Scope::local()).unwrap().documents());let jobs = crate::storage::block_on_anyhow(async move {- CronDocuments::new(docs).list_jobs().await.map_err(Into::into)+ CronDocuments::new(docs)+ .list_jobs()+ .await+ .map_err(Into::into)}).unwrap();assert!(!jobs.is_empty());diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rsindex c67794d377..2d14fc5cd5 100644--- a/crates/openhuman-core/src/tools/impl/system/shell.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs@@ -1,7 +1,7 @@use super::shell_description::{command_param_description, shell_description};-use super::shell_support::{command_failure, exec_result, python_utf8_env, tool_timeout_message};#[cfg(feature = "modules")]use super::shell_support::container_environment;+use super::shell_support::{command_failure, exec_result, python_utf8_env, tool_timeout_message};use crate::agent::host_runtime::RuntimeAdapter;use crate::config::Config;use crate::security::{AuditLogger, CommandExecutionLog, SecurityPolicy};