Skip to content

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

test(storage): cover host bus, cdylib, and linked storage paths

Steven Enamakel22cbd0eb121e
diff --git a/crates/openhuman-core/src/modules/storage_host_bus_tests.rs b/crates/openhuman-core/src/modules/storage_host_bus_tests.rs
index b6dc01f069..b14b761a44 100644
--- a/crates/openhuman-core/src/modules/storage_host_bus_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_host_bus_tests.rs
@@ -5,36 +5,21 @@ use tinystoragedrivers_busproxy::{ERROR_DENIED, OBJECT_ROOT};
#[test]
fn module_scopes_are_distinct_per_module_and_per_tenant() {
- let local = Scope::local();
- let a = module_scope(None, &local, "alpha").unwrap();
- let b = module_scope(None, &local, "beta").unwrap();
+ let a = module_scope(None, "alpha").unwrap();
+ let b = module_scope(None, "beta").unwrap();
assert_ne!(a, b);
- assert_eq!(a.as_str(), "module:alpha@local");
- let acme = module_scope(
- Some("acme"),
- &crate::storage::scope_for_profile("acme"),
- "alpha",
- )
- .unwrap();
+ assert_eq!(a.as_str(), "local/module:alpha");
+ let acme = module_scope(Some("acme"), "alpha").unwrap();
assert_ne!(a, acme);
- let other = module_scope(
- Some("globex"),
- &crate::storage::scope_for_profile("globex"),
- "alpha",
- )
- .unwrap();
+ assert_eq!(acme.as_str(), "u:acme/module:alpha");
+ let other = module_scope(Some("globex"), "alpha").unwrap();
assert_ne!(acme, other);
}
#[test]
fn a_profiles_module_scope_sits_under_its_lease_fence() {
for profile in ["acme", "user-1_x", "h-0123456789abcdef0123456789abcdef"] {
- let scope = module_scope(
- Some(profile),
- &crate::storage::scope_for_profile(profile),
- "tinymcp",
- )
- .unwrap();
+ let scope = module_scope(Some(profile), "tinymcp").unwrap();
let covered =
crate::profiles::fence::scopes_of(&crate::profiles::ProfileId::parse(profile).unwrap());
assert!(
@@ -49,18 +34,15 @@ fn a_profiles_module_scope_sits_under_its_lease_fence() {
}
#[test]
-fn an_ambiguous_module_id_falls_back_to_a_hashed_scope() {
- let local = Scope::local();
- let hashed = module_scope(None, &local, "a@b").unwrap();
- assert!(hashed.as_str().starts_with("module-sha256:"));
- assert_ne!(hashed, module_scope(None, &local, "a@c").unwrap());
- // For a profile there is no hash fallback: it would leave the fence.
- assert!(module_scope(
- Some("acme"),
- &crate::storage::scope_for_profile("acme"),
- "a@b"
- )
- .is_err());
+fn an_unusual_module_id_is_hashed_inside_its_tenant() {
+ let hashed = module_scope(Some("acme"), "a@b c").unwrap();
+ assert!(hashed.as_str().starts_with("u:acme/module:~"), "{hashed}");
+ assert_ne!(hashed, module_scope(Some("acme"), "a@b d").unwrap());
+ // Hashing keeps the scope under the fence.
+ assert_eq!(
+ hashed.tenant_scope(),
+ Some(crate::storage::scope_for_profile("acme"))
+ );
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/modules/storage_host_cdylib_tests.rs b/crates/openhuman-core/src/modules/storage_host_cdylib_tests.rs
index 0d3a42865f..e9a1a6e474 100644
--- a/crates/openhuman-core/src/modules/storage_host_cdylib_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_host_cdylib_tests.rs
@@ -131,7 +131,7 @@ impl Environment for Env {
Some(Arc::clone(&self.0))
}
fn module_scope(&self, module_id: &str) -> Result<Scope, StorageError> {
- module_scope(None, &Scope::local(), module_id)
+ module_scope(None, module_id)
}
fn grant(&self, module_id: &str) -> Option<StorageGrant> {
declared(module_id)
@@ -259,7 +259,7 @@ impl Rig {
}
fn scope(&self, module_id: &str) -> Scope {
- module_scope(None, &Scope::local(), module_id).unwrap()
+ module_scope(None, module_id).unwrap()
}
}
diff --git a/crates/openhuman-core/src/modules/storage_host_linked_tests.rs b/crates/openhuman-core/src/modules/storage_host_linked_tests.rs
index bed07f5d44..a3193934ef 100644
--- a/crates/openhuman-core/src/modules/storage_host_linked_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_host_linked_tests.rs
@@ -34,7 +34,7 @@ impl Environment for Env {
Some(Arc::clone(&self.0))
}
fn module_scope(&self, module_id: &str) -> Result<Scope, StorageError> {
- module_scope(None, &Scope::local(), module_id)
+ module_scope(None, module_id)
}
fn grant(&self, module_id: &str) -> Option<StorageGrant> {
super::super::storage_grants::declared(module_id)
diff --git a/crates/openhuman-core/src/profiles/fence.rs b/crates/openhuman-core/src/profiles/fence.rs
index 23f2320892..2245ba708c 100644
--- a/crates/openhuman-core/src/profiles/fence.rs
+++ b/crates/openhuman-core/src/profiles/fence.rs
@@ -7,11 +7,15 @@
//! `storage::open` consults). From then on each write through the storage
//! ports to one of the profile's scopes is checked against the grant:
//!
-//! - the profile's own scope (`storage::scope_for_profile`), where its
-//! domain stores, secrets, cron and flows keep their records;
-//! - every session scope of the profile (`<profile>~<agent>`,
-//! `core::runtime::session_key_prefix`), where the session store keeps
-//! transcripts and turn states.
+//! - the profile's tenant scope (`storage::scope_for_profile`, `u:<id>`),
+//! where its domain stores, secrets, cron and flows keep their records;
+//! - every principal scope under the tenant (`u:<id>/agent:<agent>` and
+//! `u:<id>/module:<module>`), where the session store keeps transcripts and
+//! turn states and modules keep theirs.
+//!
+//! The tenant is the fence boundary: one exact scope plus the prefix
+//! `<tenant>/`, which a hashed segment cannot escape (tsd hashes the segment,
+//! never the whole scope).
//!
//! The heartbeat records each renewal on the fence and latches it when the
//! lease is lost; a write check that finds the record moved on latches it
@@ -47,15 +51,13 @@ pub(crate) fn skew_margin(ttl: Duration) -> u64 {
u64::try_from((ttl / 6).as_millis()).unwrap_or(u64::MAX)
}
-/// The scopes profile `id`'s grant guards.
+/// The scopes profile `id`'s grant guards: its tenant scope and everything
+/// under `<tenant>/`.
pub(crate) fn scopes_of(id: &ProfileId) -> Vec<ScopeMatch> {
+ let tenant = crate::storage::scope_for_profile(id.as_str());
vec![
- ScopeMatch::Exact(
- crate::storage::scope_for_profile(id.as_str())
- .as_str()
- .to_string(),
- ),
- ScopeMatch::Prefix(crate::core::runtime::session_key_prefix(id.as_str())),
+ ScopeMatch::Exact(tenant.as_str().to_string()),
+ ScopeMatch::Prefix(format!("{}/", tenant.as_str())),
]
}