Skip to content

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

test(storage): pass backend references to document test helpers

Steven Enamakel16635ce56ed1
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs
index 8deda2f6f2..519af37a66 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs
@@ -68,9 +68,9 @@ fn save_upserts_sessions_and_keeps_the_others() {
#[test]
fn scopes_do_not_see_each_others_sessions() {
let storage = memory_backend();
- docs_in(&storage, "alice").save(&[session("a")]).unwrap();
- assert!(docs_in(&storage, "bob").load().unwrap().is_empty());
- assert_eq!(docs_in(&storage, "alice").load().unwrap().len(), 1);
+ docs_in(storage.as_ref(), "alice").save(&[session("a")]).unwrap();
+ assert!(docs_in(storage.as_ref(), "bob").load().unwrap().is_empty());
+ assert_eq!(docs_in(storage.as_ref(), "alice").load().unwrap().len(), 1);
}
#[test]
@@ -110,7 +110,7 @@ fn the_store_dispatches_to_documents_when_a_backend_is_pinned() {
let storage = memory_backend();
let dir = tempfile::tempdir().unwrap();
let store = SubagentSessionStore::new(dir.path().to_path_buf());
- let docs = docs_in(&storage, "local");
+ let docs = docs_in(storage.as_ref(), "local");
with_override(docs.clone(), || {
assert!(store.load().unwrap().is_empty());
store.save(&[session("a")]).unwrap();
@@ -222,7 +222,7 @@ fn a_durable_session_keeps_its_scoped_lifecycle_key_after_document_reopen() {
task_id: "task".into(),
};
saved.lifecycle_key = Some(key.clone());
- docs_in(&storage, "local").save(&[saved]).unwrap();
- let loaded = docs_in(&storage, "local").load().unwrap();
+ docs_in(storage.as_ref(), "local").save(&[saved]).unwrap();
+ let loaded = docs_in(storage.as_ref(), "local").load().unwrap();
assert_eq!(loaded[0].lifecycle_key, Some(key));
}
diff --git a/crates/openhuman-core/src/artifacts/store_documents_tests.rs b/crates/openhuman-core/src/artifacts/store_documents_tests.rs
index 1dc0c28d19..2641ac5cb8 100644
--- a/crates/openhuman-core/src/artifacts/store_documents_tests.rs
+++ b/crates/openhuman-core/src/artifacts/store_documents_tests.rs
@@ -63,11 +63,11 @@ fn args_and_delete() {
#[test]
fn scopes_do_not_see_each_others_artifacts() {
let storage = memory_backend();
- docs_in(&storage, "alice")
+ docs_in(storage.as_ref(), "alice")
.put_meta(&meta("a", 1, None))
.unwrap();
- assert!(docs_in(&storage, "bob").list_meta().unwrap().is_empty());
- assert_eq!(docs_in(&storage, "alice").list_meta().unwrap().len(), 1);
+ assert!(docs_in(storage.as_ref(), "bob").list_meta().unwrap().is_empty());
+ assert_eq!(docs_in(storage.as_ref(), "alice").list_meta().unwrap().len(), 1);
}
#[test]
@@ -157,7 +157,7 @@ fn delete_removes_the_record_before_its_arguments() {
#[tokio::test]
async fn the_store_dispatches_to_documents_when_a_backend_is_pinned() {
let storage = memory_backend();
- let docs = docs_in(&storage, "local");
+ let docs = docs_in(storage.as_ref(), "local");
let workspace = tempfile::tempdir().unwrap();
let ws = workspace.path();
super::TEST_OVERRIDE.with(|slot| *slot.borrow_mut() = Some(docs.clone()));
diff --git a/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs b/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs
index 44ca0ecbaa..879be92b9d 100644
--- a/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs
+++ b/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs
@@ -325,10 +325,10 @@ fn an_unparseable_raw_payload_reads_as_a_string() {
#[test]
fn scopes_keep_notifications_apart() {
let storage = memory_backend();
- docs_in(&storage, "alice")
+ docs_in(storage.as_ref(), "alice")
.insert(&note("a", "slack", "hi", 0), true)
.unwrap();
- let bob = docs_in(&storage, "bob");
+ let bob = docs_in(storage.as_ref(), "bob");
assert!(bob.list(10, 0, None, None).unwrap().is_empty());
assert!(!bob
.exists_recent("slack", Some("acct"), "New message", "hi")
diff --git a/crates/openhuman-core/src/integrations/task_sources/store_documents_tests.rs b/crates/openhuman-core/src/integrations/task_sources/store_documents_tests.rs
index 1c13030364..d463408f9a 100644
--- a/crates/openhuman-core/src/integrations/task_sources/store_documents_tests.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/store_documents_tests.rs
@@ -231,10 +231,10 @@ fn a_corrupt_source_is_an_error_not_a_panic() {
#[test]
fn scopes_keep_sources_apart() {
let storage = memory_backend();
- let alice = docs_in(&storage, "alice");
+ let alice = docs_in(storage.as_ref(), "alice");
alice.add_source(&source("s")).unwrap();
alice.mark_ingested("s", &task("1", "one")).unwrap();
- let bob = docs_in(&storage, "bob");
+ let bob = docs_in(storage.as_ref(), "bob");
assert!(bob.list_sources().unwrap().is_empty());
assert!(!bob.was_ingested("s", "1").unwrap());
assert_ne!(ingested_id("a/b", "c"), ingested_id("a", "b/c"));
diff --git a/crates/openhuman-core/src/memory/state_store_tests.rs b/crates/openhuman-core/src/memory/state_store_tests.rs
index e2bb3d8b34..798d99a6bf 100644
--- a/crates/openhuman-core/src/memory/state_store_tests.rs
+++ b/crates/openhuman-core/src/memory/state_store_tests.rs
@@ -140,7 +140,7 @@ async fn first_workspace_open_transfers_only_its_old_profile_queue_and_rechecks_
let bob_workspace = ProfileLayout::with_version(bob_dir, LayoutVersion::V2).workspace_dir;
let backend: std::sync::Arc<dyn crate::storage::StorageBackend> =
- std::sync::Arc::new(crate::storage::test_support::memory_backend());
+ crate::storage::test_support::memory_backend();
let alice_old = crate::storage::state_kv::StateKv::on_backend(
&backend,
&crate::storage::scope_for_profile("alice"),
@@ -259,7 +259,7 @@ async fn a_matching_active_agent_scope_is_a_legacy_source() {
ContextOverlay::new(config, DomainSet::full(), ToolGroups::none()).session_agent("agent-a"),
);
let backend: std::sync::Arc<dyn crate::storage::StorageBackend> =
- std::sync::Arc::new(crate::storage::test_support::memory_backend());
+ crate::storage::test_support::memory_backend();
let old_scope = crate::storage::scope_for_agent("agent-a");
let old =
crate::storage::state_kv::StateKv::on_backend(&backend, &old_scope, "memory", "state")
@@ -336,7 +336,7 @@ fn layout_import_places_legacy_retry_queue_in_its_workspace_scope() {
.unwrap();
let backend: std::sync::Arc<dyn crate::storage::StorageBackend> =
- std::sync::Arc::new(crate::storage::test_support::memory_backend());
+ crate::storage::test_support::memory_backend();
let local = backend.for_scope(&crate::storage::Scope::local()).unwrap();
let local_queue = crate::storage::state_kv::StateKv::over(&local, "memory", "state");
local_queue
diff --git a/crates/openhuman-core/src/platform/cost/tracker_documents_tests.rs b/crates/openhuman-core/src/platform/cost/tracker_documents_tests.rs
index 5eff4664b1..f5252e5846 100644
--- a/crates/openhuman-core/src/platform/cost/tracker_documents_tests.rs
+++ b/crates/openhuman-core/src/platform/cost/tracker_documents_tests.rs
@@ -44,8 +44,8 @@ fn a_record_is_written_once() {
#[test]
fn scopes_do_not_see_each_others_costs() {
let storage = memory_backend();
- let alice = docs_in(&storage, "alice");
- let bob = docs_in(&storage, "bob");
+ let alice = docs_in(storage.as_ref(), "alice");
+ let bob = docs_in(storage.as_ref(), "bob");
alice.add(&record("a/model", 1.0, 0)).unwrap();
assert_eq!(alice.all().unwrap().len(), 1);
assert!(bob.all().unwrap().is_empty());
diff --git a/crates/openhuman-core/src/security/approval/store_documents_tests.rs b/crates/openhuman-core/src/security/approval/store_documents_tests.rs
index 5b26a9dfc3..4c7d59f5de 100644
--- a/crates/openhuman-core/src/security/approval/store_documents_tests.rs
+++ b/crates/openhuman-core/src/security/approval/store_documents_tests.rs
@@ -72,7 +72,7 @@ fn a_request_is_decided_exactly_once() {
#[test]
fn concurrent_deciders_never_both_win() {
let storage = memory_backend();
- let store = docs_in(&storage, "local");
+ let store = docs_in(storage.as_ref(), "local");
store
.insert_pending(&pending("race", 0, None), "s")
.unwrap();
@@ -265,8 +265,8 @@ fn flow_trust_grants_list_and_revoke() {
#[test]
fn scopes_keep_users_apart() {
let storage = memory_backend();
- let alice = docs_in(&storage, "alice");
- let bob = docs_in(&storage, "bob");
+ let alice = docs_in(storage.as_ref(), "alice");
+ let bob = docs_in(storage.as_ref(), "bob");
alice.insert_pending(&pending("r", 0, None), "s").unwrap();
alice.insert_flow_trust("flow-1", "shell").unwrap();
assert!(bob.list_pending().unwrap().is_empty());
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 283bd8ad29..84a2ebbfea 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
@@ -49,7 +49,7 @@ 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 = memory_backend();
- let secrets = storage_secrets_in(&storage, "local");
+ let secrets = storage_secrets_in(storage.as_ref(), "local");
let read = |secrets| {
get_adopting(secrets, "alice:token", "token", || {
@@ -76,7 +76,7 @@ fn an_os_keyring_secret_is_adopted_into_storage_on_first_read() {
fn a_secret_absent_everywhere_stays_absent_and_storage_wins_over_the_os() {
let os = MockBackend::new();
let storage = memory_backend();
- let secrets = storage_secrets_in(&storage, "local");
+ let secrets = storage_secrets_in(storage.as_ref(), "local");
assert_eq!(
get_adopting(secrets.clone(), "bob:k", "k", || os
.get("bob:k")
@@ -102,11 +102,11 @@ fn adopted_secrets_do_not_cross_scopes() {
let os = MockBackend::new();
os.set("u:k", "v").unwrap();
let storage = memory_backend();
- get_adopting(storage_secrets_in(&storage, "alice"), "u:k", "k", || {
+ get_adopting(storage_secrets_in(storage.as_ref(), "alice"), "u:k", "k", || {
os.get("u:k").ok().flatten()
})
.unwrap();
- let other = storage_secrets_in(&storage, "bob");
+ let other = storage_secrets_in(storage.as_ref(), "bob");
assert_eq!(
crate::storage::block_on(async move { other.get("u:k").await }).unwrap(),
None
@@ -122,7 +122,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 = memory_backend();
- let secrets = storage_secrets_in(&storage, "local");
+ let secrets = storage_secrets_in(storage.as_ref(), "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/documents_tests.rs b/crates/openhuman-core/src/storage/documents_tests.rs
index 16995ea1ff..54fc178571 100644
--- a/crates/openhuman-core/src/storage/documents_tests.rs
+++ b/crates/openhuman-core/src/storage/documents_tests.rs
@@ -18,7 +18,7 @@ fn repo(storage: &dyn StorageBackend, scope: &str) -> Repo {
#[test]
fn run_declares_the_collections_and_returns_the_result() {
let storage = memory_backend();
- let repo = repo(&storage, "local");
+ let repo = repo(storage.as_ref(), "local");
repo.run(|docs| async move {
docs.put(
THINGS,
@@ -40,7 +40,7 @@ fn run_declares_the_collections_and_returns_the_result() {
#[test]
fn storage_errors_name_the_domain() {
let storage = memory_backend();
- let error = repo(&storage, "local")
+ let error = repo(storage.as_ref(), "local")
.run(|_| async { Err::<(), _>(StorageError::conflict("raced")) })
.unwrap_err();
assert!(error.to_string().starts_with("[test] storage:"), "{error}");
@@ -49,7 +49,7 @@ fn storage_errors_name_the_domain() {
#[test]
fn compare_and_swap_applies_declines_and_skips_missing() {
let storage = memory_backend();
- let repo = repo(&storage, "local");
+ let repo = repo(storage.as_ref(), "local");
let (closed, declined, missing) = repo
.run(|docs| async move {
docs.put(
@@ -79,7 +79,7 @@ fn compare_and_swap_applies_declines_and_skips_missing() {
#[test]
fn concurrent_swaps_apply_once() {
let storage = memory_backend();
- let repo = repo(&storage, "local");
+ let repo = repo(storage.as_ref(), "local");
repo.run(|docs| async move {
docs.put(
THINGS,
@@ -115,14 +115,14 @@ fn concurrent_swaps_apply_once() {
#[test]
fn scopes_do_not_see_each_other() {
let storage = memory_backend();
- repo(&storage, "alice")
+ repo(storage.as_ref(), "alice")
.run(|docs| async move {
docs.put(THINGS, "a", json!({}), Precondition::Absent)
.await
.map(|_| ())
})
.unwrap();
- let seen = repo(&storage, "bob")
+ let seen = repo(storage.as_ref(), "bob")
.run(|docs| async move { docs.get(THINGS, "a").await })
.unwrap();
assert!(seen.is_none());