Skip to content

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

refactor(storage): clean up schema support imports

Steven Enamakel220eb97e10cd
diff --git a/crates/openhuman-core/src/desktop/notifications/storage_schema.rs b/crates/openhuman-core/src/desktop/notifications/storage_schema.rs
index 78d206429a..de715531b0 100644
--- a/crates/openhuman-core/src/desktop/notifications/storage_schema.rs
+++ b/crates/openhuman-core/src/desktop/notifications/storage_schema.rs
@@ -18,8 +18,8 @@ use serde_json::Value;
use tinystoragedrivers::{CollectionSpec, IndexSpec};
use crate::storage::schema_support::{
- key_of, key_of_parts, map_legacy_collection, time_ms, Body, LegacySourceRecord as SourceRecord,
- LegacyTargetRecord as TargetRecord,
+ Body, LegacySourceRecord as SourceRecord, LegacyTargetRecord as TargetRecord, key_of,
+ key_of_parts, map_legacy_collection, time_ms,
};
pub(super) const NOTIFICATIONS: &str = "notifications.integration";
@@ -84,8 +84,7 @@ pub(super) fn legacy_collections() -> Vec<CollectionSpec> {
/// Never in practice: a two-part key is valid.
pub(super) fn core_id(workspace: &str, event_id: &str) -> String {
#[allow(clippy::expect_used)]
- key_of_parts([workspace, event_id])
- .expect("a two-part key is valid")
+ key_of_parts([workspace, event_id]).expect("a two-part key is valid")
}
fn integration_v2(batch: Vec<SourceRecord>) -> Result<Vec<TargetRecord>> {
diff --git a/crates/openhuman-core/src/integrations/task_sources/storage_schema.rs b/crates/openhuman-core/src/integrations/task_sources/storage_schema.rs
index 48e5a79f36..d81c6b8e36 100644
--- a/crates/openhuman-core/src/integrations/task_sources/storage_schema.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/storage_schema.rs
@@ -15,8 +15,8 @@ use serde_json::Value;
use tinystoragedrivers::{CollectionSpec, IndexSpec};
use crate::storage::schema_support::{
- key_of, key_of_parts, map_legacy_collection, time_ms, Body, LegacySourceRecord as SourceRecord,
- LegacyTargetRecord as TargetRecord,
+ Body, LegacySourceRecord as SourceRecord, LegacyTargetRecord as TargetRecord, key_of,
+ key_of_parts, map_legacy_collection, time_ms,
};
pub(super) const SOURCES: &str = "task_sources.sources";
@@ -61,8 +61,7 @@ pub(super) fn legacy_collections() -> Vec<CollectionSpec> {
/// Never in practice: a two-part key is valid.
pub(super) fn ingested_id(source_id: &str, external_id: &str) -> String {
#[allow(clippy::expect_used)]
- key_of_parts([source_id, external_id])
- .expect("a two-part key is valid")
+ key_of_parts([source_id, external_id]).expect("a two-part key is valid")
}
fn sources_v2(batch: Vec<SourceRecord>) -> Result<Vec<TargetRecord>> {
diff --git a/crates/openhuman-core/src/profiles/storage_schema.rs b/crates/openhuman-core/src/profiles/storage_schema.rs
index 73f4d8ce41..83053506e4 100644
--- a/crates/openhuman-core/src/profiles/storage_schema.rs
+++ b/crates/openhuman-core/src/profiles/storage_schema.rs
@@ -17,8 +17,8 @@ use serde_json::Value;
use tinystoragedrivers::{CollectionSpec, Storage};
use crate::storage::schema_support::{
- key_of, key_of_parts, map_legacy_collection, Body, LegacySourceRecord as SourceRecord,
- LegacyTargetRecord as TargetRecord,
+ Body, LegacySourceRecord as SourceRecord, LegacyTargetRecord as TargetRecord, key_of,
+ key_of_parts, map_legacy_collection,
};
/// The v2 collection: one document per profile.
diff --git a/crates/openhuman-core/src/profiles/storage_schema_tests.rs b/crates/openhuman-core/src/profiles/storage_schema_tests.rs
index 6ceb7a79a6..e0dc457e64 100644
--- a/crates/openhuman-core/src/profiles/storage_schema_tests.rs
+++ b/crates/openhuman-core/src/profiles/storage_schema_tests.rs
@@ -56,7 +56,7 @@ fn the_schema_composes_under_its_owner() {
#[tokio::test]
async fn migrate_cluster_moves_v1_leases_into_tsd_leases_and_keeps_their_epoch() {
- use crate::storage::lease::{DocumentLeases, LeaseStore, LEASE_OWNER};
+ use crate::storage::lease::{DocumentLeases, LEASE_OWNER, LeaseStore};
let backend = MemoryStorage::new();
let scoped = backend.for_scope(&Scope::cluster()).unwrap();
let docs = scoped.documents();
diff --git a/crates/openhuman-core/src/security/approval/gate_intercept.rs b/crates/openhuman-core/src/security/approval/gate_intercept.rs
index c1d5920cc3..b42eb894f0 100644
--- a/crates/openhuman-core/src/security/approval/gate_intercept.rs
+++ b/crates/openhuman-core/src/security/approval/gate_intercept.rs
@@ -621,7 +621,9 @@ impl ApprovalGate {
Err(resolution) => {
return (
GateOutcome::Deny {
- reason: format!("{POLICY_DENIED_MARKER} Agent approval registration closed: {resolution}"),
+ reason: format!(
+ "{POLICY_DENIED_MARKER} Agent approval registration closed: {resolution}"
+ ),
},
None,
);
@@ -633,7 +635,9 @@ impl ApprovalGate {
tracing::error!(error = %err, tool = tool_name, "[approval::gate] failed to persist pending row — failing closed");
return (
GateOutcome::Deny {
- reason: format!("{POLICY_DENIED_MARKER} Approval gate could not persist the request — denying for safety: {err}"),
+ reason: format!(
+ "{POLICY_DENIED_MARKER} Approval gate could not persist the request — denying for safety: {err}"
+ ),
},
None,
);
diff --git a/crates/openhuman-core/src/security/approval/storage_schema.rs b/crates/openhuman-core/src/security/approval/storage_schema.rs
index bac7825625..845e89a4ed 100644
--- a/crates/openhuman-core/src/security/approval/storage_schema.rs
+++ b/crates/openhuman-core/src/security/approval/storage_schema.rs
@@ -17,8 +17,8 @@ use serde_json::Value;
use tinystoragedrivers::{CollectionSpec, IndexSpec};
use crate::storage::schema_support::{
- key_of, key_of_parts, map_legacy_collection, time_ms, Body,
- LegacySourceRecord as SourceRecord, LegacyTargetRecord as TargetRecord,
+ Body, LegacySourceRecord as SourceRecord, LegacyTargetRecord as TargetRecord, key_of,
+ key_of_parts, map_legacy_collection, time_ms,
};
/// The v2 request collection: one document per request id.
@@ -74,8 +74,7 @@ pub(super) fn legacy_collections() -> Vec<CollectionSpec> {
/// refused.
pub(super) fn trust_id(flow_id: &str, tool_name: &str) -> String {
#[allow(clippy::expect_used)]
- key_of_parts([flow_id, tool_name])
- .expect("a two-part key is valid")
+ key_of_parts([flow_id, tool_name]).expect("a two-part key is valid")
}
fn requests_v2(batch: Vec<SourceRecord>) -> Result<Vec<TargetRecord>> {
diff --git a/crates/openhuman-core/src/security/approval/store_documents.rs b/crates/openhuman-core/src/security/approval/store_documents.rs
index 3f9557c22e..73226915a9 100644
--- a/crates/openhuman-core/src/security/approval/store_documents.rs
+++ b/crates/openhuman-core/src/security/approval/store_documents.rs
@@ -24,23 +24,21 @@
use std::sync::Arc;
-use anyhow::{anyhow, Context, Result};
+use anyhow::{Context, Result, anyhow};
use chrono::{DateTime, Utc};
-use serde_json::{json, Value};
+use serde_json::{Value, json};
use crate::config::Config;
use crate::storage::documents::compare_and_swap;
use crate::storage::local;
use crate::storage::schema_support::fresh_key;
-use crate::storage::{block_on, DocumentStore, DocumentStoreExt, Storage, StorageError};
-use tinystoragedrivers::{
- CollectionSpec, ErrorKind, Filter, Precondition, Query, Sort, Versioned,
-};
+use crate::storage::{DocumentStore, DocumentStoreExt, Storage, StorageError, block_on};
+use tinystoragedrivers::{CollectionSpec, ErrorKind, Filter, Precondition, Query, Sort, Versioned};
#[cfg(feature = "legacy-import")]
use super::storage_schema::legacy_collections;
use super::storage_schema::specs;
-pub(super) use super::storage_schema::{trust_id, APPROVALS, FLOW_TRUST};
+pub(super) use super::storage_schema::{APPROVALS, FLOW_TRUST, trust_id};
use super::types::{
ApprovalAuditEntry, ApprovalDecision, ApprovalSourceContext, ExecutionOutcome, PendingApproval,
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 1448115ef0..b95a5880e5 100644
--- a/crates/openhuman-core/src/security/approval/store_documents_tests.rs
+++ b/crates/openhuman-core/src/security/approval/store_documents_tests.rs
@@ -61,10 +61,12 @@ fn a_request_is_decided_exactly_once() {
store.get_decision("r").unwrap(),
Some(ApprovalDecision::ApproveOnce)
);
- assert!(store
- .decide("missing", ApprovalDecision::Deny)
- .unwrap()
- .is_none());
+ assert!(
+ store
+ .decide("missing", ApprovalDecision::Deny)
+ .unwrap()
+ .is_none()
+ );
assert!(store.list_pending().unwrap().is_empty());
}
@@ -142,18 +144,22 @@ fn execution_is_recorded_after_a_decision_and_only_once() {
);
store.decide("r", ApprovalDecision::ApproveOnce).unwrap();
let long = format!("token=sk-abcdefghijklmnopqrstuvwxyz {}", "e".repeat(800));
- assert!(store
- .record_execution("r", ExecutionOutcome::Failure, Some(&long))
- .unwrap());
+ assert!(
+ store
+ .record_execution("r", ExecutionOutcome::Failure, Some(&long))
+ .unwrap()
+ );
assert!(
!store
.record_execution("r", ExecutionOutcome::Success, None)
.unwrap(),
"the first outcome wins"
);
- assert!(!store
- .record_execution("missing", ExecutionOutcome::Success, None)
- .unwrap());
+ assert!(
+ !store
+ .record_execution("missing", ExecutionOutcome::Success, None)
+ .unwrap()
+ );
let stored = store
.run(|docs| async move { docs.get(APPROVALS, "r").await })
.unwrap()
@@ -269,10 +275,11 @@ fn scopes_keep_users_apart() {
alice.insert_pending(&pending("r", 0, None), "s").unwrap();
alice.insert_flow_trust("flow-1", "shell").unwrap();
assert!(bob.list_pending().unwrap().is_empty());
- assert!(bob
- .decide("r", ApprovalDecision::ApproveOnce)
- .unwrap()
- .is_none());
+ assert!(
+ bob.decide("r", ApprovalDecision::ApproveOnce)
+ .unwrap()
+ .is_none()
+ );
assert!(!bob.is_flow_tool_trusted("flow-1", "shell").unwrap());
assert_eq!(alice.list_pending().unwrap().len(), 1);
}
@@ -323,10 +330,12 @@ fn sub_second_timestamps_order_and_expire_on_time() {
let mut p = pending("late", 0, None);
p.expires_at = Some(due);
store.insert_pending(&p, "s").unwrap();
- assert!(store
- .expire_stale(whole + Duration::milliseconds(100))
- .unwrap()
- .is_empty());
+ assert!(
+ store
+ .expire_stale(whole + Duration::milliseconds(100))
+ .unwrap()
+ .is_empty()
+ );
assert_eq!(store.expire_stale(due).unwrap().len(), 1);
}
@@ -360,10 +369,12 @@ fn expiry_is_compared_in_epoch_milliseconds() {
let mut p = pending("tight", 0, None);
p.expires_at = Some(due);
store.insert_pending(&p, "s").unwrap();
- assert!(store
- .expire_stale(whole + Duration::milliseconds(2))
- .unwrap()
- .is_empty());
+ assert!(
+ store
+ .expire_stale(whole + Duration::milliseconds(2))
+ .unwrap()
+ .is_empty()
+ );
assert_eq!(store.expire_stale(due).unwrap().len(), 1);
}