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
refactor(storage): update scope move logic and tests
Steven Enamakeld9a6257b8ee5
diff --git a/crates/openhuman-core/src/storage/scope_move.rs b/crates/openhuman-core/src/storage/scope_move.rsindex d45b547b4b..2dcd0008d4 100644--- a/crates/openhuman-core/src/storage/scope_move.rs+++ b/crates/openhuman-core/src/storage/scope_move.rs@@ -155,10 +155,11 @@ pub struct MoveReport {////// # Errors///-/// Fails closed on non-zero stream bases, expiring blobs (the blob port cannot-/// preserve an absolute expiry), malformed source data, or a target write-/// error. Re-running is idempotent for documents/blobs and verifies stream-/// prefixes before appending missing entries.+/// Fails closed on non-zero stream bases, timestamped seals, expiring blobs+/// (the target ports cannot preserve those source metadata fields), malformed+/// source data, or a target write error. Re-running is idempotent for+/// documents/blobs and verifies stream prefixes before appending missing+/// entries.#[cfg(feature = "legacy-import")]pub async fn copy_inventory(backend: &Arc<dyn StorageBackend>,@@ -196,12 +197,8 @@ pub async fn copy_inventory(docs.ensure_collection(&CollectionSpec::new(&row.collection)).await?;let mut options = WriteOptions::new();- if row.meta.schema != 0 {- options.schema = row.meta.schema;- }- if row.meta.created_ms != 0 {- options.created_ms = Some(row.meta.created_ms);- }+ options.schema = row.meta.schema;+ options.created_ms = Some(row.meta.created_ms);options.expires_ms = row.meta.expires_ms;match docs.put_with(@@ -228,6 +225,12 @@ pub async fn copy_inventory(row.name);}+ if row.sealed_ms.is_some() {+ bail!(+ "target stream port cannot preserve the seal timestamp for legacy stream {source}/{}",+ row.name+ );+ }let existing = streams.len(&row.name).await?;if existing > row.entries.len() as u64 {bail!(@@ -293,10 +296,9 @@ pub async fn copy_inventory(/// Reads an explicit SQLite source and copies its known legacy scopes.///-/// The caller should run the synchronous inventory read on a blocking worker-/// when this function is invoked from an async runtime. MongoDB and other-/// non-SQLite legacy sources need their own read-only inventory adapter; they-/// are not enumerated from the v2 target backend.+/// The synchronous inventory read runs on a blocking worker. MongoDB and+/// other non-SQLite legacy sources need their own read-only inventory adapter;+/// they are not enumerated from the v2 target backend.#[cfg(feature = "legacy-import")]pub async fn run_from_source(backend: &Arc<dyn StorageBackend>,diff --git a/crates/openhuman-core/src/storage/scope_move_tests.rs b/crates/openhuman-core/src/storage/scope_move_tests.rsindex 882db0a5f2..ad50c2bc22 100644--- a/crates/openhuman-core/src/storage/scope_move_tests.rs+++ b/crates/openhuman-core/src/storage/scope_move_tests.rs@@ -69,7 +69,12 @@ async fn a_v1_scope_moves_its_documents_streams_and_blobs() {collection: "notes".into(),id: "n1".into(),body: json!({"a": 1}),- meta: Meta::default(),+ meta: Meta {+ schema: 4,+ created_ms: 123,+ updated_ms: 456,+ expires_ms: None,+ },}],streams: vec![crate::storage::import::scope_move::LegacyStream {scope: source.into(),@@ -98,15 +103,10 @@ async fn a_v1_scope_moves_its_documents_streams_and_blobs() {let new = backend.for_scope(&scope_for_profile("alice").agent("asha").unwrap()).unwrap();- assert_eq!(- new.documents()- .get("notes", "n1")- .await- .unwrap()- .unwrap()- .doc,- json!({"a": 1})- );+ let copied = new.documents().get("notes", "n1").await.unwrap().unwrap();+ assert_eq!(copied.doc, json!({"a": 1}));+ assert_eq!(copied.meta.schema, 4);+ assert_eq!(copied.meta.created_ms, 123);assert_eq!(new.streams().len("journal").await.unwrap(), 2);assert_eq!(new.blobs().get("b/1").await.unwrap().unwrap().bytes, b"hi");@@ -156,3 +156,29 @@ async fn a_record_already_in_the_target_wins_a_merge() {json!({"from": "v2"}));}++#[tokio::test]+#[cfg(feature = "legacy-import")]+async fn a_timestamped_stream_refuses_a_lossy_move_before_copying_entries() {+ let backend: Arc<dyn StorageBackend> = Arc::new(MemoryStorage::new());+ let inventory = crate::storage::import::scope_move::LegacyScopeInventory {+ scopes: vec!["asha".into()],+ streams: vec![crate::storage::import::scope_move::LegacyStream {+ scope: "asha".into(),+ name: "journal".into(),+ base: 0,+ sealed: true,+ sealed_ms: Some(123),+ entries: vec![(0, json!({"entry": 1}))],+ }],+ ..Default::default()+ };++ let error = copy_inventory(&backend, &known(), &inventory)+ .await+ .unwrap_err();++ assert!(error.to_string().contains("seal timestamp"));+ let target = backend.for_scope(&scope_for_agent("asha")).unwrap();+ assert_eq!(target.streams().len("journal").await.unwrap(), 0);+}