Skip to content

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

feat(modules): resolve source-built module artifacts from disk

Steven Enamakel021aaaf66d93
diff --git a/crates/openhuman-core/src/modules/registry_tests.rs b/crates/openhuman-core/src/modules/registry_tests.rs
index 6f556e78f2..043e755d76 100644
--- a/crates/openhuman-core/src/modules/registry_tests.rs
+++ b/crates/openhuman-core/src/modules/registry_tests.rs
@@ -693,3 +693,32 @@ fn voice_capture_release_pins_summary_contract_and_every_platform_digest() {
assert_eq!(asset.sha256, digest);
}
}
+
+#[test]
+fn every_record_names_a_source_manifest_that_exists_in_its_submodule() {
+ let vendor = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../vendor");
+ for record in ALL {
+ let spec = &record.source;
+ assert!(!spec.package.is_empty(), "{}: package", record.id);
+ assert!(!spec.lib_name.is_empty(), "{}: lib_name", record.id);
+ assert_eq!(spec.submodule, record.id, "{}: submodule dir", record.id);
+ let manifest = vendor.join(spec.submodule).join(spec.manifest);
+ assert!(
+ manifest.is_file(),
+ "{}: source manifest {} is missing (is the submodule initialised?)",
+ record.id,
+ spec.manifest
+ );
+ }
+}
+
+#[test]
+fn source_artifact_file_names_follow_the_platform_convention() {
+ for record in ALL {
+ let name = record.source.artifact_filename();
+ assert!(name.contains(record.source.lib_name), "{}", record.id);
+ if cfg!(target_os = "linux") {
+ assert!(name.starts_with("lib") && name.ends_with(".so"), "{name}");
+ }
+ }
+}
diff --git a/crates/openhuman-core/src/modules/source.rs b/crates/openhuman-core/src/modules/source.rs
index fda56958d8..1dcafcccad 100644
--- a/crates/openhuman-core/src/modules/source.rs
+++ b/crates/openhuman-core/src/modules/source.rs
@@ -6,7 +6,7 @@
//! default everywhere and the only mode CI and shipped builds use; `linked` and
//! `source` exist for local development and local tests.
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use super::types::ModuleSource;
use crate::config::schema::ModuleSourceMode;
@@ -44,13 +44,30 @@ pub(super) fn linked_factory_available(id: &str) -> bool {
}
}
+/// Environment variable naming the directory `scripts/modules/build.mjs`
+/// wrote its artifacts under (`<dir>/<id>/<library>` plus a `modules.toml`
+/// carrying the operator-trust digest). The build step prints it.
+pub(crate) const SOURCE_DIR_ENV: &str = "OPENHUMAN_MODULE_SOURCE_DIR";
+
/// The locally built artifact for `id`, if one exists.
///
-/// Produced by the source-build step (E0.4); until it lands there is none, so a
-/// `source` request without an explicit path falls back to `release`.
+/// Looks under [`SOURCE_DIR_ENV`]; with the variable unset, or no built file
+/// there, a `source` request without an explicit path falls back to `release`.
+#[must_use]
+pub(super) fn source_artifact(id: &str) -> Option<PathBuf> {
+ let root = std::env::var_os(SOURCE_DIR_ENV)?;
+ artifact_in(Path::new(&root), id)
+}
+
+/// The built library for `id` under `root`, if the file exists.
+///
+/// The file name comes from the registry's `SourceSpec`, so the caller never
+/// supplies one and an unknown id has no artifact.
#[must_use]
-pub(super) fn source_artifact(_id: &str) -> Option<PathBuf> {
- None
+pub(super) fn artifact_in(root: &Path, id: &str) -> Option<PathBuf> {
+ let record = super::registry::find(id)?;
+ let path = root.join(record.id).join(record.source.artifact_filename());
+ path.is_file().then_some(path)
}
/// Choose the source for `id` under `config`.
diff --git a/crates/openhuman-core/src/modules/source_tests.rs b/crates/openhuman-core/src/modules/source_tests.rs
index 9ac5e13d31..d021e780b6 100644
--- a/crates/openhuman-core/src/modules/source_tests.rs
+++ b/crates/openhuman-core/src/modules/source_tests.rs
@@ -97,3 +97,22 @@ fn an_override_with_both_path_and_source_is_ignored() {
assert_eq!(plan.served, ModuleSource::Release);
assert_eq!(plan.artifact, None);
}
+
+#[test]
+fn artifact_in_finds_the_built_library_by_registry_file_name() {
+ let dir = tempfile::tempdir().unwrap();
+ let record = crate::modules::registry::find("tinydocs").unwrap();
+ assert_eq!(artifact_in(dir.path(), "tinydocs"), None);
+ let module_dir = dir.path().join("tinydocs");
+ std::fs::create_dir_all(&module_dir).unwrap();
+ let file = module_dir.join(record.source.artifact_filename());
+ std::fs::write(&file, b"x").unwrap();
+ assert_eq!(artifact_in(dir.path(), "tinydocs"), Some(file));
+}
+
+#[test]
+fn artifact_in_has_nothing_for_an_unknown_id() {
+ let dir = tempfile::tempdir().unwrap();
+ std::fs::create_dir_all(dir.path().join("nope")).unwrap();
+ assert_eq!(artifact_in(dir.path(), "nope"), None);
+}