Skip to content

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

style: apply rustfmt formatting across storage and runtime modules

Steven Enamakelf5668e20c482
diff --git a/crates/openhuman-core/src/core/runtime/mod.rs b/crates/openhuman-core/src/core/runtime/mod.rs
index 16c52fab4d..45e471a611 100644
--- a/crates/openhuman-core/src/core/runtime/mod.rs
+++ b/crates/openhuman-core/src/core/runtime/mod.rs
@@ -62,6 +62,4 @@ pub use context::{ContextOverlay, CoreContext};
pub use mode::{current_mode, is_saas, Mode};
pub use saas::SaasConfig;
pub use spawn::{spawn_blocking_scoped, spawn_scoped};
-pub use tenant::{
- current_tenant, session_key, session_key_prefix, tenant_key, NoTenant, Tenant,
-};
+pub use tenant::{current_tenant, session_key, session_key_prefix, tenant_key, NoTenant, Tenant};
diff --git a/crates/openhuman-core/src/profiles/fence_tests.rs b/crates/openhuman-core/src/profiles/fence_tests.rs
index 7697706bb9..0e86289af5 100644
--- a/crates/openhuman-core/src/profiles/fence_tests.rs
+++ b/crates/openhuman-core/src/profiles/fence_tests.rs
@@ -58,17 +58,21 @@ fn the_margin_is_a_sixth_of_the_ttl() {
fn a_profiles_fence_covers_its_scope_and_its_sessions() {
let id = profile("alice");
let scopes = scopes_of(&id);
- let covers = |s: &str| scopes.iter().any(|m| match m {
- ScopeMatch::Exact(e) => e == s,
- ScopeMatch::Prefix(p) => s.starts_with(p.as_str()),
- });
+ let covers = |s: &str| {
+ scopes.iter().any(|m| match m {
+ ScopeMatch::Exact(e) => e == s,
+ ScopeMatch::Prefix(p) => s.starts_with(p.as_str()),
+ })
+ };
assert!(covers(crate::storage::scope_for_profile("alice").as_str()));
let tenant = crate::core::runtime::Tenant {
profile: Some("alice".into()),
agent: None,
};
assert!(covers(&crate::core::runtime::session_key(&tenant)));
- assert!(!covers(crate::storage::scope_for_profile("alice2").as_str()));
+ assert!(!covers(
+ crate::storage::scope_for_profile("alice2").as_str()
+ ));
}
#[tokio::test]
@@ -149,11 +153,16 @@ async fn background_jobs_are_not_started_for_a_superseded_profile() {
let alice = profile("alice");
a.provision(&alice).await.unwrap();
let state = a.open(&alice).await.unwrap();
- DocumentLeases::cluster(backend.as_ref(), "node-b", None, Duration::from_secs(TTL_SECS))
- .unwrap()
- .acquire(alice.as_str(), now_ms() + 2 * TTL_SECS * 1_000)
- .await
- .unwrap();
+ DocumentLeases::cluster(
+ backend.as_ref(),
+ "node-b",
+ None,
+ Duration::from_secs(TTL_SECS),
+ )
+ .unwrap()
+ .acquire(alice.as_str(), now_ms() + 2 * TTL_SECS * 1_000)
+ .await
+ .unwrap();
// The check the background loop runs before a profile's jobs.
assert!(state.lease_fence().check(now_ms()).await.is_err());
tokio::time::timeout(Duration::from_secs(1), state.lease_fence().fenced())
diff --git a/crates/openhuman-core/src/storage/fence_tests.rs b/crates/openhuman-core/src/storage/fence_tests.rs
index fb1b3d137b..094730a71b 100644
--- a/crates/openhuman-core/src/storage/fence_tests.rs
+++ b/crates/openhuman-core/src/storage/fence_tests.rs
@@ -102,7 +102,10 @@ async fn a_released_or_missing_record_supersedes_the_fence() {
a.release(grant.clone()).await.unwrap();
assert!(matches!(
f.check(1).await,
- Err(FenceError::Superseded { stored: Some(1), .. })
+ Err(FenceError::Superseded {
+ stored: Some(1),
+ ..
+ })
));
let other = LeaseFence::new(Arc::clone(&a), "nobody", "node-a", 1, u64::MAX, 0, scopes());
@@ -144,7 +147,15 @@ impl LeaseStore for Unreachable {
#[tokio::test]
async fn an_unreadable_record_refuses_the_write_without_latching() {
- let f = LeaseFence::new(Arc::new(Unreachable), "alice", "a", 1, u64::MAX, 0, scopes());
+ let f = LeaseFence::new(
+ Arc::new(Unreachable),
+ "alice",
+ "a",
+ 1,
+ u64::MAX,
+ 0,
+ scopes(),
+ );
assert!(matches!(f.check(1).await, Err(FenceError::Unverified(_))));
assert!(!f.is_fenced(), "a storage hiccup is not a lost lease");
}
@@ -213,8 +224,6 @@ async fn the_guard_passes_unfenced_scopes_and_refuses_with_a_typed_error() {
let refused = registry.guard("profile:alice", "test").await.unwrap_err();
assert_eq!(
fence_error(&refused),
- Some(&FenceError::Expired {
- epoch: grant.epoch
- })
+ Some(&FenceError::Expired { epoch: grant.epoch })
);
}
diff --git a/crates/openhuman-core/src/storage/fenced_backend_tests.rs b/crates/openhuman-core/src/storage/fenced_backend_tests.rs
index ebd4e4600a..3d8ea4cb06 100644
--- a/crates/openhuman-core/src/storage/fenced_backend_tests.rs
+++ b/crates/openhuman-core/src/storage/fenced_backend_tests.rs
@@ -97,7 +97,10 @@ async fn a_node_that_lost_the_lease_cannot_write_and_the_new_holder_can() {
let refused = a.put("profile:alice", "n2").await.unwrap_err();
assert!(matches!(
fence_error(&refused),
- Some(FenceError::Superseded { held: 1, stored: Some(2) })
+ Some(FenceError::Superseded {
+ held: 1,
+ stored: Some(2)
+ })
));
// Every write port, and every session scope of the profile, is fenced.
let session = a.scoped("alice~default");
@@ -109,7 +112,12 @@ async fn a_node_that_lost_the_lease_cannot_write_and_the_new_holder_can() {
.await
.is_err());
// Reads are not.
- assert!(session.documents().get("notes", "n1").await.unwrap().is_some());
+ assert!(session
+ .documents()
+ .get("notes", "n1")
+ .await
+ .unwrap()
+ .is_some());
// Other profiles' scopes are untouched.
a.put("profile:bob", "n1").await.unwrap();
diff --git a/crates/openhuman-core/src/storage/lease.rs b/crates/openhuman-core/src/storage/lease.rs
index e7b1a548e4..26c0e26055 100644
--- a/crates/openhuman-core/src/storage/lease.rs
+++ b/crates/openhuman-core/src/storage/lease.rs
@@ -25,8 +25,8 @@
//! stop the previous holder: resources a lease protects must reject writes
//! carrying an epoch below the current one, and a holder must stop work
//! before `expires_at_ms` minus the maximum clock skew between nodes (each
-//! node supplies its own `now_ms`). Nothing in this module checks epochs at
-//! the protected resource. An epoch at `u64::MAX` cannot be advanced, so a
+//! node supplies its own `now_ms`). This module does not check epochs at
+//! the protected resource; [`super::fence`] does, for storage-port writes. An epoch at `u64::MAX` cannot be advanced, so a
//! takeover of it fails with a storage error instead of repeating it.
//! - **renew** extends a grant by compare-and-swap on the version it holds.
//! Any write since (a takeover, a release) makes it [`LeaseError::Lost`].
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index 269372d501..dac45cb3c8 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -106,7 +106,9 @@ pub async fn open(url: &str) -> Result<Arc<dyn StorageBackend>, StorageError> {
);
// Every opened backend checks the process's lease fences on write; with
// no fence registered (every single-user host) that is a pass-through.
- Ok(fenced_backend::wrap(tinystoragedrivers::open(&parsed).await?))
+ Ok(fenced_backend::wrap(
+ tinystoragedrivers::open(&parsed).await?,
+ ))
}
/// Makes `backend` the process's storage backend; returns the previous one.