Skip to content

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

chore: files changed crates/openhuman-core/src/agent/session_store/mod.rs,crates/openhuman-core/src/

Steven Enamakel61f8140d3c2f
diff --git a/crates/openhuman-core/src/agent/session_store/mod.rs b/crates/openhuman-core/src/agent/session_store/mod.rs
index bc1f737e21..92507e771f 100644
--- a/crates/openhuman-core/src/agent/session_store/mod.rs
+++ b/crates/openhuman-core/src/agent/session_store/mod.rs
@@ -27,11 +27,10 @@ mod workspace;
pub use rebound::{rebind_all, ReboundSessionStores, StoreRegistry};
pub use tenant_router::TenantSessionStores;
pub use workspace::{
- session_scope,
artifact_blobs_for, attachment_stash_for, current_documents_for, default_turn_states_for,
ledger_for, provider_for_workspace, release_workspace, release_workspace_defaults,
- require_ledger, status_store_for, stores_for, stores_or_ephemeral, turn_states_for,
- with_ledger, with_ledger_async, WorkspaceSessionStores,
+ require_ledger, session_scope, status_store_for, stores_for, stores_or_ephemeral,
+ turn_states_for, with_ledger, with_ledger_async, WorkspaceSessionStores,
};
static PROVIDER: LazyLock<RwLock<Option<Arc<dyn SessionStoreProvider>>>> =
diff --git a/crates/openhuman-core/src/agent/session_store/rebound.rs b/crates/openhuman-core/src/agent/session_store/rebound.rs
index 4070c8cecc..8e3b54eea2 100644
--- a/crates/openhuman-core/src/agent/session_store/rebound.rs
+++ b/crates/openhuman-core/src/agent/session_store/rebound.rs
@@ -13,8 +13,8 @@
use std::sync::{Arc, LazyLock, Mutex, PoisonError, RwLock, Weak};
-use tinyagents_session::port::{AgentStores, SessionStoreProvider};
use super::tenant_router::TenantSessionStores;
+use tinyagents_session::port::{AgentStores, SessionStoreProvider};
use tinystoragedrivers::{Blocking, StorageBackend, StorageError};
/// The live [`ReboundSessionStores`] of one owner, so a rebind reaches the one
diff --git a/crates/openhuman-core/src/agent/session_store/splice_fixture.rs b/crates/openhuman-core/src/agent/session_store/splice_fixture.rs
index 6f5a5fed4a..37daf0a508 100644
--- a/crates/openhuman-core/src/agent/session_store/splice_fixture.rs
+++ b/crates/openhuman-core/src/agent/session_store/splice_fixture.rs
@@ -18,9 +18,9 @@ pub(crate) fn memory_locator() -> Arc<dyn TranscriptLocator> {
Arc::new(crate::storage::MemoryStorage::new()),
crate::storage::Scope::local(),
)
- .expect("driver session stores over memory")
- .for_agent("fixture")
- .transcripts
+ .expect("driver session stores over memory")
+ .for_agent("fixture")
+ .transcripts
}
/// A thread's head transcript as the model reads it.
diff --git a/crates/openhuman-core/src/agent/session_store/tenant_router.rs b/crates/openhuman-core/src/agent/session_store/tenant_router.rs
index 19663a2908..b9caf83f95 100644
--- a/crates/openhuman-core/src/agent/session_store/tenant_router.rs
+++ b/crates/openhuman-core/src/agent/session_store/tenant_router.rs
@@ -70,7 +70,11 @@ impl TenantSessionStores {
backend: Arc<dyn StorageBackend>,
recover_on_open: bool,
) -> Result<Self, StorageError> {
- Ok(Self::with_bridge(backend, Blocking::new()?, recover_on_open))
+ Ok(Self::with_bridge(
+ backend,
+ Blocking::new()?,
+ recover_on_open,
+ ))
}
/// The provider of the tenant `key` belongs to, and the agent id within it.
diff --git a/crates/openhuman-core/src/agent/session_store/tenant_router_tests.rs b/crates/openhuman-core/src/agent/session_store/tenant_router_tests.rs
index 41d9efc133..08e23d9804 100644
--- a/crates/openhuman-core/src/agent/session_store/tenant_router_tests.rs
+++ b/crates/openhuman-core/src/agent/session_store/tenant_router_tests.rs
@@ -11,7 +11,10 @@ fn an_unprofiled_key_routes_to_the_local_tenant() {
let (provider, agent) = router.route("asha");
assert_eq!(provider.tenant(), &Scope::local());
assert_eq!(agent, "asha");
- assert_eq!(provider.scope_for(&agent).unwrap().as_str(), "local/agent:asha");
+ assert_eq!(
+ provider.scope_for(&agent).unwrap().as_str(),
+ "local/agent:asha"
+ );
}
#[test]
@@ -23,7 +26,10 @@ fn a_profile_key_routes_to_the_profile_tenant() {
});
let (provider, agent) = router.route(&key);
assert_eq!(provider.tenant().as_str(), "u:alice");
- assert_eq!(provider.scope_for(&agent).unwrap().as_str(), "u:alice/agent:asha");
+ assert_eq!(
+ provider.scope_for(&agent).unwrap().as_str(),
+ "u:alice/agent:asha"
+ );
}
#[test]
@@ -34,7 +40,10 @@ fn escaped_keys_round_trip_to_the_same_tenant_and_agent() {
agent: None,
});
let (provider, agent) = router.route(&key);
- assert_eq!(provider.tenant(), &crate::storage::scope_for_profile("a~b%c"));
+ assert_eq!(
+ provider.tenant(),
+ &crate::storage::scope_for_profile("a~b%c")
+ );
assert_eq!(agent, "default");
}
diff --git a/crates/openhuman-core/src/agent/session_store/workspace.rs b/crates/openhuman-core/src/agent/session_store/workspace.rs
index ce16a4ad44..b342643f9a 100644
--- a/crates/openhuman-core/src/agent/session_store/workspace.rs
+++ b/crates/openhuman-core/src/agent/session_store/workspace.rs
@@ -17,10 +17,10 @@ use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::{Arc, LazyLock, Mutex, PoisonError};
+use super::tenant_router::TenantSessionStores;
use tinyagents_harness::multimodal::BlobAttachmentStash;
use tinyagents_session::port::{AgentStores, SessionStoreProvider, TurnStates};
use tinyagents_session::run_ledger::{LedgerError, LedgerResult, RunLedgerStore};
-use super::tenant_router::TenantSessionStores;
use tinystoragedrivers::{BlobStore, DocumentStore, MemoryStorage, StorageBackend};
/// One fallback provider and the backend it was built over.
diff --git a/crates/openhuman-core/src/core/runtime/mod.rs b/crates/openhuman-core/src/core/runtime/mod.rs
index 71a06f66f6..9bf7bc5f9c 100644
--- a/crates/openhuman-core/src/core/runtime/mod.rs
+++ b/crates/openhuman-core/src/core/runtime/mod.rs
@@ -69,7 +69,8 @@ pub use dispatch_ctx::DispatchCtx;
pub use mode::{current_mode, is_saas, Mode};
pub use saas::SaasConfig;
pub use tenant::{
- current_tenant, session_key, session_key_prefix, split_session_key, tenant_key, NoTenant, Tenant,
+ current_tenant, session_key, session_key_prefix, split_session_key, tenant_key, NoTenant,
+ Tenant,
};
/// Operator-owned direct inference settings.
diff --git a/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs b/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
index 12d6821739..3872587c84 100644
--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
@@ -71,7 +71,10 @@ fn seed_thread(config: &Config, id: &str) {
working_dir: None,
},
)
- .unwrap_or_else(|e| { eprintln!("ERR {e:#}"); panic!() });
+ .unwrap_or_else(|e| {
+ eprintln!("ERR {e:#}");
+ panic!()
+ });
}
#[test]
diff --git a/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs b/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs
index 44df41b29e..f640a2ba94 100644
--- a/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs
@@ -2,7 +2,12 @@ use super::*;
use crate::modules::storage_grants::{authorize, declared, Denied, Object, Plan};
use serde_json::json;
-fn allowed(grant: &StorageGrant, object: Object, selector: &str, request: serde_json::Value) -> bool {
+fn allowed(
+ grant: &StorageGrant,
+ object: Object,
+ selector: &str,
+ request: serde_json::Value,
+) -> bool {
matches!(
authorize(grant, object, selector, &request),
Ok(Plan::Forward { .. })
@@ -12,11 +17,19 @@ fn allowed(grant: &StorageGrant, object: Object, selector: &str, request: serde_
#[test]
fn every_row_has_a_valid_generated_grant() {
for row in &ROWS {
- let grant = declared(row.module).unwrap_or_else(|| panic!("{} declares storage", row.module));
- grant.validate().unwrap_or_else(|why| panic!("{}: {why}", row.module));
+ let grant =
+ declared(row.module).unwrap_or_else(|| panic!("{} declares storage", row.module));
+ grant
+ .validate()
+ .unwrap_or_else(|why| panic!("{}: {why}", row.module));
assert!(grant.writable);
let items = module_items(row.owner);
- assert_eq!(grant.collections.len(), items.collections.len(), "{}", row.module);
+ assert_eq!(
+ grant.collections.len(),
+ items.collections.len(),
+ "{}",
+ row.module
+ );
}
assert!(declared("not-a-module").is_none());
}
@@ -25,7 +38,9 @@ fn every_row_has_a_valid_generated_grant() {
fn the_registry_ids_exist() {
for row in &ROWS {
assert!(
- crate::modules::registry::ALL.iter().any(|record| record.id == row.module)
+ crate::modules::registry::ALL
+ .iter()
+ .any(|record| record.id == row.module)
|| row.module == "tinywallet",
"{}",
row.module
@@ -36,11 +51,32 @@ fn the_registry_ids_exist() {
#[test]
fn tinymcp_reaches_its_v2_collections_stream_and_secrets() {
let grant = declared("tinymcp").unwrap();
- assert!(allowed(&grant, Object::Documents, "Get", json!({"collection": "mcp.servers", "id": "x"})));
- assert!(allowed(&grant, Object::Streams, "Append", json!({"stream": "mcp.audit"})));
- assert!(allowed(&grant, Object::Secrets, "Get", json!({"name": "mcp_client_env/abc"})));
+ assert!(allowed(
+ &grant,
+ Object::Documents,
+ "Get",
+ json!({"collection": "mcp.servers", "id": "x"})
+ ));
+ assert!(allowed(
+ &grant,
+ Object::Streams,
+ "Append",
+ json!({"stream": "mcp.audit"})
+ ));
+ assert!(allowed(
+ &grant,
+ Object::Secrets,
+ "Get",
+ json!({"name": "mcp_client_env/abc"})
+ ));
assert_eq!(
- authorize(&grant, Object::Documents, "Get", &json!({"collection": "mcp_servers", "id": "x"})).unwrap_err(),
+ authorize(
+ &grant,
+ Object::Documents,
+ "Get",
+ &json!({"collection": "mcp_servers", "id": "x"})
+ )
+ .unwrap_err(),
Denied::Target,
"the v1 name is no longer granted"
);
@@ -50,6 +86,16 @@ fn tinymcp_reaches_its_v2_collections_stream_and_secrets() {
fn tinyjuice_reaches_only_its_blob_prefix() {
let grant = declared("tinyjuice").unwrap();
assert!(grant.collections.is_empty());
- assert!(allowed(&grant, Object::Blobs, "Get", json!({"key": "juice/ccr/abc"})));
- assert!(!allowed(&grant, Object::Blobs, "Get", json!({"key": "other/abc"})));
+ assert!(allowed(
+ &grant,
+ Object::Blobs,
+ "Get",
+ json!({"key": "juice/ccr/abc"})
+ ));
+ assert!(!allowed(
+ &grant,
+ Object::Blobs,
+ "Get",
+ json!({"key": "other/abc"})
+ ));
}
diff --git a/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs b/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs
index 4013dc420b..2f850e5340 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs
@@ -26,7 +26,9 @@ use anyhow::{anyhow, Context, Result};
use serde_json::{json, Value};
use tinystoragedrivers::{CollectionSpec, ScopedStorage};
-use super::storage_grant_schemas::tinyconnectors::{MODULE_ID, PREFS_COLLECTION, TRIGGER_STREAM_PREFIX};
+use super::storage_grant_schemas::tinyconnectors::{
+ MODULE_ID, PREFS_COLLECTION, TRIGGER_STREAM_PREFIX,
+};
use super::storage_import_support as support;
use crate::core::runtime::DispatchCtx;
diff --git a/crates/openhuman-core/src/storage/boot.rs b/crates/openhuman-core/src/storage/boot.rs
index 9db6477fb7..2162938cdd 100644
--- a/crates/openhuman-core/src/storage/boot.rs
+++ b/crates/openhuman-core/src/storage/boot.rs
@@ -76,7 +76,10 @@ pub async fn prepare_and_migrate(
/// `local`, plus every v2 scope the backend reports (when it can enumerate).
async fn scopes_to_migrate(backend: &Arc<dyn StorageBackend>) -> Vec<Scope> {
let mut scopes = vec![Scope::local()];
- if backend.capabilities().contains(Capability::ScopeEnumeration) {
+ if backend
+ .capabilities()
+ .contains(Capability::ScopeEnumeration)
+ {
match backend.scopes("").await {
Ok(found) => {
for scope in found {
@@ -165,7 +168,12 @@ async fn post_migrate_importers(
}
}
-fn record(report: &mut BootReport, scope: &Scope, step: &'static str, error: &dyn std::fmt::Display) {
+fn record(
+ report: &mut BootReport,
+ scope: &Scope,
+ step: &'static str,
+ error: &dyn std::fmt::Display,
+) {
tracing::warn!(
target: "openhuman::storage",
scope = scope.as_str(),
diff --git a/crates/openhuman-core/src/storage/boot_tests.rs b/crates/openhuman-core/src/storage/boot_tests.rs
index 5571508be8..41db1f8382 100644
--- a/crates/openhuman-core/src/storage/boot_tests.rs
+++ b/crates/openhuman-core/src/storage/boot_tests.rs
@@ -30,7 +30,9 @@ async fn a_v1_agent_scope_is_moved_before_its_owner_steps_run() {
let report = prepare_and_migrate(&backend).await.unwrap();
assert!(report.failures.is_empty(), "{:?}", report.failures);
- let new = backend.for_scope(&Scope::local().agent("asha").unwrap()).unwrap();
+ let new = backend
+ .for_scope(&Scope::local().agent("asha").unwrap())
+ .unwrap();
assert!(new
.documents()
.get("harness.embedding_cache", "s/k")
diff --git a/crates/openhuman-core/src/storage/fenced_backend.rs b/crates/openhuman-core/src/storage/fenced_backend.rs
index cd3cdf39b3..4536cba52c 100644
--- a/crates/openhuman-core/src/storage/fenced_backend.rs
+++ b/crates/openhuman-core/src/storage/fenced_backend.rs
@@ -54,10 +54,7 @@ impl std::fmt::Debug for FencedBackend {
impl FencedBackend {
/// `inner`, its writes checked against `fences`.
pub fn new(inner: Arc<dyn StorageBackend>, fences: Arc<FenceRegistry>) -> Self {
- Self {
- inner,
- fences,
- }
+ Self { inner, fences }
}
}
@@ -125,7 +122,11 @@ impl StorageBackend for FencedBackend {
/// The driver's own fenced handles; the fence wrapper itself builds on
/// these, so they are not wrapped a second time.
- fn for_scope_fenced(&self, scope: &Scope, fence: &tinystoragedrivers::Fence) -> Result<ScopedStorage> {
+ fn for_scope_fenced(
+ &self,
+ scope: &Scope,
+ fence: &tinystoragedrivers::Fence,
+ ) -> Result<ScopedStorage> {
self.inner.for_scope_fenced(scope, fence)
}
@@ -144,7 +145,8 @@ impl StorageBackend for FencedBackend {
generation: tinystoragedrivers::ScopeGeneration,
fence: &tinystoragedrivers::Fence,
) -> Result<ScopedStorage> {
- self.inner.for_scope_fenced_generation(scope, generation, fence)
+ self.inner
+ .for_scope_fenced_generation(scope, generation, fence)
}
async fn maintain(
@@ -172,7 +174,6 @@ impl StorageBackend for FencedBackend {
async fn sweep_expired_blobs(&self, scope: &Scope) -> Result<u64> {
self.inner.sweep_expired_blobs(scope).await
}
-
}
#[derive(Clone)]
diff --git a/crates/openhuman-core/src/storage/import/mod.rs b/crates/openhuman-core/src/storage/import/mod.rs
index b4ec117a68..b677bd50d6 100644
--- a/crates/openhuman-core/src/storage/import/mod.rs
+++ b/crates/openhuman-core/src/storage/import/mod.rs
@@ -28,8 +28,9 @@
//! untouched legacy file. A failed import leaves no marker and is retried
//! on the next boot.
//!
-//! Records land under [`Scope::local`], the scope the operator's own stores
-//! read; the legacy files belong to one workspace and carry no tenancy. SaaS
+//! Records land under [`super::scope::tenant_scope`] of no profile
+//! (`local`), the one scope every unprofiled reader resolves to
+//! ([`super::current_scope`]) — never a scope only some readers use; the legacy files belong to one workspace and carry no tenancy. SaaS
//! processes have no workspace-local legacy files and import nothing.
//!
//! # What is not here
@@ -279,8 +280,18 @@ fn import_one(
) -> Result<Outcome> {
let domain = source.domain;
let marker = marker_id(domain, &config.workspace_dir);
- let repo = Repo::on(backend, &Scope::local(), domain, source.collections)?;
- let markers = Repo::on(backend, &Scope::local(), "storage::import", marker_spec)?;
+ let repo = Repo::on(
+ backend,
+ &super::scope::tenant_scope(None),
+ domain,
+ source.collections,
+ )?;
+ let markers = Repo::on(
+ backend,
+ &super::scope::tenant_scope(None),
+ "storage::import",
+ marker_spec,
+ )?;
let marker_id = marker.clone();
let done = markers
@@ -382,7 +393,7 @@ pub fn is_done(
) -> Result<bool> {
let marker = marker_id(source.domain, &config.workspace_dir);
let scoped = backend
- .for_scope(&Scope::local())
+ .for_scope(&super::scope::tenant_scope(None))
.map_err(|error| anyhow!("open the local scope: {error}"))?;
let docs = Arc::clone(scoped.documents());
let found = block_on(async move {
diff --git a/crates/openhuman-core/src/storage/import/snapshot.rs b/crates/openhuman-core/src/storage/import/snapshot.rs
index a6f1c253c2..c90e7deb75 100644
--- a/crates/openhuman-core/src/storage/import/snapshot.rs
+++ b/crates/openhuman-core/src/storage/import/snapshot.rs
@@ -76,7 +76,7 @@ impl Snapshot {
let storage = tinystoragedrivers::sqlite::SqliteStorage::open(&self.db)
.with_context(|| format!("open the copy {}", self.db.display()))?;
let scoped = storage
- .for_scope(&Scope::local())
+ .for_scope(&crate::storage::tenant_scope(None))
.context("open the local scope of the copy")?;
let docs = std::sync::Arc::clone(scoped.documents());
let specs = collections();
diff --git a/crates/openhuman-core/src/storage/import/tinyflows.rs b/crates/openhuman-core/src/storage/import/tinyflows.rs
index a70af0a59f..a2ef457db4 100644
--- a/crates/openhuman-core/src/storage/import/tinyflows.rs
+++ b/crates/openhuman-core/src/storage/import/tinyflows.rs
@@ -59,7 +59,12 @@ pub(super) fn marked(
body: impl FnOnce() -> Result<Option<(usize, usize, usize)>>,
) -> Result<Outcome> {
let marker = marker_id(domain, workspace);
- let markers = Repo::on(backend, &Scope::local(), "storage::import", marker_spec)?;
+ let markers = Repo::on(
+ backend,
+ &crate::storage::tenant_scope(None),
+ "storage::import",
+ marker_spec,
+ )?;
let id = marker.clone();
let done = markers
.run(move |docs| async move { docs.get(MARKER_COLLECTION, &id).await })?
@@ -287,7 +292,7 @@ pub fn run_with(backend: &Arc<dyn StorageBackend>, config: &Config) -> Vec<Repor
#[cfg(feature = "flows")]
reports.push(finish(
FLOWS_DOMAIN,
- import_flows(backend, &Scope::local(), config),
+ import_flows(backend, &crate::storage::tenant_scope(None), config),
));
#[cfg(not(feature = "flows"))]
if config.workspace_dir.join("flows").exists() {
@@ -298,7 +303,13 @@ pub fn run_with(backend: &Arc<dyn StorageBackend>, config: &Config) -> Vec<Repor
}
reports.push(finish(
CRON_DOMAIN,
- import_cron(backend, &Scope::local(), config, &config.workspace_dir, ""),
+ import_cron(
+ backend,
+ &crate::storage::tenant_scope(None),
+ config,
+ &config.workspace_dir,
+ "",
+ ),
));
for (agent, dir) in agent_cron_dirs(&config.workspace_dir) {
let scope = crate::storage::scope_for_agent(&agent);
diff --git a/crates/openhuman-core/src/storage/import/tinyflows_tests.rs b/crates/openhuman-core/src/storage/import/tinyflows_tests.rs
index 20237cdda2..04ac1e2e0a 100644
--- a/crates/openhuman-core/src/storage/import/tinyflows_tests.rs
+++ b/crates/openhuman-core/src/storage/import/tinyflows_tests.rs
@@ -186,7 +186,11 @@ fn cron_jobs_and_runs_come_across_with_their_fields() {
let before = tree(dir.path());
let backend = backend();
- let outcome = import_cron(&backend, &Scope::local(), &config, dir.path(), "").unwrap_or_else(|e| { eprintln!("ERR {e:#}"); panic!() });
+ let outcome =
+ import_cron(&backend, &Scope::local(), &config, dir.path(), "").unwrap_or_else(|e| {
+ eprintln!("ERR {e:#}");
+ panic!()
+ });
assert_eq!(written(outcome), 3 + 4);
let expected = expected()["cron"].clone();
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index d33ae03307..2afb018956 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -39,8 +39,8 @@ mod lease_local;
pub mod local;
pub mod rebind;
pub mod schema;
-pub mod scope_move;
pub mod scope;
+pub mod scope_move;
pub mod secrets;
pub use scope::{scope_for_agent, scope_for_module, scope_for_profile, tenant_scope};
diff --git a/crates/openhuman-core/src/storage/schema_tests.rs b/crates/openhuman-core/src/storage/schema_tests.rs
index fe71ce3cc3..21fa7416f6 100644
--- a/crates/openhuman-core/src/storage/schema_tests.rs
+++ b/crates/openhuman-core/src/storage/schema_tests.rs
@@ -12,7 +12,10 @@ fn every_owner_composes_without_collision() {
#[test]
fn module_items_are_the_owners_module_scoped_declarations() {
let mcp = module_items("mcp");
- assert!(mcp.collections.iter().any(|spec| spec.name == "mcp.servers"));
+ assert!(mcp
+ .collections
+ .iter()
+ .any(|spec| spec.name == "mcp.servers"));
assert!(mcp.streams.iter().any(|name| name == "mcp.audit"));
assert!(module_items("no-such-owner").collections.is_empty());
}
diff --git a/crates/openhuman-core/src/storage/scope.rs b/crates/openhuman-core/src/storage/scope.rs
index e570f583fd..823e164230 100644
--- a/crates/openhuman-core/src/storage/scope.rs
+++ b/crates/openhuman-core/src/storage/scope.rs
@@ -60,7 +60,10 @@ pub fn scope_for_agent(agent_id: &str) -> Scope {
/// # Errors
///
/// When `module_id` is empty.
-pub fn scope_for_module(profile: Option<&str>, module_id: &str) -> Result<Scope, super::StorageError> {
+pub fn scope_for_module(
+ profile: Option<&str>,
+ module_id: &str,
+) -> Result<Scope, super::StorageError> {
tenant_scope(profile).module(module_id)
}
diff --git a/crates/openhuman-core/src/storage/scope_move.rs b/crates/openhuman-core/src/storage/scope_move.rs
index e652ba9921..b14e708ca7 100644
--- a/crates/openhuman-core/src/storage/scope_move.rs
+++ b/crates/openhuman-core/src/storage/scope_move.rs
@@ -35,8 +35,8 @@ use std::sync::Arc;
use sha2::Digest;
use tinystoragedrivers::schema::Migrations;
use tinystoragedrivers::{
- Capability, DocumentStore, DocumentStoreExt, ErrorKind, Filter, Precondition, Query, Scope, ScopedStorage,
- StorageBackend, StorageError, WriteOptions,
+ Capability, DocumentStore, DocumentStoreExt, ErrorKind, Filter, Precondition, Query, Scope,
+ ScopedStorage, StorageBackend, StorageError, WriteOptions,
};
use super::scope::{scope_for_agent, scope_for_profile, tenant_scope};
@@ -214,7 +214,10 @@ async fn ids_of(
/// The first storage error. Nothing is lost: re-running resumes.
pub async fn run(backend: &Arc<dyn StorageBackend>) -> Result<MoveReport, StorageError> {
let mut report = MoveReport::default();
- if !backend.capabilities().contains(Capability::ScopeEnumeration) {
+ if !backend
+ .capabilities()
+ .contains(Capability::ScopeEnumeration)
+ {
tracing::debug!(
target: "openhuman::storage",
driver = backend.driver(),
diff --git a/crates/openhuman-core/src/storage/scope_move_tests.rs b/crates/openhuman-core/src/storage/scope_move_tests.rs
index 61aeb08f58..3bd1f06462 100644
--- a/crates/openhuman-core/src/storage/scope_move_tests.rs
+++ b/crates/openhuman-core/src/storage/scope_move_tests.rs
@@ -24,7 +24,10 @@ fn every_v1_shape_maps_to_a_v2_scope() {
assert_eq!(mapped("profile:alice"), "u:alice");
assert_eq!(mapped("alice~asha"), "u:alice/agent:asha");
assert_eq!(mapped("alice~default"), "u:alice/agent:default");
- assert_eq!(mapped("a%7Eb~asha"), format!("{}/agent:asha", scope_for_profile("a~b")));
+ assert_eq!(
+ mapped("a%7Eb~asha"),
+ format!("{}/agent:asha", scope_for_profile("a~b"))
+ );
assert_eq!(mapped("alice~module:tinymcp"), "u:alice/module:tinymcp");
assert_eq!(mapped("module:tinymcp@local"), "local/module:tinymcp");
assert_eq!(mapped("module:tinymcp@asha"), "local/module:tinymcp");
@@ -41,7 +44,13 @@ fn hashed_v1_scopes_map_through_known_ids_only() {
#[test]
fn v2_scopes_are_left_alone() {
- for scope in ["local", "u:alice", "u:alice/agent:x", "local/module:m", "cluster"] {
+ for scope in [
+ "local",
+ "u:alice",
+ "u:alice/agent:x",
+ "local/module:m",
+ "cluster",
+ ] {
assert_eq!(map_scope(scope, &known()), Mapping::V2, "{scope}");
}
}
@@ -49,14 +58,25 @@ fn v2_scopes_are_left_alone() {
#[tokio::test]
async fn a_v1_scope_moves_its_documents_streams_and_blobs() {
let backend: Arc<dyn StorageBackend> = Arc::new(MemoryStorage::new());
- let old = backend.for_scope(&Scope::new("alice~asha").unwrap()).unwrap();
+ let old = backend
+ .for_scope(&Scope::new("alice~asha").unwrap())
+ .unwrap();
old.documents()
.put("notes", "n1", json!({"a": 1}), Precondition::None)
.await
.unwrap();
- old.streams().append("journal", json!({"k": 1})).await.unwrap();
- old.streams().append("journal", json!({"k": 2})).await.unwrap();
- old.blobs().put("b/1", b"hi".to_vec(), Some("text/plain")).await.unwrap();
+ old.streams()
+ .append("journal", json!({"k": 1}))
+ .await
+ .unwrap();
+ old.streams()
+ .append("journal", json!({"k": 2}))
+ .await
+ .unwrap();
+ old.blobs()
+ .put("b/1", b"hi".to_vec(), Some("text/plain"))
+ .await
+ .unwrap();
let report = run(&backend).await.unwrap();
assert_eq!(report.moved, 1);
@@ -68,14 +88,21 @@ async fn a_v1_scope_moves_its_documents_streams_and_blobs() {
.for_scope(&scope_for_profile("alice").agent("asha").unwrap())
.unwrap();
assert_eq!(
- new.documents().get("notes", "n1").await.unwrap().unwrap().doc,
+ new.documents()
+ .get("notes", "n1")
+ .await
+ .unwrap()
+ .unwrap()
+ .doc,
json!({"a": 1})
);
assert_eq!(new.streams().len("journal").await.unwrap(), 2);
assert_eq!(new.blobs().get("b/1").await.unwrap().unwrap().bytes, b"hi");
// The v1 scope is gone and a second run is a no-op.
- let old = backend.for_scope(&Scope::new("alice~asha").unwrap()).unwrap();
+ let old = backend
+ .for_scope(&Scope::new("alice~asha").unwrap())
+ .unwrap();
assert!(old.documents().get("notes", "n1").await.unwrap().is_none());
assert_eq!(old.streams().len("journal").await.unwrap(), 0);
let again = run(&backend).await.unwrap();
@@ -98,7 +125,13 @@ async fn a_record_already_in_the_target_wins_a_merge() {
.unwrap();
run(&backend).await.unwrap();
assert_eq!(
- target.documents().get("notes", "n").await.unwrap().unwrap().doc,
+ target
+ .documents()
+ .get("notes", "n")
+ .await
+ .unwrap()
+ .unwrap()
+ .doc,
json!({"from": "v2"})
);
}