Skip to content

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

refactor(storage): update storage import modules to use crate::storage types

Steven Enamakelf38aaf724e72
diff --git a/crates/openhuman-core/src/modules/storage_import_support.rs b/crates/openhuman-core/src/modules/storage_import_support.rs
index 8598429ddc..1e6e20aa3a 100644
--- a/crates/openhuman-core/src/modules/storage_import_support.rs
+++ b/crates/openhuman-core/src/modules/storage_import_support.rs
@@ -9,10 +9,10 @@
use std::path::Path;
use std::sync::Arc;
-use anyhow::{anyhow, Result};
+use crate::storage::{DocumentStore, ErrorKind, Precondition, Storage};
+use anyhow::{Result, anyhow};
use serde_json::Value;
use sha2::Digest;
-use crate::storage::{DocumentStore, ErrorKind, Precondition, Storage};
/// The module's scope of the installed backend, or `None` when the process
/// runs without a storage backend (the module is then not using this storage).
diff --git a/crates/openhuman-core/src/modules/storage_import_tinybox.rs b/crates/openhuman-core/src/modules/storage_import_tinybox.rs
index 68213dddd3..83aafe33d5 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinybox.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinybox.rs
@@ -21,9 +21,9 @@
use std::path::Path;
+use crate::storage::{CollectionSpec, Storage};
use anyhow::{Context, Result};
use serde_json::Value;
-use crate::storage::{CollectionSpec, Storage};
use super::storage_grant_schemas::tinybox::{JAIL_INDEX_COLLECTION, MODULE_ID};
use super::storage_import_support as support;
diff --git a/crates/openhuman-core/src/modules/storage_import_tinybox_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinybox_tests.rs
index 1aa20be47a..5f741f7595 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinybox_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinybox_tests.rs
@@ -1,7 +1,7 @@
use super::*;
+use crate::storage::{Precondition, Scope, Storage};
use serde_json::json;
use sha2::Digest;
-use crate::storage::{Precondition, Scope, Storage};
use tinystoragedrivers_testkit::memory_storage;
fn scoped() -> Storage {
diff --git a/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs b/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs
index e513ba6323..771b1629e0 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs
@@ -22,9 +22,9 @@
use std::path::Path;
-use anyhow::{anyhow, Context, Result};
-use serde_json::{json, Value};
use crate::storage::{CollectionSpec, Storage};
+use anyhow::{Context, Result, anyhow};
+use serde_json::{Value, json};
use super::storage_grant_schemas::tinyconnectors::{
MODULE_ID, PREFS_COLLECTION, TRIGGER_STREAM_PREFIX,
@@ -82,11 +82,7 @@ struct Legacy {
skipped: usize,
}
-async fn import_into(
- ctx: &DispatchCtx,
- scoped: &Storage,
- state_dir: &Path,
-) -> Result<Outcome> {
+async fn import_into(ctx: &DispatchCtx, scoped: &Storage, state_dir: &Path) -> Result<Outcome> {
let docs = scoped.documents();
let marker = support::marker_id("connectors", state_dir);
if support::already_imported(scoped, MARKER_COLLECTION, &marker).await? {
diff --git a/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs
index d00cb7e614..52e6a2b421 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinyconnectors_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-use sha2::Digest;
use crate::storage::{Precondition, Scope, Storage};
+use sha2::Digest;
use tinystoragedrivers_testkit::memory_storage;
fn scoped() -> Storage {
@@ -91,11 +91,12 @@ async fn preferences_and_the_trigger_archive_move_into_the_modules_storage() {
);
let slack = docs.get(PREFS_COLLECTION, "slack").await.unwrap().unwrap();
assert_eq!(slack.doc, json!({"value": true}));
- assert!(docs
- .get(PREFS_COLLECTION, "broken")
- .await
- .unwrap()
- .is_none());
+ assert!(
+ docs.get(PREFS_COLLECTION, "broken")
+ .await
+ .unwrap()
+ .is_none()
+ );
let streams = scoped.streams();
let first = streams
@@ -144,12 +145,14 @@ async fn a_second_run_is_a_noop_even_after_the_module_changed_the_data() {
.unwrap(),
Outcome::AlreadyDone
);
- assert!(scoped
- .documents()
- .get(PREFS_COLLECTION, "gmail")
- .await
- .unwrap()
- .is_none());
+ assert!(
+ scoped
+ .documents()
+ .get(PREFS_COLLECTION, "gmail")
+ .await
+ .unwrap()
+ .is_none()
+ );
}
#[tokio::test]
@@ -234,12 +237,14 @@ async fn an_unreadable_preference_file_is_retried_instead_of_marked_done() {
.await
.is_err()
);
- assert!(scoped
- .documents()
- .get(PREFS_COLLECTION, "gmail")
- .await
- .unwrap()
- .is_none());
+ assert!(
+ scoped
+ .documents()
+ .get(PREFS_COLLECTION, "gmail")
+ .await
+ .unwrap()
+ .is_none()
+ );
std::fs::remove_file(legacy.path().join(PREFS_DIR).join("bad.json")).unwrap();
assert!(matches!(
diff --git a/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs b/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs
index bf82ea13e9..8fa44b1b26 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs
@@ -23,7 +23,7 @@
use std::path::Path;
use std::time::{Duration, SystemTime};
-use anyhow::{anyhow, Context, Result};
+use anyhow::{Context, Result, anyhow};
use tinystoragedrivers_types::Capability;
use crate::storage::Storage;
diff --git a/crates/openhuman-core/src/modules/storage_import_tinyjuice_savings.rs b/crates/openhuman-core/src/modules/storage_import_tinyjuice_savings.rs
index 13aad39a26..a889f7762e 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinyjuice_savings.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinyjuice_savings.rs
@@ -21,9 +21,9 @@
use std::future::Future;
use std::path::{Path, PathBuf};
+use crate::storage::Storage;
use anyhow::{Context, Result};
use tinyjuice_bus::savings::SavingsAggregate;
-use crate::storage::Storage;
use super::storage_grant_schemas::tinyjuice::MODULE_ID;
use super::storage_import_support as support;
diff --git a/crates/openhuman-core/src/modules/storage_import_tinyjuice_savings_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinyjuice_savings_tests.rs
index 6bebff0093..1cd3ff1ee6 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinyjuice_savings_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinyjuice_savings_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-use std::sync::atomic::{AtomicUsize, Ordering};
use crate::storage::{Scope, Storage};
+use std::sync::atomic::{AtomicUsize, Ordering};
use tinystoragedrivers_testkit::memory_storage;
const SNAPSHOT: &str = r#"{
diff --git a/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs
index 1c0a24432b..aa4f9f853c 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinyjuice_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-use std::time::Duration;
use crate::storage::{Scope, Storage};
+use std::time::Duration;
use tinystoragedrivers_testkit::memory_storage;
const FRESH: &str = "00112233445566778899aabbccddeeff";
diff --git a/crates/openhuman-core/src/modules/storage_import_tinymcp.rs b/crates/openhuman-core/src/modules/storage_import_tinymcp.rs
index d813910848..95794bd652 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinymcp.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinymcp.rs
@@ -29,10 +29,10 @@
use std::path::{Path, PathBuf};
use std::sync::Arc;
-use anyhow::{anyhow, Context, Result};
-use serde_json::{json, Value};
-use sha2::Digest;
use crate::storage::{CollectionSpec, DocumentStore, ErrorKind, Precondition, Storage};
+use anyhow::{Context, Result, anyhow};
+use serde_json::{Value, json};
+use sha2::Digest;
use tinystoragedrivers_api::SecretStore;
use crate::core::runtime::DispatchCtx;
diff --git a/crates/openhuman-core/src/modules/storage_import_tinymcp_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinymcp_tests.rs
index 6ebb3542e5..2289531171 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinymcp_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinymcp_tests.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::storage::{Scope, Storage};
-use tinystoragedrivers_testkit::memory_storage;
use tinystoragedrivers_api::SecretStore;
+use tinystoragedrivers_testkit::memory_storage;
/// The first-generation schema: no `transport`, `deployment_url`, `enabled` or
/// `catalog_managed` column, which older installs never gained.
@@ -115,13 +115,14 @@ async fn servers_env_and_audit_rows_move_into_the_modules_storage() {
let env: std::collections::BTreeMap<String, String> = serde_json::from_slice(&stored).unwrap();
assert_eq!(env["API_KEY"], "sk-secret");
assert_eq!(env["REGION"], "eu");
- assert!(rig
- .scoped
- .secrets()
- .get("mcp_client_env/srv-2")
- .await
- .unwrap()
- .is_none());
+ assert!(
+ rig.scoped
+ .secrets()
+ .get("mcp_client_env/srv-2")
+ .await
+ .unwrap()
+ .is_none()
+ );
let audit = rig
.scoped
@@ -187,10 +188,12 @@ async fn the_legacy_files_are_left_untouched() {
.unwrap();
let after = [CLIENTS_DB, AUDIT_DB].map(|path| digest(&legacy.path().join(path)));
assert_eq!(before, after);
- assert!(!legacy
- .path()
- .join("mcp_clients/mcp_clients.db-wal")
- .exists());
+ assert!(
+ !legacy
+ .path()
+ .join("mcp_clients/mcp_clients.db-wal")
+ .exists()
+ );
}
#[tokio::test]
@@ -271,14 +274,16 @@ async fn an_unreadable_file_writes_no_marker_so_the_next_start_retries() {
)
.unwrap();
let rig = rig();
- assert!(import_into(
- &DispatchCtx::host_default(),
- &rig.scoped,
- rig.scoped.secrets().as_ref(),
- dir.path()
- )
- .await
- .is_err());
+ assert!(
+ import_into(
+ &DispatchCtx::host_default(),
+ &rig.scoped,
+ rig.scoped.secrets().as_ref(),
+ dir.path()
+ )
+ .await
+ .is_err()
+ );
let done = crate::storage::import_state::host_import_done(
&rig.scoped,
MARKER_COLLECTION,
diff --git a/crates/openhuman-core/src/modules/storage_import_tinywallet.rs b/crates/openhuman-core/src/modules/storage_import_tinywallet.rs
index 676bb7616f..9b8801811d 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinywallet.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinywallet.rs
@@ -22,8 +22,8 @@
use std::path::Path;
-use anyhow::{anyhow, Context, Result};
use crate::storage::Storage;
+use anyhow::{Context, Result, anyhow};
use super::storage_grant_schemas::tinywallet::{MODULE_ID, PAYMENTS_STREAM};
use super::storage_import_support as support;
@@ -56,11 +56,7 @@ pub(crate) async fn import_legacy(ctx: &DispatchCtx, workspace_dir: &Path) -> Re
import_into(ctx, &scoped, workspace_dir).await
}
-async fn import_into(
- ctx: &DispatchCtx,
- scoped: &Storage,
- workspace_dir: &Path,
-) -> Result<Outcome> {
+async fn import_into(ctx: &DispatchCtx, scoped: &Storage, workspace_dir: &Path) -> Result<Outcome> {
let marker = support::marker_id("x402", workspace_dir);
if support::already_imported(scoped, MARKER_COLLECTION, &marker).await? {
return Ok(Outcome::AlreadyDone);
diff --git a/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs b/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs
index 5bcb32fb2e..8e3782523b 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinywallet_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-use sha2::Digest;
use crate::storage::{Scope, Storage};
+use sha2::Digest;
use tinystoragedrivers_testkit::memory_storage;
fn scoped() -> Storage {
diff --git a/crates/openhuman-core/src/storage/scope_move.rs b/crates/openhuman-core/src/storage/scope_move.rs
index 4dbd2c2ad6..8a10b7a8fd 100644
--- a/crates/openhuman-core/src/storage/scope_move.rs
+++ b/crates/openhuman-core/src/storage/scope_move.rs
@@ -20,10 +20,10 @@ use std::sync::Arc;
use sha2::Digest;
use tinystoragedrivers_types::{Capability, CollectionSpec, ErrorKind, WriteOptions};
+use super::scope::{scope_for_agent, scope_for_profile, tenant_scope};
use crate::storage::{
DocumentStore, DocumentStoreExt, Precondition, Scope, StorageBackend, StorageError,
};
-use super::scope::{scope_for_agent, scope_for_profile, tenant_scope};
/// The ids a hashed v1 scope can be matched against.
#[derive(Debug, Default, Clone)]
@@ -318,9 +318,7 @@ pub async fn run_from_source(
/// path to [`crate::storage::import::scope_move::LegacyScopeInventory::read`]
/// and then pass that inventory to [`copy_inventory`].
#[deprecated(note = "use an explicit read-only legacy scope inventory")]
-pub async fn run(
- _backend: &Arc<dyn StorageBackend>,
-) -> Result<MoveReport, StorageError> {
+pub async fn run(_backend: &Arc<dyn StorageBackend>) -> Result<MoveReport, StorageError> {
Err(StorageError::unsupported(
Capability::CollectionEnumeration,
"v2 backends do not enumerate legacy scopes; supply an explicit legacy database inventory",
diff --git a/crates/openhuman-core/src/storage/scope_move_tests.rs b/crates/openhuman-core/src/storage/scope_move_tests.rs
index e658524c99..e80ac7d01f 100644
--- a/crates/openhuman-core/src/storage/scope_move_tests.rs
+++ b/crates/openhuman-core/src/storage/scope_move_tests.rs
@@ -1,8 +1,8 @@
use super::*;
#[cfg(feature = "legacy-import")]
-use serde_json::json;
-#[cfg(feature = "legacy-import")]
use crate::storage::Precondition;
+#[cfg(feature = "legacy-import")]
+use serde_json::json;
use tinystoragedrivers_testkit::MemoryBackend;
use tinystoragedrivers_types::Meta;