Skip to content

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

fix(modules): move path-safety helpers to tinybus and drop redundant tests

Steven Enamakel599f2a3d733c
diff --git a/crates/openhuman-core/src/modules/memory_tests.rs b/crates/openhuman-core/src/modules/memory_tests.rs
index 297f8f5fdb..9e90e891eb 100644
--- a/crates/openhuman-core/src/modules/memory_tests.rs
+++ b/crates/openhuman-core/src/modules/memory_tests.rs
@@ -235,7 +235,7 @@ async fn shutdown_on_an_unused_driver_is_a_no_op() {
#[tokio::test]
async fn a_read_against_a_loading_module_reports_unavailable_within_its_grace() {
- use crate::modules::resolution::{self, Resolution};
+ use tinybus::module::resolution::{self, Resolution};
use tinymemory_api::provider::mandatory::MemoryCore;
// Plant an in-flight slot for the memory module. The table is process-wide
@@ -243,8 +243,8 @@ async fn a_read_against_a_loading_module_reports_unavailable_within_its_grace()
// removed before this test returns; a parallel caller sees, at worst, a
// brief "loading" followed by the terminal failure it would have reached
// anyway with downloads off.
- let table = resolution::table();
- let sender = table.mark_in_flight_for_test(MODULE_ID);
+ let table = resolution::global();
+ let sender = table.mark_in_flight(MODULE_ID);
let provider = ModuleMemoryProvider::new(Arc::new(Config::default()))
.with_loading_grace(std::time::Duration::from_millis(30));
@@ -261,7 +261,7 @@ async fn a_read_against_a_loading_module_reports_unavailable_within_its_grace()
Resolution::Failed("planted by a test".to_string()),
sender,
);
- table.reset_for_test(MODULE_ID);
+ table.forget(MODULE_ID);
// Loading is degraded, never down: `Down` is what rebinds the fallback.
assert!(
diff --git a/crates/openhuman-core/src/modules/ops.rs b/crates/openhuman-core/src/modules/ops.rs
index 2e37f3ae14..6111aabe52 100644
--- a/crates/openhuman-core/src/modules/ops.rs
+++ b/crates/openhuman-core/src/modules/ops.rs
@@ -35,11 +35,13 @@ use std::path::{Path, PathBuf};
use std::sync::OnceLock;
use std::time::Duration;
-use tinybus::module::resolution::{self, Claim, Resolution, ResolutionState, ResolutionTable, Waited};
-use tinybus::module::{artifact_dir, prune_stale_versions};
use super::types::{ModuleRecord, ModuleState, ModuleStatus};
use super::{host, platform, registry};
use crate::config::Config;
+use tinybus::module::resolution::{
+ self, Claim, Resolution, ResolutionState, ResolutionTable, Waited,
+};
+use tinybus::module::{artifact_dir, prune_stale_versions};
/// Installer-owned, read-only release cache. The desktop host sets this before
/// starting the embedded core; other hosts continue using the user cache.
@@ -310,7 +312,9 @@ fn load_cached(
let mut found_bundled = false;
if let Some(bundled_root) = bundled_root {
for asset in &assets {
- let Some(cache_dir) = artifact_dir(bundled_root, record.id, record.version, asset.host_key) else {
+ let Some(cache_dir) =
+ artifact_dir(bundled_root, record.id, record.version, asset.host_key)
+ else {
continue;
};
if !cache_dir.join(asset.archive).is_file() {
@@ -351,7 +355,8 @@ fn load_cached(
));
}
for asset in assets {
- let Some(cache_dir) = artifact_dir(install_root, record.id, record.version, asset.host_key) else {
+ let Some(cache_dir) = artifact_dir(install_root, record.id, record.version, asset.host_key)
+ else {
last_error =
"the module's cache path could not be built from its registry entry".to_string();
continue;
diff --git a/crates/openhuman-core/src/modules/ops_tests.rs b/crates/openhuman-core/src/modules/ops_tests.rs
index 5abfe7f9d7..c12c0d6cfd 100644
--- a/crates/openhuman-core/src/modules/ops_tests.rs
+++ b/crates/openhuman-core/src/modules/ops_tests.rs
@@ -305,53 +305,18 @@ async fn a_bounded_wait_with_nothing_cached_and_downloads_off_fails_rather_than_
}
#[test]
-fn each_artifact_of_a_version_has_its_own_cache_directory() {
- let record = registry::find("tinydocs").expect("tinydocs is a registry entry");
- let root = std::path::Path::new("/cache/modules");
- let dir = ops::artifact_dir(root, record, "macos-26-arm64").expect("a usable cache path");
- assert_eq!(
- dir,
- root.join("tinydocs")
- .join(record.version)
- .join("macos-26-arm64")
- );
- assert_ne!(Some(dir), ops::artifact_dir(root, record, "macos-15-arm64"));
-}
-
-#[test]
-fn a_component_that_cannot_name_a_directory_yields_no_cache_path() {
- // The delete in `prune_stale_versions` is built from these components, so
- // a value that escapes its directory must produce no path at all rather
- // than one that resolves somewhere else.
- for bad in ["..", ".", "", "a/b", "a\\b", ".hidden", "a\0b"] {
- assert!(
- !ops::is_safe_path_component(bad),
- "{bad:?} must be refused as a directory name"
- );
- }
- for good in [
- "tinydocs",
- "0.1.15",
- "macos-26-arm64",
- "ubuntu-22.04-x86_64",
- ] {
- assert!(ops::is_safe_path_component(good), "{good:?} is a real name");
- }
-
- let record = registry::find("tinydocs").expect("tinydocs is a registry entry");
- let root = std::path::Path::new("/cache/modules");
- assert_eq!(ops::artifact_dir(root, record, ".."), None);
- assert_eq!(ops::artifact_dir(root, record, "a/b"), None);
+fn every_shipped_registry_entry_names_a_cache_directory() {
// Every shipped registry entry names a directory on every host it claims.
for entry in registry::ALL {
assert!(
- ops::is_safe_path_component(entry.id) && ops::is_safe_path_component(entry.version),
+ tinybus::module::is_safe_path_component(entry.id)
+ && tinybus::module::is_safe_path_component(entry.version),
"registry entry '{}' cannot name a cache directory",
entry.id
);
for asset in entry.assets {
assert!(
- ops::is_safe_path_component(asset.host_key),
+ tinybus::module::is_safe_path_component(asset.host_key),
"'{}' host key '{}' cannot name a cache directory",
entry.id,
asset.host_key
@@ -360,35 +325,6 @@ fn a_component_that_cannot_name_a_directory_yields_no_cache_path() {
}
}
-#[test]
-fn pruning_keeps_the_pinned_version_and_anything_still_being_staged() {
- let record = registry::find("tinydocs").expect("tinydocs is a registry entry");
- let install = tempfile::tempdir().expect("temp install dir");
- let module_root = install.path().join(record.id);
- let pinned = module_root.join(record.version);
- let stale = module_root.join("0.0.1");
- let staging = module_root.join(".staging-abc123");
- for dir in [&pinned, &stale, &staging] {
- std::fs::create_dir_all(dir).unwrap();
- std::fs::write(dir.join("marker"), b"x").unwrap();
- }
- // A stray file beside the version directories is not a version.
- std::fs::write(module_root.join("notes.txt"), b"x").unwrap();
-
- ops::prune_stale_versions(install.path(), record);
-
- assert!(pinned.join("marker").is_file(), "the pinned version stays");
- assert!(
- staging.join("marker").is_file(),
- "an in-progress staging dir stays"
- );
- assert!(!stale.exists(), "an unpinned version is removed");
- assert!(module_root.join("notes.txt").is_file());
-
- // A module that was never cached has nothing to prune, and says nothing.
- ops::prune_stale_versions(&install.path().join("never"), record);
-}
-
#[test]
fn a_module_nobody_asked_for_is_available_not_loading() {
assert_eq!(ops::state_of("never-asked"), ModuleState::Available);