Skip to content

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

test(ops): cover module operation edge cases

Steven Enamakel999f34d8dbc3
diff --git a/crates/openhuman-core/src/modules/ops_tests.rs b/crates/openhuman-core/src/modules/ops_tests.rs
index 94bdb26c00..961dde9069 100644
--- a/crates/openhuman-core/src/modules/ops_tests.rs
+++ b/crates/openhuman-core/src/modules/ops_tests.rs
@@ -9,7 +9,9 @@ use crate::config::Config;
use crate::modules::ops::{self, install_dir, list};
use crate::modules::registry;
use crate::modules::types::ModuleState;
-use tinybus::module::{LoadError, Reason, Resolver};
+#[cfg(feature = "crash-reporting")]
+use tinybus::module::Reason;
+use tinybus::module::{LoadError, Resolver};
fn test_bundled_record() -> &'static crate::modules::types::ModuleRecord {
use crate::modules::types::{LoadPolicy, ModuleRecord, PlatformAsset};
@@ -689,3 +691,109 @@ 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());
+}