The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(storage): derive storage grants from module schemas
Steven Enamakelb923272aa375
diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rsindex 224a8297f5..87ba3fb89c 100644--- a/crates/openhuman-core/src/modules/mod.rs+++ b/crates/openhuman-core/src/modules/mod.rs@@ -90,17 +90,7 @@ mod search_path;pub(crate) mod site_memory_host;mod source;#[cfg(feature = "modules")]-mod storage_grant_tinybox;-#[cfg(feature = "modules")]-mod storage_grant_tinychannels;-#[cfg(feature = "modules")]-mod storage_grant_tinyconnectors;-#[cfg(feature = "modules")]-mod storage_grant_tinyjuice;-#[cfg(feature = "modules")]-mod storage_grant_tinymcp;-#[cfg(feature = "modules")]-mod storage_grant_tinywallet;+mod storage_grant_schemas;#[cfg(feature = "modules")]pub mod storage_grants;#[cfg(feature = "modules")]diff --git a/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs b/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rsnew file mode 100644index 0000000000..44df41b29e--- /dev/null+++ b/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs@@ -0,0 +1,55 @@+use super::*;+use crate::modules::storage_grants::{authorize, declared, Denied, Object, Plan};+use serde_json::json;++fn allowed(grant: &StorageGrant, object: Object, selector: &str, request: serde_json::Value) -> bool {+ matches!(+ authorize(grant, object, selector, &request),+ Ok(Plan::Forward { .. })+ )+}++#[test]+fn every_row_has_a_valid_generated_grant() {+ for row in &ROWS {+ let grant = declared(row.module).unwrap_or_else(|| panic!("{} declares storage", row.module));+ grant.validate().unwrap_or_else(|why| panic!("{}: {why}", row.module));+ assert!(grant.writable);+ let items = module_items(row.owner);+ assert_eq!(grant.collections.len(), items.collections.len(), "{}", row.module);+ }+ assert!(declared("not-a-module").is_none());+}++#[test]+fn the_registry_ids_exist() {+ for row in &ROWS {+ assert!(+ crate::modules::registry::ALL.iter().any(|record| record.id == row.module)+ || row.module == "tinywallet",+ "{}",+ row.module+ );+ }+}++#[test]+fn tinymcp_reaches_its_v2_collections_stream_and_secrets() {+ let grant = declared("tinymcp").unwrap();+ assert!(allowed(&grant, Object::Documents, "Get", json!({"collection": "mcp.servers", "id": "x"})));+ assert!(allowed(&grant, Object::Streams, "Append", json!({"stream": "mcp.audit"})));+ assert!(allowed(&grant, Object::Secrets, "Get", json!({"name": "mcp_client_env/abc"})));+ assert_eq!(+ authorize(&grant, Object::Documents, "Get", &json!({"collection": "mcp_servers", "id": "x"})).unwrap_err(),+ Denied::Target,+ "the v1 name is no longer granted"+ );+}++#[test]+fn tinyjuice_reaches_only_its_blob_prefix() {+ let grant = declared("tinyjuice").unwrap();+ assert!(grant.collections.is_empty());+ assert!(allowed(&grant, Object::Blobs, "Get", json!({"key": "juice/ccr/abc"})));+ assert!(!allowed(&grant, Object::Blobs, "Get", json!({"key": "other/abc"})));+}diff --git a/crates/openhuman-core/src/modules/storage_grants.rs b/crates/openhuman-core/src/modules/storage_grants.rsindex 3097315048..af5cbc062e 100644--- a/crates/openhuman-core/src/modules/storage_grants.rs+++ b/crates/openhuman-core/src/modules/storage_grants.rs@@ -172,51 +172,15 @@ impl StorageGrant {}}-/// One module's declaration: its registry id and the grant it holds.-type Declaration = (&'static str, fn() -> StorageGrant);-/// The modules whose build declares storage, and what each may use.///-/// A module adds its row here (a declaration is a reviewable build-time-/// decision, like the registry's digests) and then calls-/// `ai.tinyhumans.tinystorage.Storage`; a module with no row has no storage at-/// all. `tinymcp` (v0.18.0 and later) reaches its servers, audit log and-/// environment secrets through this table; so do `tinyconnectors` (v0.18.0:-/// scope preferences and trigger archive), `tinywallet` (v0.22.0: x402 ledger and-/// budget hold), `tinybox` (v0.1.29: box records, jail index) and `tinyjuice`-/// (v0.10.0: CCR blobs).+/// The grant is generated from the module owner's `storage_schema()`+/// (`storage_grant_schemas`), so it cannot drift from what the module+/// declares; a module with no row has no storage at all. Rows: `tinychannels`,+/// `tinymcp`, `tinyconnectors`, `tinywallet`, `tinybox` and `tinyjuice`.#[must_use]pub fn declared(module_id: &str) -> Option<StorageGrant> {- let table: &[Declaration] = &[- (- super::storage_grant_tinychannels::MODULE_ID,- super::storage_grant_tinychannels::grant,- ),- (- super::storage_grant_tinymcp::MODULE_ID,- super::storage_grant_tinymcp::grant,- ),- (- super::storage_grant_tinyconnectors::MODULE_ID,- super::storage_grant_tinyconnectors::grant,- ),- (- super::storage_grant_tinywallet::MODULE_ID,- super::storage_grant_tinywallet::grant,- ),- (- super::storage_grant_tinybox::MODULE_ID,- super::storage_grant_tinybox::grant,- ),- (- super::storage_grant_tinyjuice::MODULE_ID,- super::storage_grant_tinyjuice::grant,- ),- ];- table- .iter()- .find(|(id, _)| *id == module_id)- .map(|(_, grant)| grant())+ super::storage_grant_schemas::grant_for(module_id)}fn text<'a>(request: &'a Value, field: &str) -> Result<&'a str, Denied> {