Skip to content

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

test(storage): pin the doctor's holder_readonly branches for both lease stores

M3gA-Mind0ba5600e5eac
diff --git a/crates/openhuman-core/src/storage/lease_documents_tests.rs b/crates/openhuman-core/src/storage/lease_documents_tests.rs
index a47b8dc0ad..d9341ec3c0 100644
--- a/crates/openhuman-core/src/storage/lease_documents_tests.rs
+++ b/crates/openhuman-core/src/storage/lease_documents_tests.rs
@@ -216,3 +216,40 @@ async fn concurrent_renewals_of_one_grant_have_one_winner() {
// The heartbeat's next renewal, from the grant the winner returned, holds.
assert!(a.holder("k").await.unwrap().unwrap().is_live(150));
}
+
+#[tokio::test]
+async fn doctor_inspection_refuses_a_legacy_leases_collection() {
+ // Only the pre-rename `leases` collection exists: its records are not
+ // read as "no holder", the doctor is told a migration is needed.
+ let storage = memory_backend();
+ let leases = DocumentLeases::cluster(storage.as_ref(), "d", None, TTL).unwrap();
+ storage
+ .for_scope(&Scope::new(CLUSTER_SCOPE).unwrap())
+ .unwrap()
+ .documents()
+ .ensure_collection(&CollectionSpec::new("leases"))
+ .await
+ .unwrap();
+
+ let error = leases.holder_readonly("alice").await.unwrap_err();
+ assert!(
+ error.to_string().contains("explicit storage migration"),
+ "{error}"
+ );
+}
+
+#[tokio::test]
+async fn doctor_inspection_reports_a_live_foreign_holder() {
+ let storage = crate::storage::test_support::sqlite_backend().unwrap();
+ let grant = node(&storage, "a").acquire("alice", 0).await.unwrap();
+
+ let record = node(&storage, "d")
+ .holder_readonly("alice")
+ .await
+ .unwrap()
+ .expect("the live holder's record");
+ assert_eq!(record.owner, "a");
+ assert_eq!(record.epoch, grant.epoch);
+ assert!(record.is_live(500), "inside its TTL the holder is live");
+ assert!(!record.is_live(1_000), "at its deadline it no longer is");
+}
diff --git a/crates/openhuman-core/src/storage/lease_local_tests.rs b/crates/openhuman-core/src/storage/lease_local_tests.rs
index 7d026226ab..eb49b62e5d 100644
--- a/crates/openhuman-core/src/storage/lease_local_tests.rs
+++ b/crates/openhuman-core/src/storage/lease_local_tests.rs
@@ -34,6 +34,40 @@ async fn doctor_holder_inspection_does_not_create_a_lock_file() {
);
}
+#[tokio::test]
+async fn doctor_inspection_sees_a_live_holder_as_live_and_a_dead_one_as_not() {
+ let dir = tempfile::tempdir().unwrap();
+ let a = LocalLeases::new(dir.path(), "a");
+ let doctor = LocalLeases::new(dir.path(), "doctor");
+ let grant = a.acquire("k", 0).await.unwrap();
+
+ let live = doctor.holder_readonly("k").await.unwrap().unwrap();
+ assert_eq!(live.owner, "a");
+ assert!(live.is_live(0), "a held lock is a live holder");
+
+ // The lock is free again but the record says "not released": its holder
+ // died, so the record no longer excludes anyone.
+ a.release(grant).await.unwrap();
+ fs::write(
+ local_dir(dir.path(), "k").join(RECORD_FILE),
+ serde_json::to_vec(&LeaseRecord {
+ owner: "a".into(),
+ endpoint: None,
+ epoch: 1,
+ expires_at_ms: u64::MAX,
+ released: false,
+ })
+ .unwrap(),
+ )
+ .unwrap();
+ let dead = doctor.holder_readonly("k").await.unwrap().unwrap();
+ assert_eq!(dead.owner, "a");
+ assert!(
+ !dead.is_live(0),
+ "a free lock under an unreleased record is dead"
+ );
+}
+
#[tokio::test]
async fn a_second_instance_on_one_root_is_held_out() {
let dir = tempfile::tempdir().unwrap();