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
style(storage): apply rustfmt to lease code and tests
Steven Enamakelf4a7aefef311
diff --git a/crates/openhuman-core/proptest-regressions/storage/lease_model_tests.txt b/crates/openhuman-core/proptest-regressions/storage/lease_model_tests.txtdeleted file mode 100644index 3cfb3b1a6b..0000000000--- a/crates/openhuman-core/proptest-regressions/storage/lease_model_tests.txt+++ /dev/null@@ -1,7 +0,0 @@-# Seeds for failure cases proptest has generated in the past. It is-# automatically read and these particular cases re-run before any-# novel cases are generated.-#-# It is recommended to check this file in to source control so that-# everyone who runs the test benefits from these saved cases.-cc 7db526ff184e6a4384a8e5154f3f9b487f6545fd3766102792af780b583ee9f0 # shrinks to (nodes, steps) = (2, [Acquire(0), Advance(999), Acquire(1)])diff --git a/crates/openhuman-core/src/storage/lease_documents.rs b/crates/openhuman-core/src/storage/lease_documents.rsindex efc3b1ef88..7c1f32d0e7 100644--- a/crates/openhuman-core/src/storage/lease_documents.rs+++ b/crates/openhuman-core/src/storage/lease_documents.rs@@ -15,8 +15,8 @@ use async_trait::async_trait;use tinystoragedrivers::{CollectionSpec, ErrorKind, Precondition, Scope, Version};use super::lease::{- decide, validate_key, LeaseError, LeaseGrant, LeaseRecord, LeaseStore, Takeover,- CLUSTER_SCOPE, LEASE_COLLECTION,+ decide, validate_key, LeaseError, LeaseGrant, LeaseRecord, LeaseStore, Takeover, CLUSTER_SCOPE,+ LEASE_COLLECTION,};use super::{DocumentStore, StorageBackend, StorageError};@@ -136,9 +136,8 @@ impl DocumentLeases {let Some(stored) = self.docs.get(LEASE_COLLECTION, key).await? else {return Ok(None);};- let record: LeaseRecord = serde_json::from_value(stored.doc).map_err(|error| {- StorageError::serialization(format!("lease record {key}: {error}"))- })?;+ let record: LeaseRecord = serde_json::from_value(stored.doc)+ .map_err(|error| StorageError::serialization(format!("lease record {key}: {error}")))?;Ok(Some((stored.version, record)))}@@ -196,28 +195,29 @@ impl LeaseStore for DocumentLeases {let expires_at_ms = now_ms.saturating_add(self.ttl_ms);for attempt in 0..ACQUIRE_ATTEMPTS {let found = self.read(key).await?;- let (epoch, unclean) =- match decide(found.as_ref().map(|(_, r)| r), &self.node, self.held_epoch(key), now_ms)- {- Takeover::Take { epoch, unclean } => (epoch, unclean),- Takeover::Refuse => {- let (_, record) = found.expect("refuse implies a record");- tracing::debug!(- target: "openhuman::storage::lease",- key,- node = %self.node,- owner = %record.owner,- epoch = record.epoch,- "[lease] acquire refused: held elsewhere"- );- return Err(LeaseError::Held(record));- }- };- let precondition = found- .as_ref()- .map_or(Precondition::Absent, |(version, _)| {- Precondition::Version(*version)- });+ let (epoch, unclean) = match decide(+ found.as_ref().map(|(_, r)| r),+ &self.node,+ self.held_epoch(key),+ now_ms,+ ) {+ Takeover::Take { epoch, unclean } => (epoch, unclean),+ Takeover::Refuse => {+ let (_, record) = found.expect("refuse implies a record");+ tracing::debug!(+ target: "openhuman::storage::lease",+ key,+ node = %self.node,+ owner = %record.owner,+ epoch = record.epoch,+ "[lease] acquire refused: held elsewhere"+ );+ return Err(LeaseError::Held(record));+ }+ };+ let precondition = found.as_ref().map_or(Precondition::Absent, |(version, _)| {+ Precondition::Version(*version)+ });let record = self.record(epoch, expires_at_ms, false);match self.write(key, &record, precondition).await {Ok(version) => {diff --git a/crates/openhuman-core/src/storage/lease_documents_tests.rs b/crates/openhuman-core/src/storage/lease_documents_tests.rsindex 4e51be31ce..7dab21ebea 100644--- a/crates/openhuman-core/src/storage/lease_documents_tests.rs+++ b/crates/openhuman-core/src/storage/lease_documents_tests.rs@@ -52,7 +52,10 @@ async fn renew_extends_and_keeps_the_epoch() {assert_eq!(renewed.epoch, grant.epoch);assert_eq!(renewed.expires_at_ms, 1_900);assert!(renewed.version > grant.version);- assert!(matches!(b.acquire("k", 1_500).await, Err(LeaseError::Held(_))));+ assert!(matches!(+ b.acquire("k", 1_500).await,+ Err(LeaseError::Held(_))+ ));assert!(matches!(a.renew(&grant, 950).await, Err(LeaseError::Lost)),"the superseded grant cannot renew"@@ -108,7 +111,10 @@ async fn bad_keys_and_corrupt_records_are_storage_errors() {).await.unwrap();- assert!(matches!(a.acquire("k", 0).await, Err(LeaseError::Storage(_))));+ assert!(matches!(+ a.acquire("k", 0).await,+ Err(LeaseError::Storage(_))+ ));}#[tokio::test]@@ -164,7 +170,10 @@ fn race_on(url: String, contenders: usize) {fn sqlite_threads_racing_for_a_key_have_one_winner() {for round in 0..5 {let dir = tempfile::tempdir().unwrap();- let url = format!("sqlite:{}", dir.path().join(format!("leases-{round}.db")).display());+ let url = format!(+ "sqlite:{}",+ dir.path().join(format!("leases-{round}.db")).display()+ );race_on(url, 8);}}diff --git a/crates/openhuman-core/src/storage/lease_model_tests.rs b/crates/openhuman-core/src/storage/lease_model_tests.rsindex ec39c61517..efbdd34b61 100644--- a/crates/openhuman-core/src/storage/lease_model_tests.rs+++ b/crates/openhuman-core/src/storage/lease_model_tests.rs@@ -289,7 +289,13 @@ async fn run(nodes: usize, steps: Vec<Op>) -> Result<(), TestCaseError> {prop_assert_eq!(s.expires_at_ms, m.expires_at_ms, "step {}", step);prop_assert_eq!(s.released, m.released, "step {}", step);}- _ => prop_assert!(false, "step {}: stored {:?} vs model {:?}", step, stored, model.rec),+ _ => prop_assert!(+ false,+ "step {}: stored {:?} vs model {:?}",+ step,+ stored,+ model.rec+ ),}}Ok(())diff --git a/crates/openhuman-core/src/storage/lease_tests.rs b/crates/openhuman-core/src/storage/lease_tests.rsindex bc02361b41..a6d2e3650a 100644--- a/crates/openhuman-core/src/storage/lease_tests.rs+++ b/crates/openhuman-core/src/storage/lease_tests.rs@@ -12,7 +12,13 @@ fn record(owner: &str, epoch: u64, expires_at_ms: u64, released: bool) -> LeaseR#[test]fn keys_cannot_escape_a_directory_or_an_id() {- for good in ["user-1", "a", "[email protected]", "x_y.z", &"k".repeat(MAX_KEY_LEN)] {+ for good in [+ "user-1",+ "a",+ "[email protected]",+ "x_y.z",+ &"k".repeat(MAX_KEY_LEN),+ ] {assert!(validate_key(good).is_ok(), "{good}");}let too_long = "k".repeat(MAX_KEY_LEN + 1);