Skip to content

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

test(storage): route store tests through persistent defaults

Steven Enamakele15527cec6ca
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 69139673a1..3e6d11c0b4 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
@@ -8,18 +8,9 @@ fn docs_in(storage: &dyn StorageBackend, scope: &str) -> Docs {
Docs::over(&storage.for_scope(&Scope::new(scope).unwrap()).unwrap())
}
-fn opened_docs_in(
- storage: &std::sync::Arc<dyn StorageBackend>,
- scope: &str,
-) -> Docs {
+fn opened_docs_in(storage: &std::sync::Arc<dyn StorageBackend>, scope: &str) -> Docs {
let scope = Scope::new(scope).unwrap();
- Docs(crate::storage::documents::Repo::on(
- storage,
- &scope,
- DOMAIN,
- collections,
- )
- .unwrap())
+ Docs(crate::storage::documents::Repo::on(storage, &scope, DOMAIN, collections).unwrap())
}
fn session(id: &str) -> DurableSubagentSession {
diff --git a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
index a21309420c..778738c0ed 100644
--- a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
@@ -342,11 +342,12 @@ async fn cron_agent_job_uses_agent_definition_tool_scope() {
job.name = Some("morning_briefing".into());
job.agent_id = Some("morning_briefing".into());
- let built = build_agent_for_cron_job(&crate::core::runtime::DispatchCtx::ambient(), &config, &job)
- .unwrap_or_else(|error| {
- eprintln!("failed to build cron agent: {error:#}");
- panic!("build cron agent")
- });
+ let built =
+ build_agent_for_cron_job(&crate::core::runtime::DispatchCtx::ambient(), &config, &job)
+ .unwrap_or_else(|error| {
+ eprintln!("failed to build cron agent: {error:#}");
+ panic!("build cron agent")
+ });
let visible = built.agent.visible_tool_specs_arc();
assert!(
diff --git a/crates/openhuman-core/src/desktop/notifications/store_import_tests.rs b/crates/openhuman-core/src/desktop/notifications/store_import_tests.rs
index ec62a87c8b..803755fd86 100644
--- a/crates/openhuman-core/src/desktop/notifications/store_import_tests.rs
+++ b/crates/openhuman-core/src/desktop/notifications/store_import_tests.rs
@@ -9,6 +9,7 @@ use tempfile::TempDir;
fn workspace() -> (TempDir, Config) {
let dir = TempDir::new().unwrap();
+ crate::storage::local::use_persistent_default_for_test(dir.path());
let config = Config {
workspace_dir: dir.path().to_path_buf(),
..Config::default()
diff --git a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs b/crates/openhuman-core/src/integrations/composio/file_store_documents.rs
index b61d630298..60609f6d17 100644
--- a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs
+++ b/crates/openhuman-core/src/integrations/composio/file_store_documents.rs
@@ -79,6 +79,17 @@ impl Docs {
}
}
+ #[cfg(test)]
+ pub(super) fn on_backend(
+ backend: &std::sync::Arc<dyn crate::storage::StorageBackend>,
+ scope: &crate::storage::Scope,
+ ) -> anyhow::Result<Self> {
+ Ok(Self {
+ repo: Repo::on(backend, scope, DOMAIN, Vec::new)?,
+ state: StateKv::on_backend(backend, scope, KV_OWNER, KV_NS)?,
+ })
+ }
+
/// The value stored stored under `name`, or `T::default()`.
pub(super) fn load<T: DeserializeOwned + Default>(&self, name: &str) -> Result<T> {
let stored: Option<Value> = self.state.get(name)?;
diff --git a/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs b/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs
index 915278d137..f65ddce509 100644
--- a/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs
@@ -163,7 +163,7 @@ fn an_unchanged_update_writes_nothing_and_returns_its_result() {
#[test]
fn the_import_marker_is_a_migrations_entry_and_stops_a_second_import() {
let storage = crate::storage::test_support::sqlite_backend().unwrap();
- let docs = docs_in(&storage.backend, &Scope::local());
+ let docs = Docs::on_backend(&storage.backend, &Scope::local()).unwrap();
assert!(!docs.legacy_imported(path()).unwrap());
assert!(docs
.import_if_absent(path(), serde_json::json!({ "gmail": 5 }))
diff --git a/crates/openhuman-core/src/integrations/composio/file_store_tests.rs b/crates/openhuman-core/src/integrations/composio/file_store_tests.rs
index c729cea3a1..ac507c9d0b 100644
--- a/crates/openhuman-core/src/integrations/composio/file_store_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/file_store_tests.rs
@@ -2,6 +2,7 @@ use super::*;
use std::collections::BTreeMap;
fn config_in(dir: &tempfile::TempDir) -> Config {
+ crate::storage::local::use_persistent_default_for_test(dir.path());
Config {
workspace_dir: dir.path().to_path_buf(),
..Config::default()
diff --git a/crates/openhuman-core/src/integrations/task_sources/store_import_tests.rs b/crates/openhuman-core/src/integrations/task_sources/store_import_tests.rs
index f127924657..0fb90743d1 100644
--- a/crates/openhuman-core/src/integrations/task_sources/store_import_tests.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/store_import_tests.rs
@@ -9,6 +9,7 @@ use tempfile::TempDir;
fn workspace() -> (TempDir, Config) {
let dir = TempDir::new().unwrap();
+ crate::storage::local::use_persistent_default_for_test(dir.path());
let config = Config {
workspace_dir: dir.path().to_path_buf(),
..Config::default()
diff --git a/crates/openhuman-core/src/security/approval/store_import_tests.rs b/crates/openhuman-core/src/security/approval/store_import_tests.rs
index ddc6cf839a..41d6e39799 100644
--- a/crates/openhuman-core/src/security/approval/store_import_tests.rs
+++ b/crates/openhuman-core/src/security/approval/store_import_tests.rs
@@ -8,6 +8,7 @@ use tempfile::TempDir;
fn workspace() -> (TempDir, Config) {
let dir = TempDir::new().unwrap();
+ crate::storage::local::use_persistent_default_for_test(dir.path());
let config = Config {
workspace_dir: dir.path().to_path_buf(),
..Config::default()
diff --git a/crates/openhuman-embed/examples/storage.rs b/crates/openhuman-embed/examples/storage.rs
index d0f7037cc9..641af6a978 100644
--- a/crates/openhuman-embed/examples/storage.rs
+++ b/crates/openhuman-embed/examples/storage.rs
@@ -27,7 +27,10 @@ async fn run() -> anyhow::Result<()> {
.build()
.await?;
let storage = runtime.storage().expect("configured SQLite backend");
- assert_eq!(runtime.capabilities().storage.driver.as_deref(), Some("sqlite"));
+ assert_eq!(
+ runtime.capabilities().storage.driver.as_deref(),
+ Some("sqlite")
+ );
let scoped = storage.for_scope(&Scope::local())?;
let documents = scoped.documents();
documents
@@ -73,7 +76,10 @@ async fn run() -> anyhow::Result<()> {
// An explicit environment variable is the only path to a live database.
if let Ok(url) = std::env::var("OPENHUMAN_EXAMPLE_MONGODB_URL") {
let live = RuntimeBuilder::library().storage(url).build().await?;
- assert_eq!(live.capabilities().storage.driver.as_deref(), Some("mongodb"));
+ assert_eq!(
+ live.capabilities().storage.driver.as_deref(),
+ Some("mongodb")
+ );
}
// ANCHOR_END: storage_mongodb
println!("SQLite put/get/delete and credential-safe MongoDB configuration verified");
diff --git a/crates/openhuman-rpc/src/session_store/mod_tests.rs b/crates/openhuman-rpc/src/session_store/mod_tests.rs
index 36cd43feaa..016b101a1e 100644
--- a/crates/openhuman-rpc/src/session_store/mod_tests.rs
+++ b/crates/openhuman-rpc/src/session_store/mod_tests.rs
@@ -165,9 +165,7 @@ async fn provider_for_url_returns_the_store_without_installing_it() {
crate::core_host::agent::session_store::restore(previous);
assert!(
- backed_key
- .as_deref()
- .is_some_and(|key| !key.is_empty()),
+ backed_key.as_deref().is_some_and(|key| !key.is_empty()),
"{backed_key:?}"
);
assert_eq!(
@@ -205,10 +203,6 @@ async fn provider_for_host_reads_the_storage_url_from_the_environment() {
restore_backend(previous_backend);
let key = booted.unwrap();
- assert!(
- key.as_deref()
- .is_some_and(|key| !key.is_empty()),
- "{key:?}"
- );
+ assert!(key.as_deref().is_some_and(|key| !key.is_empty()), "{key:?}");
assert!(refused.is_err(), "an unusable env URL fails the TUI boot");
}