Skip to content

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

test(storage): gate sqlite-dependent tests behind feature flags

Steven Enamakel355b5bbc1aa4
diff --git a/crates/openhuman-core/src/storage/import/schemas_tests.rs b/crates/openhuman-core/src/storage/import/schemas_tests.rs
index ca8b77da53..c40b9ebe81 100644
--- a/crates/openhuman-core/src/storage/import/schemas_tests.rs
+++ b/crates/openhuman-core/src/storage/import/schemas_tests.rs
@@ -88,6 +88,7 @@ async fn run_import(workspace: Option<&std::path::Path>) -> Value {
}
#[tokio::test]
+#[cfg(feature = "storage-sqlite")]
async fn a_real_run_on_an_empty_configured_workspace_reports_each_domain() {
let result = run_import(None).await;
assert_eq!(result["dry_run"], Value::Bool(false), "{result:#}");
@@ -96,6 +97,7 @@ async fn a_real_run_on_an_empty_configured_workspace_reports_each_domain() {
}
#[tokio::test]
+#[cfg(feature = "storage-sqlite")]
async fn a_real_run_on_an_overridden_workspace_opens_that_workspaces_backend() {
let other = tempfile::TempDir::new().unwrap();
let result = run_import(Some(other.path())).await;
diff --git a/crates/openhuman-core/src/storage/import_state_tests.rs b/crates/openhuman-core/src/storage/import_state_tests.rs
index e842e19eab..f88d99a584 100644
--- a/crates/openhuman-core/src/storage/import_state_tests.rs
+++ b/crates/openhuman-core/src/storage/import_state_tests.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::storage::{Scope, StorageBackend};
-use std::sync::Arc;
use std::sync::mpsc;
+use std::sync::Arc;
use tinystoragedrivers::CollectionSpec;
use tinystoragedrivers_testkit::MemoryBackend;
@@ -199,11 +199,10 @@ fn a_legacy_marker_row_is_honoured_and_removed() {
.await?
);
assert!(!done(&owned, "storage", &step_id("storage_import", "other@x")).await?);
- assert!(
- docs.query_all("storage_import", &tinystoragedrivers::Query::all())
- .await?
- .is_empty()
- );
+ assert!(docs
+ .query_all("storage_import", &tinystoragedrivers::Query::all())
+ .await?
+ .is_empty());
assert_eq!(migrate_legacy_markers(&owned).await?, 0);
assert!(
done(
@@ -240,8 +239,9 @@ fn a_waiting_process_runs_once_the_holder_releases() {
}
#[test]
+#[cfg(feature = "storage-sqlite")]
fn a_long_import_keeps_its_claim_alive() {
- let repo = repo();
+ let (_dir, _backend, repo) = sqlite_repo();
let now = chrono::Utc::now().timestamp_millis();
let rival_repo = repo.clone();
let rival_ran = with_claim_at(&repo, OWNER, "m", now, 90, |_| {
diff --git a/crates/openhuman-core/src/storage/mod_tests.rs b/crates/openhuman-core/src/storage/mod_tests.rs
index def9e8e444..dde6bdb1ac 100644
--- a/crates/openhuman-core/src/storage/mod_tests.rs
+++ b/crates/openhuman-core/src/storage/mod_tests.rs
@@ -84,8 +84,13 @@ async fn opens_memory_and_refuses_garbage() {
block_on(async move {
docs.ensure_collection(&CollectionSpec::new("probe"))
.await?;
- docs.put("probe", "opened", serde_json::json!({"ok": true}), Precondition::Absent)
- .await?;
+ docs.put(
+ "probe",
+ "opened",
+ serde_json::json!({"ok": true}),
+ Precondition::Absent,
+ )
+ .await?;
assert_eq!(docs.get("probe", "opened").await?.unwrap().doc["ok"], true);
Ok(())
})
@@ -101,14 +106,10 @@ fn install_installed_and_clear() {
assert!(slot.installed().is_none());
let backend = test_support::memory_backend();
assert!(slot.install(Arc::clone(&backend)).is_none());
- assert!(
- slot.installed()
- .is_some_and(|got| Arc::ptr_eq(&got, &backend))
- );
- assert!(
- slot.install(test_support::memory_backend())
- .is_some()
- );
+ assert!(slot
+ .installed()
+ .is_some_and(|got| Arc::ptr_eq(&got, &backend)));
+ assert!(slot.install(test_support::memory_backend()).is_some());
assert!(slot.clear());
assert!(!slot.clear());
}
@@ -116,11 +117,9 @@ fn install_installed_and_clear() {
#[test]
fn agent_scopes_sit_under_the_local_tenant() {
assert_eq!(scope_for_agent("agent-7").as_str(), "local/agent:agent-7");
- assert!(
- scope_for_agent("has a space")
- .as_str()
- .starts_with("local/agent:~")
- );
+ assert!(scope_for_agent("has a space")
+ .as_str()
+ .starts_with("local/agent:~"));
}
#[test]
@@ -158,11 +157,9 @@ fn a_profile_scopes_storage_over_its_agents() {
let odd = scope_for_profile("has a space");
assert!(odd.as_str().starts_with("u:~"), "{odd}");
assert_ne!(odd, scope_for_profile("has a space"));
- assert!(
- scope_for_profile(&"x".repeat(400))
- .as_str()
- .starts_with("u:~")
- );
+ assert!(scope_for_profile(&"x".repeat(400))
+ .as_str()
+ .starts_with("u:~"));
}
#[test]
@@ -236,12 +233,19 @@ fn only_mongodb_and_sqlite_have_cross_process_cas() {
}
#[tokio::test]
+#[cfg(all(feature = "storage-sqlite", feature = "storage-file"))]
async fn local_drivers_do_not_claim_cross_process_cas() {
let dir = tempfile::tempdir().unwrap();
for (url, expected) in [
("memory".to_string(), false),
- (format!("sqlite:{}", dir.path().join("cas.db").display()), true),
- (format!("file:{}", dir.path().join("files").display()), false),
+ (
+ format!("sqlite:{}", dir.path().join("cas.db").display()),
+ true,
+ ),
+ (
+ format!("file:{}", dir.path().join("files").display()),
+ false,
+ ),
] {
let backend = open(&url).await.unwrap();
assert!(
diff --git a/crates/openhuman-core/src/storage/scope_move_tests.rs b/crates/openhuman-core/src/storage/scope_move_tests.rs
index c2a9ca9030..ded75d4866 100644
--- a/crates/openhuman-core/src/storage/scope_move_tests.rs
+++ b/crates/openhuman-core/src/storage/scope_move_tests.rs
@@ -130,7 +130,8 @@ async fn a_v1_scope_moves_its_documents_streams_and_blobs() {
#[tokio::test]
#[cfg(feature = "legacy-import")]
async fn canonical_cluster_scope_import_converts_profiles_and_leases_in_place() {
- let backend: Arc<dyn StorageBackend> = Arc::new(MemoryBackend::new());
+ let fixture = crate::storage::test_support::sqlite_backend().unwrap();
+ let backend = Arc::clone(&fixture.backend);
let inventory = crate::storage::import::scope_move::LegacyScopeInventory {
scopes: vec!["cluster".into()],
documents: vec![
diff --git a/crates/openhuman-core/src/storage/sessions/mod_tests.rs b/crates/openhuman-core/src/storage/sessions/mod_tests.rs
index aa14feb24a..ce9884a959 100644
--- a/crates/openhuman-core/src/storage/sessions/mod_tests.rs
+++ b/crates/openhuman-core/src/storage/sessions/mod_tests.rs
@@ -247,9 +247,12 @@ fn the_per_workspace_store_recovers_nothing_at_install_time() {
}
#[test]
+#[cfg(feature = "storage-sqlite")]
fn each_workspace_keeps_its_sessions_in_its_own_database() {
let first = tempfile::tempdir().unwrap();
let second = tempfile::tempdir().unwrap();
+ crate::storage::local::use_persistent_default_for_test(first.path());
+ crate::storage::local::use_persistent_default_for_test(second.path());
let in_first = provider_for_workspace(first.path()).for_agent("agent");
let in_second = provider_for_workspace(second.path()).for_agent("agent");
@@ -276,8 +279,10 @@ fn started(thread: &str, request: &str) -> tinyagents_session::turn_state::TurnS
}
#[tokio::test]
+#[cfg(feature = "storage-sqlite")]
async fn a_threads_turn_state_survives_a_restart_of_the_workspace_store() {
let dir = tempfile::tempdir().unwrap();
+ crate::storage::local::use_persistent_default_for_test(dir.path());
turn_states_for(dir.path())
.put(&started("thread-1", "req-1"))
.unwrap();
@@ -306,8 +311,10 @@ async fn a_threads_turn_state_survives_a_restart_of_the_workspace_store() {
}
#[tokio::test]
+#[cfg(feature = "storage-sqlite")]
async fn a_stashed_attachment_survives_a_restart_of_the_workspace_store() {
let dir = tempfile::tempdir().unwrap();
+ crate::storage::local::use_persistent_default_for_test(dir.path());
let data_uri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==";
let stash = attachment_stash_for(dir.path()).expect("a stash for the default tenant");
stash.write("att-1", data_uri).await.unwrap();
diff --git a/crates/openhuman-core/src/storage/sessions/workspace_tests.rs b/crates/openhuman-core/src/storage/sessions/workspace_tests.rs
index fde5464d7e..e5cda1ffdb 100644
--- a/crates/openhuman-core/src/storage/sessions/workspace_tests.rs
+++ b/crates/openhuman-core/src/storage/sessions/workspace_tests.rs
@@ -88,6 +88,7 @@ fn the_ledger_serves_reads_from_async_and_sync_callers() {
}
#[test]
+#[cfg(feature = "storage-sqlite")]
fn an_unusable_workspace_degrades_to_an_in_memory_store() {
// A path under a regular file cannot hold a storage directory, so the
// default backend cannot open and the provider degrades rather than fails.