Skip to content

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

test(modules): add coverage for client and ops module behaviour

Steven Enamakeld44fd5cca340
diff --git a/crates/openhuman-core/src/modules/client_tests.rs b/crates/openhuman-core/src/modules/ops_client_tests.rs
similarity index 100%
rename from crates/openhuman-core/src/modules/client_tests.rs
rename to crates/openhuman-core/src/modules/ops_client_tests.rs
diff --git a/crates/openhuman-core/src/modules/ops_tests.rs b/crates/openhuman-core/src/modules/ops_tests.rs
index e94680e756..94bdb26c00 100644
--- a/crates/openhuman-core/src/modules/ops_tests.rs
+++ b/crates/openhuman-core/src/modules/ops_tests.rs
@@ -9,6 +9,7 @@ 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};
fn test_bundled_record() -> &'static crate::modules::types::ModuleRecord {
use crate::modules::types::{LoadPolicy, ModuleRecord, PlatformAsset};
@@ -59,11 +60,11 @@ async fn invalid_installer_bundle_is_reported_without_falling_back_to_the_cache(
std::fs::write(bundle_dir.join(record.assets[0].archive), b"").unwrap();
let runtime = crate::modules::runtime::runtime().await.unwrap();
- let error = ops::load_cached(
+ let error = Resolver::load_cached(
runtime,
- record,
+ &record.release(),
user_cache.path(),
- serde_json::json!({}),
+ &serde_json::json!({}),
false,
Some(bundled.path()),
)
@@ -80,11 +81,11 @@ async fn absent_installer_bundle_uses_the_existing_cache_miss_path() {
let bundled = tempfile::tempdir().unwrap();
let user_cache = tempfile::tempdir().unwrap();
let runtime = crate::modules::runtime::runtime().await.unwrap();
- let error = ops::load_cached(
+ let error = Resolver::load_cached(
runtime,
- record,
+ &record.release(),
user_cache.path(),
- serde_json::json!({}),
+ &serde_json::json!({}),
false,
Some(bundled.path()),
)
@@ -270,14 +271,14 @@ async fn a_bounded_wait_with_nothing_cached_and_downloads_off_fails_rather_than_
assert_eq!(state, ModuleState::Ready);
assert_eq!(status.state, ModuleState::Ready);
}
- Err(ops::LoadError::Failed(reason)) => assert!(
+ Err(LoadError::Failed(reason)) => assert!(
reason.contains("downloads are disabled")
|| reason.contains("not available for this platform"),
"unhelpful message: {reason}"
),
other => panic!("expected a terminal failure or an already-serving module, got {other:?}"),
}
- if matches!(&outcome, Err(ops::LoadError::Failed(_))) {
+ if matches!(&outcome, Err(LoadError::Failed(_))) {
assert_eq!(state, ModuleState::Failed);
assert_eq!(status.state, ModuleState::Failed);
assert!(status.detail.is_some());
@@ -296,7 +297,12 @@ fn terminal_resolution_cached_failure_is_reported_when_a_client_becomes_availabl
let hub = std::sync::Arc::new(sentry::Hub::new_from_top(sentry::Hub::current()));
hub.bind_client(None);
sentry::Hub::run(hub, || {
- ops::report_resolution_failure(MODULE, "private token /home/private-user/module.so");
+ let record = registry::find(MODULE).unwrap();
+ crate::modules::report::reporter().report(
+ record.id,
+ record.version,
+ Reason::ResolutionFailed,
+ );
});
let sender = table.mark_in_flight(MODULE);
table.complete(
@@ -319,12 +325,12 @@ fn terminal_resolution_cached_failure_is_reported_when_a_client_becomes_availabl
ops::ensure_loaded_within(&config, MODULE, None),
);
for result in [first, second] {
- assert!(matches!(result, Err(ops::LoadError::Failed(_))));
+ assert!(matches!(result, Err(LoadError::Failed(_))));
}
let repeated = ops::ensure_loaded_within(&config, MODULE, None)
.await
.expect_err("the same cached failure remains terminal");
- assert!(matches!(repeated, ops::LoadError::Failed(_)));
+ assert!(matches!(repeated, LoadError::Failed(_)));
});
});
table.forget(MODULE);
@@ -357,7 +363,7 @@ fn terminal_resolution_wait_timeout_is_not_reported_as_terminal() {
Some(std::time::Duration::ZERO),
)
.await;
- assert!(matches!(result, Err(ops::LoadError::StillLoading)));
+ assert!(matches!(result, Err(LoadError::StillLoading)));
});
});
table.forget(MODULE);
@@ -393,16 +399,16 @@ fn a_module_nobody_asked_for_is_available_not_loading() {
#[test]
fn load_errors_render_for_callers_that_cannot_wait_again() {
assert_eq!(
- ops::LoadError::Failed("refused".to_string()).into_message(),
+ LoadError::Failed("refused".to_string()).into_message(),
"refused"
);
- let message = ops::LoadError::StillLoading.into_message();
+ let message = LoadError::StillLoading.into_message();
assert!(message.contains("still loading"), "{message}");
}
-#[tokio::test]
-async fn a_loader_error_carries_the_terminal_marker_exactly_once() {
- // `blocking` marks a loader error terminal, but tinybus' release-cache path
+#[test]
+fn a_loader_error_carries_the_terminal_marker_exactly_once() {
+ // The resolver marks a loader error terminal, but tinybus' release-cache path
// and `load_local` already say so; appending again doubled the sentence.
// The failure policy keys on both phrases, so each must stay, once.
let marker = tinytools::status::MODULE_FAULT_MARKER;
@@ -412,8 +418,7 @@ async fn a_loader_error_carries_the_terminal_marker_exactly_once() {
"module 'tinydocs' could not be loaded from the installer bundle: refused. Restart the \
app after repairing the installation",
] {
- let owned = loader_error.to_string();
- let error = ops::blocking(move || Err(owned)).await.unwrap_err();
+ let error = ops::resolver(&Config::default()).mark_terminal(loader_error.to_string());
assert_eq!(error.matches(marker).count(), 1, "{error}");
assert_eq!(
error.matches("restart the app to try again").count(),
@@ -437,9 +442,11 @@ fn a_failed_resolution_is_reported_once_with_the_module_id() {
// report is the one Sentry event per broken install. Every later caller's
// re-report is demoted as `ModuleUnavailable`; this one must not be.
let events = sentry::test::with_captured_events(|| {
- ops::report_resolution_failure(
- "tinyconnectors",
- "private-test-token /home/private-user/document.txt",
+ let record = registry::find("tinyconnectors").unwrap();
+ crate::modules::report::reporter().report(
+ record.id,
+ record.version,
+ Reason::ResolutionFailed,
);
});
assert_eq!(events.len(), 1, "{events:?}");
@@ -538,13 +545,13 @@ fn bundled_dir_skips_a_missing_candidate_for_a_valid_later_one() {
/// carry the terminal marker the observability classifier demotes on.
#[test]
fn a_marked_bus_startup_failure_is_classified_as_module_unavailable() {
- let marked = ops::mark_terminal("the module bus could not start: no runtime".to_string());
+ let marked = ops::resolver(&Config::default()).mark_terminal("the module bus could not start: no runtime".to_string());
assert!(marked.ends_with("restart the app to try again"), "{marked}");
assert!(crate::core::observability::is_module_unavailable_message(
&marked
));
// Idempotent: an already-marked error is not annotated twice.
- assert_eq!(ops::mark_terminal(marked.clone()), marked);
+ assert_eq!(ops::resolver(&Config::default()).mark_terminal(marked.clone()), marked);
}
#[tokio::test]
@@ -625,7 +632,7 @@ async fn a_registered_linked_factory_serves_the_module_and_status_says_so() {
#[tokio::test]
async fn attaching_a_linked_module_without_a_factory_fails_with_a_static_reason() {
let runtime = crate::modules::runtime::runtime().await.expect("module host");
- let error = ops::load_linked(runtime, "tinyhosts-no-factory", serde_json::json!({}))
+ let error = Resolver::load_linked(runtime, "tinyhosts-no-factory", None, serde_json::json!({}))
.expect_err("no factory is registered for this id");
assert!(error.contains("no linked factory"), "{error}");
assert!(!error.contains('/'), "{error}");
@@ -636,9 +643,13 @@ async fn a_failing_linked_factory_is_reported_without_its_error_detail() {
fn failing() -> tinybus::Result<tinybus::module::LinkedModule> {
Err(tinybus::Error::failed("secret-token /home/user/path"))
}
- crate::modules::linked::register_linked("linked-failing-test", failing);
let runtime = crate::modules::runtime::runtime().await.expect("module host");
- let error = ops::load_linked(runtime, "linked-failing-test", serde_json::json!({}))
+ let error = Resolver::load_linked(
+ runtime,
+ "linked-failing-test",
+ Some(failing),
+ serde_json::json!({}),
+ )
.expect_err("the factory fails");
assert!(
error.contains("linked factory could not be started"),
diff --git a/crates/openhuman-core/src/modules/report.rs b/crates/openhuman-core/src/modules/report.rs
index 5513e43571..5d2c8667a9 100644
--- a/crates/openhuman-core/src/modules/report.rs
+++ b/crates/openhuman-core/src/modules/report.rs
@@ -56,7 +56,7 @@ impl FailureSink for SentrySink {
/// The reporter shared by every resolver and client in this process.
#[must_use]
-pub(super) fn reporter() -> Arc<FailureReporter> {
+pub(crate) fn reporter() -> Arc<FailureReporter> {
static REPORTER: OnceLock<Arc<FailureReporter>> = OnceLock::new();
Arc::clone(REPORTER.get_or_init(|| Arc::new(FailureReporter::new(Arc::new(SentrySink)))))
}