Skip to content

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

test(orchestration): update completion tests for scoped router pool

Steven Enamakel81ab536a2620
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions_release_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_completions_release_tests.rs
index 218136c171..0a60cd3257 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_completions_release_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions_release_tests.rs
@@ -37,7 +37,9 @@ async fn release_all_closes_every_router_and_the_log_stays_replayable() {
assert!(release_all().await >= 1);
assert!(
- !state().routers.contains_key(w),
+ !state()
+ .stores
+ .contains_key(&super::router_scope(w)),
"the router (and its log handle) is dropped"
);
assert!(
@@ -78,7 +80,7 @@ async fn release_all_gives_up_waiting_after_the_drain_window() {
released >= 1,
"stragglers are dropped once the window passes"
);
- assert!(!state().routers.contains_key(w));
+ assert!(!state().stores.contains_key(&super::router_scope(w)));
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/agent/orchestration/completion_target_tests.rs b/crates/openhuman-core/src/agent/orchestration/completion_target_tests.rs
index f42594160d..3628c44627 100644
--- a/crates/openhuman-core/src/agent/orchestration/completion_target_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/completion_target_tests.rs
@@ -1,7 +1,9 @@
use std::path::Path;
use std::sync::Arc;
-use super::super::background_completions::{new_router, state, Entry};
+use super::super::background_completions::{
+ entry_for, router_pool, router_scope, state, test_store_overrides,
+};
use tinyagents_tasks::CompletionStore;
/// A temporary workspace that forgets its router when dropped, so the
@@ -27,19 +29,27 @@ impl Drop for TestWorkspace {
/// Register `store` as `workspace_dir`'s completion store, so a test can inject
/// one that fails.
pub(crate) fn install_store_for_test(workspace_dir: &Path, store: Arc<dyn CompletionStore>) {
- let entry = Arc::new(Entry {
- router: Arc::new(new_router(store.clone())),
- store,
- });
- state().routers.insert(workspace_dir.to_path_buf(), entry);
+ let scope = router_scope(workspace_dir);
+ test_store_overrides()
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .insert(scope, store);
+ router_pool().clear().expect("clear completion router pool");
+ let _ = entry_for(workspace_dir);
}
/// Forget everything this process knows about `workspace_dir`, as a restart
/// would: the router (and its open log handle) and every thread/session mapping
/// that points at it. The on-disk log is untouched.
pub(crate) fn forget_workspace_for_test(workspace_dir: &Path) {
+ let scope = router_scope(workspace_dir);
+ let _ = router_pool().clear();
+ test_store_overrides()
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .remove(&scope);
let mut st = state();
- st.routers.remove(workspace_dir);
+ st.stores.remove(&scope);
let gone: Vec<String> = st
.thread_workspaces
.iter()
@@ -51,7 +61,7 @@ pub(crate) fn forget_workspace_for_test(workspace_dir: &Path) {
st.stopped_threads.remove(&thread);
st.deleted_threads.remove(&thread);
}
- st.recovered_workspaces.remove(workspace_dir);
+ st.recovered_workspaces.remove(&scope);
st.session_threads.clear();
st.session_order.clear();
}