Skip to content

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

test(storage): run fence tests against the sqlite backend

Steven Enamakel33317cf49050
diff --git a/crates/openhuman-core/src/security/secret_storage/ops_adoption_tests.rs b/crates/openhuman-core/src/security/secret_storage/ops_adoption_tests.rs
index d5d5647f01..283bd8ad29 100644
--- a/crates/openhuman-core/src/security/secret_storage/ops_adoption_tests.rs
+++ b/crates/openhuman-core/src/security/secret_storage/ops_adoption_tests.rs
@@ -9,7 +9,7 @@ use zeroize::Zeroizing;
use crate::security::secret_storage::backend::MockBackend;
use crate::security::secret_storage::SecretBackend;
-use crate::storage::{MemoryStorage, Scope, StorageBackend};
+use crate::storage::{test_support::memory_backend, Scope, StorageBackend};
#[test]
fn encrypted_file_is_unavailable_without_an_initialized_master_key() {
@@ -33,7 +33,7 @@ fn encrypted_file_is_unavailable_without_an_initialized_master_key() {
}
fn storage_secrets_in(
- storage: &MemoryStorage,
+ storage: &dyn StorageBackend,
scope: &str,
) -> tinystoragedrivers::secrets::DocumentSecrets {
let owner_scope = Scope::new(scope).unwrap();
@@ -48,7 +48,7 @@ fn storage_secrets_in(
fn an_os_keyring_secret_is_adopted_into_storage_on_first_read() {
let os = MockBackend::new();
os.set("alice:token", "from-the-os-keychain").unwrap();
- let storage = MemoryStorage::new();
+ let storage = memory_backend();
let secrets = storage_secrets_in(&storage, "local");
let read = |secrets| {
@@ -75,7 +75,7 @@ fn an_os_keyring_secret_is_adopted_into_storage_on_first_read() {
#[test]
fn a_secret_absent_everywhere_stays_absent_and_storage_wins_over_the_os() {
let os = MockBackend::new();
- let storage = MemoryStorage::new();
+ let storage = memory_backend();
let secrets = storage_secrets_in(&storage, "local");
assert_eq!(
get_adopting(secrets.clone(), "bob:k", "k", || os
@@ -101,7 +101,7 @@ fn a_secret_absent_everywhere_stays_absent_and_storage_wins_over_the_os() {
fn adopted_secrets_do_not_cross_scopes() {
let os = MockBackend::new();
os.set("u:k", "v").unwrap();
- let storage = MemoryStorage::new();
+ let storage = memory_backend();
get_adopting(storage_secrets_in(&storage, "alice"), "u:k", "k", || {
os.get("u:k").ok().flatten()
})
@@ -121,7 +121,7 @@ fn a_failing_legacy_backend_reads_as_nothing_to_adopt() {
);
assert_eq!(legacy_or_warn(Ok(Some("v".into()))).as_deref(), Some("v"));
// With nothing legacy to adopt, the storage read is still answered.
- let storage = MemoryStorage::new();
+ let storage = memory_backend();
let secrets = storage_secrets_in(&storage, "local");
let read = get_adopting(secrets, "alice:k", "k", || {
legacy_or_warn(Err(SecretStorageError::Backend("locked".into())))
diff --git a/crates/openhuman-core/src/storage/fence_tests.rs b/crates/openhuman-core/src/storage/fence_tests.rs
index 235d4571ca..f630a54e02 100644
--- a/crates/openhuman-core/src/storage/fence_tests.rs
+++ b/crates/openhuman-core/src/storage/fence_tests.rs
@@ -1,12 +1,14 @@
+#![cfg(feature = "storage-sqlite")]
+
use super::*;
-use crate::storage::MemoryStorage;
+use crate::storage::test_support::SqliteBackend;
use crate::storage::lease::{DocumentLeases, LeaseError, LeaseGrant, LeaseRecord};
use std::time::Duration;
const TTL: Duration = Duration::from_secs(30);
-fn leases(backend: &MemoryStorage, node: &str) -> Arc<dyn LeaseStore> {
- Arc::new(DocumentLeases::cluster(backend, node, None, TTL).unwrap())
+fn leases(backend: &SqliteBackend, node: &str) -> Arc<dyn LeaseStore> {
+ Arc::new(DocumentLeases::cluster(backend.backend.as_ref(), node, None, TTL).unwrap())
}
fn scopes() -> Vec<ScopeMatch> {
@@ -30,11 +32,11 @@ fn fence(store: Arc<dyn LeaseStore>, node: &str, grant: &LeaseGrant, margin: u64
#[test]
fn a_fence_covers_its_exact_scope_and_prefix_only() {
- let backend = MemoryStorage::new();
+ let backend = crate::storage::test_support::sqlite_backend().unwrap();
let grant = LeaseGrant {
key: "alice".into(),
epoch: 1,
- version: tinystoragedrivers::Version(1),
+ version: tinystoragedrivers_types::Version(1),
expires_at_ms: 1_000,
previous_unclean: false,
};
@@ -49,11 +51,11 @@ fn a_fence_covers_its_exact_scope_and_prefix_only() {
#[test]
fn the_local_check_refuses_inside_the_skew_margin_and_after_renewal_admits_again() {
- let backend = MemoryStorage::new();
+ let backend = crate::storage::test_support::sqlite_backend().unwrap();
let grant = LeaseGrant {
key: "alice".into(),
epoch: 3,
- version: tinystoragedrivers::Version(1),
+ version: tinystoragedrivers_types::Version(1),
expires_at_ms: 30_000,
previous_unclean: false,
};
@@ -68,7 +70,7 @@ fn the_local_check_refuses_inside_the_skew_margin_and_after_renewal_admits_again
#[tokio::test]
async fn the_full_check_follows_the_stored_record_and_latches_on_takeover() {
- let backend = MemoryStorage::new();
+ let backend = crate::storage::test_support::sqlite_backend().unwrap();
let a = leases(&backend, "node-a");
let grant = a.acquire("alice", 0).await.unwrap();
let f = fence(Arc::clone(&a), "node-a", &grant, 0);
@@ -95,7 +97,7 @@ async fn the_full_check_follows_the_stored_record_and_latches_on_takeover() {
#[tokio::test]
async fn a_released_or_missing_record_supersedes_the_fence() {
- let backend = MemoryStorage::new();
+ let backend = crate::storage::test_support::sqlite_backend().unwrap();
let a = leases(&backend, "node-a");
let grant = a.acquire("alice", 0).await.unwrap();
let f = fence(Arc::clone(&a), "node-a", &grant, 0);
@@ -171,7 +173,7 @@ fn a_refusal_survives_the_trip_through_a_port_error() {
#[test]
fn the_registry_replaces_retires_and_prunes_dead_tombstones() {
- let backend = MemoryStorage::new();
+ let backend = crate::storage::test_support::sqlite_backend().unwrap();
let store = leases(&backend, "a");
let registry = FenceRegistry::new(|| 0);
let make = |epoch| {
@@ -219,7 +221,7 @@ fn the_registry_replaces_retires_and_prunes_dead_tombstones() {
#[test]
fn registration_prunes_a_dead_anchored_fence_before_comparing_epochs() {
- let backend = MemoryStorage::new();
+ let backend = crate::storage::test_support::sqlite_backend().unwrap();
let store = leases(&backend, "a");
let registry = FenceRegistry::new(|| 0);
let make = |epoch| {
@@ -246,7 +248,7 @@ fn registration_prunes_a_dead_anchored_fence_before_comparing_epochs() {
#[test]
fn registration_preserves_a_live_or_unanchored_higher_epoch_fence() {
- let backend = MemoryStorage::new();
+ let backend = crate::storage::test_support::sqlite_backend().unwrap();
let store = leases(&backend, "a");
let registry = FenceRegistry::new(|| 0);
let make = |epoch| {