Skip to content

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

feat(modules): expose local_artifact helper for tests

Steven Enamakeld51e6993317d
diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rs
index 5e3330a31c..54d2a2959c 100644
--- a/crates/openhuman-core/src/modules/mod.rs
+++ b/crates/openhuman-core/src/modules/mod.rs
@@ -108,4 +108,6 @@ pub(crate) mod x402_service;
pub use ops::{ensure_loaded, ensure_loaded_within, state_of, LoadError};
#[cfg(feature = "modules")]
pub use schemas::{all_controller_schemas, all_registered_controllers};
+#[doc(hidden)]
+pub use source::local_artifact;
pub use types::{LoadPolicy, ModuleRecord, ModuleSource, ModuleState, ModuleStatus, PlatformAsset};
diff --git a/crates/openhuman-core/src/modules/ops_tests.rs b/crates/openhuman-core/src/modules/ops_tests.rs
index d0db5b2b8e..d9b4408f8a 100644
--- a/crates/openhuman-core/src/modules/ops_tests.rs
+++ b/crates/openhuman-core/src/modules/ops_tests.rs
@@ -33,6 +33,13 @@ fn test_bundled_record() -> &'static crate::modules::types::ModuleRecord {
release_url: "https://github.com/tinyhumansai/tinydocs/releases/tag/v0.1.16",
assets,
load: LoadPolicy::Lazy,
+ source: crate::modules::types::SourceSpec {
+ submodule: "tinydocs",
+ manifest: "Cargo.toml",
+ package: "test-bundled-module",
+ lib_name: "test_bundled_module",
+ features: &[],
+ },
}))
}
diff --git a/crates/openhuman-core/src/modules/source.rs b/crates/openhuman-core/src/modules/source.rs
index 1dcafcccad..6bbc626ffd 100644
--- a/crates/openhuman-core/src/modules/source.rs
+++ b/crates/openhuman-core/src/modules/source.rs
@@ -70,6 +70,25 @@ pub(super) fn artifact_in(root: &Path, id: &str) -> Option<PathBuf> {
path.is_file().then_some(path)
}
+/// A real module library for `id` on this machine, for tests that need one.
+///
+/// Looks first under [`SOURCE_DIR_ENV`] (a `scripts/modules/build.mjs` build),
+/// then in every `OPENHUMAN_MODULE_PATH` directory (the released modules the
+/// CI installer stages). `None` means the test should skip, not fail: no module
+/// was provided. Never used by the loader, which goes through [`plan`].
+#[doc(hidden)]
+#[must_use]
+pub fn local_artifact(id: &str) -> Option<PathBuf> {
+ if let Some(path) = source_artifact(id) {
+ return Some(path);
+ }
+ let name = super::registry::find(id)?.source.artifact_filename();
+ let dirs = std::env::var_os("OPENHUMAN_MODULE_PATH")?;
+ std::env::split_paths(&dirs)
+ .map(|dir| dir.join(&name))
+ .find(|path| path.is_file())
+}
+
/// Choose the source for `id` under `config`.
pub(super) fn plan(config: &Config, id: &str) -> SourcePlan {
plan_with(