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
feat(storage): add lease storage schema tests
Steven Enamakel20c967cb55af
diff --git a/crates/openhuman-core/src/profiles/storage_schema_tests.rs b/crates/openhuman-core/src/profiles/storage_schema_tests.rsindex 73297ec0ad..e4e025465f 100644--- a/crates/openhuman-core/src/profiles/storage_schema_tests.rs+++ b/crates/openhuman-core/src/profiles/storage_schema_tests.rs@@ -53,3 +53,58 @@ async fn migrate_cluster_moves_the_v1_registry_into_the_v2_collection() {fn the_schema_composes_under_its_owner() {tinystoragedrivers::schema::Registry::compose([storage_schema()]).unwrap();}++#[tokio::test]+async fn migrate_cluster_moves_v1_leases_into_tsd_leases_and_keeps_their_epoch() {+ use crate::storage::lease::{DocumentLeases, LeaseStore, LEASE_OWNER};+ let backend = MemoryStorage::new();+ let scoped = backend.for_scope(&Scope::cluster()).unwrap();+ let docs = scoped.documents();+ docs.ensure_collection(&CollectionSpec::new("leases"))+ .await+ .unwrap();+ docs.put(+ "leases",+ "alice",+ json!({ "owner": "node-a", "endpoint": "http://a", "epoch": 4,+ "expires_at_ms": 5_000, "released": false }),+ Precondition::Absent,+ )+ .await+ .unwrap();+ docs.put(+ "leases",+ "bob",+ json!({ "owner": "node-a", "endpoint": null, "epoch": 2,+ "expires_at_ms": 1_000, "released": true }),+ Precondition::Absent,+ )+ .await+ .unwrap();+ migrate_cluster(&scoped).await.unwrap();+ migrate_cluster(&scoped).await.unwrap();+ assert!(!docs+ .collections("")+ .await+ .unwrap()+ .iter()+ .any(|name| name == "leases"));+ let id = tinystoragedrivers::Key::of([LEASE_OWNER, "alice"]).unwrap();+ let moved = docs.get("tsd.leases", id.as_str()).await.unwrap().unwrap();+ assert_eq!(+ moved.doc,+ json!({ "holder": "node-a", "epoch": 4, "expires_ms": 5_000, "endpoint": "http://a" })+ );++ // The host's lease store reads the moved records: alice is still held,+ // bob's released record is taken over cleanly at the next epoch.+ let b = DocumentLeases::cluster(&backend, "node-b", None, std::time::Duration::from_secs(1))+ .unwrap();+ let held = b.holder("alice").await.unwrap().unwrap();+ assert_eq!((held.owner.as_str(), held.epoch), ("node-a", 4));+ assert!(b.acquire("alice", 1_000).await.is_err());+ let taken = b.acquire("bob", 2_000).await.unwrap();+ assert_eq!((taken.epoch, taken.previous_unclean), (3, false));+ let after = b.acquire("alice", 5_000).await.unwrap();+ assert_eq!((after.epoch, after.previous_unclean), (5, true));+}diff --git a/crates/openhuman-core/src/storage/lease.rs b/crates/openhuman-core/src/storage/lease.rsindex f4f25a36d2..2af435c03f 100644--- a/crates/openhuman-core/src/storage/lease.rs+++ b/crates/openhuman-core/src/storage/lease.rs@@ -55,7 +55,7 @@ use serde::{Deserialize, Serialize};use super::StorageError;-pub use super::lease_documents::DocumentLeases;+pub use super::lease_documents::{DocumentLeases, LEASE_OWNER};pub use super::lease_local::LocalLeases;/// The storage scope lease records live under, shared by every node.