Skip to content

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

feat(storage): add queue-backed storage grant and host operations

Steven Enamakelc4022bbaa080
diff --git a/crates/openhuman-core/src/modules/storage_grants.rs b/crates/openhuman-core/src/modules/storage_grants.rs
index f9a7d54164..df85c26bf6 100644
--- a/crates/openhuman-core/src/modules/storage_grants.rs
+++ b/crates/openhuman-core/src/modules/storage_grants.rs
@@ -257,10 +257,10 @@ pub(crate) fn authorize(
// module with no queue grant still connects: it learns it has no features
// and every other `Queues` selector is refused below.
if object == Object::Queues && selector == "Features" && !grant.has_object(object) {
- return Ok(Plan::Answer(serde_json::to_value(
- tinystoragedrivers_bus::QueueFeaturesReply::default(),
- )
- .map_err(|_| Denied::Malformed)?));
+ return Ok(Plan::Answer(
+ serde_json::to_value(tinystoragedrivers_bus::QueueFeaturesReply::default())
+ .map_err(|_| Denied::Malformed)?,
+ ));
}
if !grant.has_object(object) {
return Err(Denied::Object);
diff --git a/crates/openhuman-core/src/modules/storage_grants_queues_tests.rs b/crates/openhuman-core/src/modules/storage_grants_queues_tests.rs
index a4d54da810..c27128b5b3 100644
--- a/crates/openhuman-core/src/modules/storage_grants_queues_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_grants_queues_tests.rs
@@ -71,7 +71,12 @@ fn a_queue_call_without_a_queue_name_is_malformed() {
Err(Denied::Malformed)
);
assert_eq!(
- authorize(&with_queues(), Object::Queues, "Pop", &json!({"queue": "inbox"})),
+ authorize(
+ &with_queues(),
+ Object::Queues,
+ "Pop",
+ &json!({"queue": "inbox"})
+ ),
Err(Denied::Malformed)
);
}
@@ -123,13 +128,24 @@ fn a_read_only_grant_may_inspect_queues_but_not_lease_or_enqueue() {
};
for selector in ["Stats", "DeadLetters"] {
assert!(
- authorize(&read_only, Object::Queues, selector, &json!({"queue": "inbox"})).is_ok(),
+ authorize(
+ &read_only,
+ Object::Queues,
+ selector,
+ &json!({"queue": "inbox"})
+ )
+ .is_ok(),
"{selector}"
);
}
for selector in ["Receive", "Enqueue", "Ack", "Redrive", "Purge"] {
assert_eq!(
- authorize(&read_only, Object::Queues, selector, &json!({"queue": "inbox"})),
+ authorize(
+ &read_only,
+ Object::Queues,
+ selector,
+ &json!({"queue": "inbox"})
+ ),
Err(Denied::ReadOnly),
"{selector}"
);
diff --git a/crates/openhuman-core/src/modules/storage_host.rs b/crates/openhuman-core/src/modules/storage_host.rs
index 0f14811d03..cb6939173b 100644
--- a/crates/openhuman-core/src/modules/storage_host.rs
+++ b/crates/openhuman-core/src/modules/storage_host.rs
@@ -417,15 +417,17 @@ impl StorageHost {
// The queue port of a document backend keeps its messages in the
// storage layer's own collections; declare them on this scope
// before the server takes its first `Queues` call.
- tinystoragedrivers::queue::ensure(&storage).await.map_err(|error| {
- tracing::warn!(
- target: "openhuman::storage_host",
- module,
- %error,
- "[storage_host] could not declare the queue collections"
- );
- BindError::Backend(StorageKind::Backend)
- })?;
+ tinystoragedrivers::queue::ensure(&storage)
+ .await
+ .map_err(|error| {
+ tracing::warn!(
+ target: "openhuman::storage_host",
+ module,
+ %error,
+ "[storage_host] could not declare the queue collections"
+ );
+ BindError::Backend(StorageKind::Backend)
+ })?;
tracing::debug!(
target: "openhuman::storage_host",
module,
diff --git a/crates/openhuman-core/src/modules/storage_host_queues_tests.rs b/crates/openhuman-core/src/modules/storage_host_queues_tests.rs
index 6424f3322e..fad02b2e28 100644
--- a/crates/openhuman-core/src/modules/storage_host_queues_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_host_queues_tests.rs
@@ -33,7 +33,11 @@ struct Peers {
async fn peers() -> Peers {
let bus = MemoryBus::new();
Broker::new().spawn(bus.clone());
- let connect = || async { Connection::connect(bus.connect().await.unwrap()).await.unwrap() };
+ let connect = || async {
+ Connection::connect(bus.connect().await.unwrap())
+ .await
+ .unwrap()
+ };
let service = connect().await;
let queued = connect().await;
let plain = connect().await;
@@ -49,8 +53,14 @@ async fn peers() -> Peers {
keys_ready: AtomicBool::new(true),
});
let directory = Directory(HashMap::from([
- (queued.unique_name().unwrap().as_str().to_string(), "alpha".to_string()),
- (plain.unique_name().unwrap().as_str().to_string(), "beta".to_string()),
+ (
+ queued.unique_name().unwrap().as_str().to_string(),
+ "alpha".to_string(),
+ ),
+ (
+ plain.unique_name().unwrap().as_str().to_string(),
+ "beta".to_string(),
+ ),
]));
let host = Arc::new(StorageHost::new(
Arc::new(directory),
@@ -137,8 +147,5 @@ async fn a_module_without_a_queue_grant_connects_but_is_denied_queues() {
.enqueue("inbox", &[NewMessage::new(json!({}))])
.await
.unwrap_err();
- assert!(
- error.to_string().contains("object-not-granted"),
- "{error}"
- );
+ assert!(error.to_string().contains("object-not-granted"), "{error}");
}