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
test(memory): add coverage for bus, import, and sync paths
Steven Enamakel936f8fb2e207
diff --git a/crates/openhuman-core/src/memory/bus_tests.rs b/crates/openhuman-core/src/memory/bus_tests.rsindex 9a66de2cae..71218a741d 100644--- a/crates/openhuman-core/src/memory/bus_tests.rs+++ b/crates/openhuman-core/src/memory/bus_tests.rs@@ -28,13 +28,13 @@ async fn the_background_job_runs_the_due_queue() {).await;- run_system_job(&config, BACKGROUND_JOB).await;+ run_system_job(&crate::core::runtime::DispatchCtx::ambient(), &config, BACKGROUND_JOB).await;let queue = jobs::snapshot(&config).await;assert!(queue.pending.is_empty());assert_eq!(queue.history.len(), 1);- run_system_job(&config, "someone_elses_job").await;- run_system_job(&config, SOURCES_SYNC_JOB).await;+ run_system_job(&crate::core::runtime::DispatchCtx::ambient(), &config, "someone_elses_job").await;+ run_system_job(&crate::core::runtime::DispatchCtx::ambient(), &config, SOURCES_SYNC_JOB).await;}#[test]@@ -57,7 +57,7 @@ async fn a_sign_in_drains_the_deletions_queued_while_signed_out() {},);bind_reference(&config);- assert_eq!(drain_pending_deletions(&config, "session").await, 1);+ assert_eq!(drain_pending_deletions(&crate::core::runtime::DispatchCtx::ambient(), &config, "session").await, 1);assert!(pending(&config.workspace_dir).is_empty());}@@ -74,6 +74,6 @@ async fn the_background_job_retries_pending_deletions() {},);bind_reference(&config);- run_system_job(&config, BACKGROUND_JOB).await;+ run_system_job(&crate::core::runtime::DispatchCtx::ambient(), &config, BACKGROUND_JOB).await;assert!(pending(&config.workspace_dir).is_empty());}diff --git a/crates/openhuman-core/src/memory/import_tests.rs b/crates/openhuman-core/src/memory/import_tests.rsindex 509dc7748b..68306ff922 100644--- a/crates/openhuman-core/src/memory/import_tests.rs+++ b/crates/openhuman-core/src/memory/import_tests.rs@@ -64,7 +64,7 @@ fn a_credits_pause_blocks_organizing_until_resumed() {async fn starting_without_consent_is_refused_before_anything_runs() {let tmp = tempfile::tempdir().unwrap();let config = config_in(&tmp);- let error = start(&config, false).await.unwrap_err();+ let error = start(&crate::core::runtime::DispatchCtx::ambient(), &config, false).await.unwrap_err();assert!(error.to_string().contains("consent"), "{error}");assert!(!running(&config.workspace_dir));assert_eq!(status(&config).phase, ImportPhase::Idle);@@ -76,7 +76,7 @@ async fn retrying_with_nothing_failed_is_refused_and_releases_the_workspace() {let config = config_in(&tmp);// Either no engine is bound here or there is nothing to retry; either// way the call fails and the workspace must not stay claimed.- assert!(retry_failed(&config).await.is_err());+ assert!(retry_failed(&crate::core::runtime::DispatchCtx::ambient(), &config).await.is_err());assert!(!running(&config.workspace_dir));}@@ -85,7 +85,7 @@ async fn nothing_resumes_when_no_import_was_started() {let tmp = tempfile::tempdir().unwrap();let config = config_in(&tmp);let resumed =- resume_interrupted_with(&config, Arc::new(|| false), Arc::new(|_: &Config| true)).await;+ resume_interrupted_with(&crate::core::runtime::DispatchCtx::ambient(), &config, Arc::new(|| false), Arc::new(|_: &Config| true)).await;assert!(!resumed);}@@ -99,7 +99,7 @@ async fn a_paused_scheduler_leaves_an_interrupted_import_for_later() {.save(&file).unwrap();let resumed =- resume_interrupted_with(&config, Arc::new(|| true), Arc::new(|_: &Config| true)).await;+ resume_interrupted_with(&crate::core::runtime::DispatchCtx::ambient(), &config, Arc::new(|| true), Arc::new(|_: &Config| true)).await;assert!(!resumed);assert_eq!(read_file(&config.workspace_dir).state.phase,diff --git a/crates/openhuman-core/src/memory/layout_migration/service_tests.rs b/crates/openhuman-core/src/memory/layout_migration/service_tests.rsindex 830dd964db..9312181a66 100644--- a/crates/openhuman-core/src/memory/layout_migration/service_tests.rs+++ b/crates/openhuman-core/src/memory/layout_migration/service_tests.rs@@ -34,7 +34,7 @@ async fn scan_finds_legacy_memory_and_nothing_after_the_move() {shared: false});- assert!(start(config.clone(), host.clone(), Trigger::Auto, never()));+ assert!(start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));settle(&config).await;assert!(!scan(host.as_ref()).await.unwrap().needed);assert_eq!(status(&config).unwrap().state.phase, Phase::Cleaned);@@ -53,9 +53,9 @@ async fn one_run_per_workspace_at_a_time() {let tmp = tempfile::tempdir().unwrap();let config = crate::memory::test_fixtures::config_in(&tmp);let host = Arc::new(FakeHost::with(200, &config).await);- assert!(start(config.clone(), host.clone(), Trigger::Auto, never()));+ assert!(start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));assert!(- !start(config.clone(), host.clone(), Trigger::Auto, never()),+ !start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()),"a second start while one runs starts nothing");settle(&config).await;@@ -72,10 +72,10 @@ async fn a_stopped_run_reads_as_interrupted_and_a_tick_resumes_it() {state::save(&config.workspace_dir, &stopped).unwrap();assert!(status(&config).unwrap().interrupted);- assert!(tick(&config, host.clone(), never()));+ assert!(tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host.clone(), never()));settle(&config).await;assert_eq!(status(&config).unwrap().state.phase, Phase::Cleaned);- assert!(!tick(&config, host, never()), "nothing left to do");+ assert!(!tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host, never()), "nothing left to do");}#[tokio::test]@@ -94,8 +94,8 @@ async fn nothing_starts_while_an_import_is_unfinished() {).unwrap();assert!(crate::memory::import::in_progress(&config));- assert!(!start(config.clone(), host.clone(), Trigger::Auto, never()));- assert!(!tick(&config, host.clone(), never()));+ assert!(!start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));+ assert!(!tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host.clone(), never()));assert_eq!(count(host.tree.as_ref()).await, 0);std::fs::write(@@ -103,7 +103,7 @@ async fn nothing_starts_while_an_import_is_unfinished() {r#"{"state":{"phase":"done","total":3,"imported":3}}"#,).unwrap();- assert!(start(config.clone(), host.clone(), Trigger::Auto, never()));+ assert!(start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));settle(&config).await;assert_eq!(count(host.tree.as_ref()).await, 3);}@@ -113,7 +113,7 @@ async fn a_tick_starts_nothing_while_background_work_is_paused() {let tmp = tempfile::tempdir().unwrap();let config = crate::memory::test_fixtures::config_in(&tmp);let host = Arc::new(FakeHost::with(3, &config).await);- assert!(!tick(&config, host.clone(), Arc::new(|| true)));+ assert!(!tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host.clone(), Arc::new(|| true)));assert_eq!(count(host.tree.as_ref()).await, 0);}@@ -123,7 +123,7 @@ async fn retry_puts_a_lost_copy_back_in_line() {let config = crate::memory::test_fixtures::config_in(&tmp);let host = Arc::new(FakeHost::with(4, &config).await);host.free.store(true, Ordering::SeqCst);- assert!(start(config.clone(), host.clone(), Trigger::Auto, never()));+ assert!(start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));settle(&config).await;assert_eq!(status(&config).unwrap().state.phase, Phase::Cleaned);@@ -151,5 +151,5 @@ async fn a_damaged_state_file_surfaces_as_the_hosts_engine_error() {let error = status(&config).unwrap_err();assert_eq!(error.code(), "ENGINE");let host = Arc::new(FakeHost::with(1, &config).await);- assert!(!tick(&config, host, never()), "a torn state starts nothing");+ assert!(!tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host, never()), "a torn state starts nothing");}diff --git a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rsindex 71ed7ce97f..ce99697d9a 100644--- a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs+++ b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs@@ -453,7 +453,7 @@ async fn an_erase_retires_queued_automatic_work_and_allows_later_work() {);// The current-thread executor has not polled the earlier job. Erasure// advances the owner fence synchronously before its first suspension.- let fence = crate::memory::tool_writes::fence_and_clear(&config)+ let fence = crate::memory::tool_writes::fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config).await.unwrap();let new_count = later.clone();@@ -505,7 +505,7 @@ async fn erase_waits_for_current_automatic_work_before_returning_its_barrier() {let erase_config = config.clone();let mut fencing =tokio::spawn(- async move { crate::memory::tool_writes::fence_and_clear(&erase_config).await },+ async move { crate::memory::tool_writes::fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &erase_config).await },);assert!(tokio::time::timeout(Duration::from_secs(1), &mut fencing)diff --git a/crates/openhuman-core/src/memory/ops_tests.rs b/crates/openhuman-core/src/memory/ops_tests.rsindex dff2b012af..0f61bebb8e 100644--- a/crates/openhuman-core/src/memory/ops_tests.rs+++ b/crates/openhuman-core/src/memory/ops_tests.rs@@ -432,7 +432,7 @@ async fn erase_all_needs_its_confirmation() {let config = config_in(&tmp);let engine = bind_reference(&config);learn(&config, learn_params("a fact"), None).await.unwrap();- let error = erase_all(&config, EraseAllParams { confirm: false })+ let error = erase_all(&crate::core::runtime::DispatchCtx::ambient(), &config, EraseAllParams { confirm: false }).await.unwrap_err();assert_eq!(error.code(), INVALID_REQUEST);@@ -448,7 +448,7 @@ async fn erase_all_erases_everything_the_engine_holds() {learn(&config, learn_params("another fact"), None).await.unwrap();- let view = erase_all(&config, EraseAllParams { confirm: true })+ let view = erase_all(&crate::core::runtime::DispatchCtx::ambient(), &config, EraseAllParams { confirm: true }).await.unwrap();assert!(view.erased_scopes >= 1, "{view:?}");@@ -459,7 +459,7 @@ async fn erase_all_erases_everything_the_engine_holds() {async fn erase_all_reports_memory_off_without_an_engine() {let tmp = tempfile::tempdir().unwrap();let config = config_in(&tmp);- let error = erase_all(&config, EraseAllParams { confirm: true })+ let error = erase_all(&crate::core::runtime::DispatchCtx::ambient(), &config, EraseAllParams { confirm: true }).await.unwrap_err();assert_eq!(error.code(), MEMORY_OFF);@@ -481,7 +481,7 @@ async fn erasing_memory_cancels_queued_learning_so_restart_cannot_restore_it() {).unwrap();assert!(queued["status"].as_str().unwrap().starts_with("queued"));- erase_all(&config, EraseAllParams { confirm: true })+ erase_all(&crate::core::runtime::DispatchCtx::ambient(), &config, EraseAllParams { confirm: true }).await.unwrap();let restarted = config.clone();diff --git a/crates/openhuman-core/src/memory/sources/sync_tests.rs b/crates/openhuman-core/src/memory/sources/sync_tests.rsindex 70b4145a20..e60f322e8d 100644--- a/crates/openhuman-core/src/memory/sources/sync_tests.rs+++ b/crates/openhuman-core/src/memory/sources/sync_tests.rs@@ -118,7 +118,7 @@ async fn start_sync_walks_syncing_then_idle_and_records_items() {.sources.push(folder_source("src-ok", &dir, None));- let started = start_sync(&config, Some("src-ok")).unwrap();+ let started = start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, Some("src-ok")).unwrap();assert_eq!(started, vec!["src-ok".to_string()]);let done = wait_for_idle(&config, "src-ok").await;assert_eq!(done.status, SourceStatus::Idle);@@ -143,7 +143,7 @@ async fn a_failing_sync_lands_in_error_with_the_message() {.sources.push(folder_source("src-bad", &missing, None));- start_sync(&config, None).unwrap();+ start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, None).unwrap();let done = wait_for_idle(&config, "src-bad").await;assert_eq!(done.status, SourceStatus::Error);assert!(done.error.as_deref().is_some_and(|e| !e.is_empty()));@@ -155,16 +155,16 @@ fn start_sync_refuses_unknown_ids_and_memory_off() {let tmp = tempfile::tempdir().unwrap();let config = config_in(&tmp);assert_eq!(- start_sync(&config, None).unwrap_err().code(),+ start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, None).unwrap_err().code(),crate::memory::error::MEMORY_OFF);bind_reference(&config);assert_eq!(- start_sync(&config, Some("src-nope")).unwrap_err().code(),+ start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, Some("src-nope")).unwrap_err().code(),INVALID_REQUEST);assert!(- start_sync(&config, None).unwrap().is_empty(),+ start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, None).unwrap().is_empty(),"no sources, nothing started");}@@ -182,9 +182,9 @@ async fn a_source_already_syncing_is_not_started_twice() {// Hold a claim as a running sync would: a second request starts nothing.let held = syncer_for(&config).start(Some("src-once")).unwrap();assert_eq!(held.len(), 1);- assert!(start_sync(&config, Some("src-once")).unwrap().is_empty());+ assert!(start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, Some("src-once")).unwrap().is_empty());drop(held);- assert_eq!(start_sync(&config, Some("src-once")).unwrap().len(), 1);+ assert_eq!(start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, Some("src-once")).unwrap().len(), 1);wait_for_idle(&config, "src-once").await;}@@ -211,12 +211,12 @@ async fn sync_due_starts_only_scheduled_sources_that_are_due() {s.last_sync_at = Some(now);});- let started = sync_due(&config, now);+ let started = sync_due(&crate::core::runtime::DispatchCtx::ambient(), &config, now);assert_eq!(started, vec!["src-sched".to_string()]);wait_for_idle(&config, "src-sched").await;// Fifteen minutes later everything scheduled is due again; manual never is.- let later = sync_due(&config, now + chrono::Duration::minutes(16));+ let later = sync_due(&crate::core::runtime::DispatchCtx::ambient(), &config, now + chrono::Duration::minutes(16));assert!(later.contains(&"src-sched".to_string()));assert!(later.contains(&"src-fresh".to_string()));assert!(!later.contains(&"src-manual".to_string()));@@ -232,7 +232,7 @@ fn sync_due_with_memory_off_starts_nothing() {.memory.sources.push(folder_source("s", tmp.path(), Some(15)));- assert!(sync_due(&config, Utc::now()).is_empty());+ assert!(sync_due(&crate::core::runtime::DispatchCtx::ambient(), &config, Utc::now()).is_empty());}#[test]diff --git a/crates/openhuman-core/src/memory/tool_writes_tests.rs b/crates/openhuman-core/src/memory/tool_writes_tests.rsindex 3818786613..b934946063 100644--- a/crates/openhuman-core/src/memory/tool_writes_tests.rs+++ b/crates/openhuman-core/src/memory/tool_writes_tests.rs@@ -392,7 +392,7 @@ async fn an_erase_fence_clears_prior_pending_learnings_across_restart() {&facts(&config),).unwrap();- let fence = fence_and_clear(&config).await.unwrap();+ let fence = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config).await.unwrap();assert!(read(&config.workspace_dir).unwrap().is_empty());drop(fence);let restarted = config_in(&tmp);@@ -424,10 +424,10 @@ async fn an_erase_fence_waits_for_only_the_current_write_and_preserves_later_enq&facts(&config),).unwrap();- schedule(Arc::new(config.clone()), &Namespace::ROOT);+ schedule(&crate::core::runtime::DispatchCtx::ambient(), Arc::new(config.clone()), &Namespace::ROOT);engine.entered.notified().await;let fence_config = config.clone();- let fencing = tokio::spawn(async move { fence_and_clear(&fence_config).await });+ let fencing = tokio::spawn(async move { fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &fence_config).await });let state = owner_state(&config);while !state.gate.is_fenced() {tokio::task::yield_now().await;@@ -458,7 +458,7 @@ async fn an_erase_fence_waits_for_only_the_current_write_and_preserves_later_enq&facts(&config),).unwrap();- schedule(Arc::new(config.clone()), &Namespace::ROOT);+ schedule(&crate::core::runtime::DispatchCtx::ambient(), Arc::new(config.clone()), &Namespace::ROOT);assert_eq!(read(&config.workspace_dir).unwrap().len(), 2);drop(fence);drain(&config).await;@@ -491,7 +491,7 @@ async fn separate_owner_roots_share_a_workspace_without_blocking_or_erasing_each&facts(&second),).unwrap();- let fence = fence_and_clear(&first).await.unwrap();+ let fence = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &first).await.unwrap();assert_eq!(drain(&second).await,1,@@ -524,7 +524,7 @@ async fn erasing_one_owner_fences_pending_writes_from_every_team_root() {&facts(&second),).unwrap();- let fence = fence_and_clear(&first).await.unwrap();+ let fence = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &first).await.unwrap();assert!(read_at(&queue_path(&first, &facts(&first).reach.at)).unwrap().is_empty());@@ -542,7 +542,7 @@ async fn erasing_one_owner_fences_pending_writes_from_every_team_root() {async fn a_later_erase_clears_pending_writes_admitted_during_the_first_erase() {let tmp = tempfile::tempdir().unwrap();let config = config_in(&tmp);- let first = fence_and_clear(&config).await.unwrap();+ let first = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config).await.unwrap();enqueue(&config,&json!({"action":"learn","text":"Queued after the first erase began"}),@@ -550,7 +550,7 @@ async fn a_later_erase_clears_pending_writes_admitted_during_the_first_erase() {).unwrap();drop(first);- let second = fence_and_clear(&config).await.unwrap();+ let second = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config).await.unwrap();assert!(read(&config.workspace_dir).unwrap().is_empty(),"the second erase must discard a learning admitted before it started"