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
test: use shared memory backend helper in store document tests
Steven Enamakelb2d14f2b388b
diff --git a/crates/openhuman-core/src/artifacts/store_documents_tests.rs b/crates/openhuman-core/src/artifacts/store_documents_tests.rsindex e00790c523..1dc0c28d19 100644--- a/crates/openhuman-core/src/artifacts/store_documents_tests.rs+++ b/crates/openhuman-core/src/artifacts/store_documents_tests.rs@@ -5,10 +5,10 @@ use crate::artifacts::store::{};use crate::artifacts::types::{ArtifactKind, ArtifactStatus};use crate::artifacts::FileRoots;-use crate::storage::{MemoryStorage, Scope, StorageBackend};+use crate::storage::{test_support::memory_backend, Scope, StorageBackend};use chrono::{TimeZone, Utc};-fn docs_in(storage: &MemoryStorage, scope: &str) -> Docs {+fn docs_in(storage: &dyn StorageBackend, scope: &str) -> Docs {Docs::over(&storage.for_scope(&Scope::new(scope).unwrap()).unwrap())}@@ -31,7 +31,8 @@ fn meta(id: &str, month: u32, thread: Option<&str>) -> ArtifactMeta {#[test]fn records_round_trip_newest_first() {- let docs = docs_in(&MemoryStorage::new(), "local");+ let storage = memory_backend();+ let docs = docs_in(storage.as_ref(), "local");docs.put_meta(&meta("a", 1, None)).unwrap();docs.put_meta(&meta("c", 3, None)).unwrap();docs.put_meta(&meta("b", 2, None)).unwrap();@@ -48,7 +49,8 @@ fn records_round_trip_newest_first() {#[test]fn args_and_delete() {- let docs = docs_in(&MemoryStorage::new(), "local");+ let storage = memory_backend();+ let docs = docs_in(storage.as_ref(), "local");docs.put_meta(&meta("a", 1, None)).unwrap();docs.put_args("a", &serde_json::json!({ "k": 1 })).unwrap();assert_eq!(docs.get_args("a").unwrap().unwrap()["k"], 1);@@ -60,7 +62,7 @@ fn args_and_delete() {#[test]fn scopes_do_not_see_each_others_artifacts() {- let storage = MemoryStorage::new();+ let storage = memory_backend();docs_in(&storage, "alice").put_meta(&meta("a", 1, None)).unwrap();@@ -101,7 +103,8 @@ fn the_legacy_files_are_imported_without_overwriting() {.unwrap();std::fs::write(copy.join("args.json"), r#"{"x":5}"#).unwrap();- let docs = docs_in(&MemoryStorage::new(), "local");+ let storage = memory_backend();+ let docs = docs_in(storage.as_ref(), "local");// A record and arguments written before the import are not overwritten.let mut existing = meta("a", 1, Some("t"));existing.title = "kept".into();@@ -126,7 +129,8 @@ fn a_legacy_folder_that_cannot_be_read_fails_the_import() {let dir = tempfile::tempdir().unwrap();let not_a_dir = dir.path().join("artifacts");std::fs::write(¬_a_dir, "a file").unwrap();- let docs = docs_in(&MemoryStorage::new(), "local");+ let storage = memory_backend();+ let docs = docs_in(storage.as_ref(), "local");assert!(docs.import_legacy(¬_a_dir).is_err());// An unreadable sidecar (here a directory named args.json) fails it too.@@ -142,7 +146,8 @@ fn a_legacy_folder_that_cannot_be_read_fails_the_import() {#[test]fn delete_removes_the_record_before_its_arguments() {- let docs = docs_in(&MemoryStorage::new(), "local");+ let storage = memory_backend();+ let docs = docs_in(storage.as_ref(), "local");docs.put_args("orphan", &serde_json::json!({})).unwrap();// No record: reported absent, and the orphaned arguments are swept.assert!(!docs.delete("orphan").unwrap());@@ -151,7 +156,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 = MemoryStorage::new();+ let storage = memory_backend();let docs = docs_in(&storage, "local");let workspace = tempfile::tempdir().unwrap();let ws = workspace.path();diff --git a/crates/openhuman-core/src/security/approval/store_documents_tests.rs b/crates/openhuman-core/src/security/approval/store_documents_tests.rsindex b95a5880e5..3d4df9be69 100644--- a/crates/openhuman-core/src/security/approval/store_documents_tests.rs+++ b/crates/openhuman-core/src/security/approval/store_documents_tests.rs@@ -1,13 +1,14 @@use super::*;use chrono::{Duration, Timelike};-use tinystoragedrivers::{MemoryStorage, Scope, StorageBackend};+use crate::storage::{test_support::memory_backend, Scope, StorageBackend};-fn docs_in(storage: &MemoryStorage, scope: &str) -> Docs {+fn docs_in(storage: &dyn StorageBackend, scope: &str) -> Docs {Docs::new(&storage.for_scope(&Scope::new(scope).unwrap()).unwrap())}fn docs() -> Docs {- docs_in(&MemoryStorage::new(), "local")+ let storage = memory_backend();+ docs_in(storage.as_ref(), "local")}fn pending(id: &str, created_secs_ago: i64, expires_in: Option<i64>) -> PendingApproval {@@ -72,7 +73,7 @@ fn a_request_is_decided_exactly_once() {#[test]fn concurrent_deciders_never_both_win() {- let storage = MemoryStorage::new();+ let storage = memory_backend();let store = docs_in(&storage, "local");store.insert_pending(&pending("race", 0, None), "s")@@ -269,7 +270,7 @@ fn flow_trust_grants_list_and_revoke() {#[test]fn scopes_keep_users_apart() {- let storage = MemoryStorage::new();+ let storage = memory_backend();let alice = docs_in(&storage, "alice");let bob = docs_in(&storage, "bob");alice.insert_pending(&pending("r", 0, None), "s").unwrap();