Skip to content

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

test(web_chat): add test helper to lock thread sessions

Steven Enamakel6fc3193c484a
diff --git a/crates/openhuman-core/src/web_chat/mod.rs b/crates/openhuman-core/src/web_chat/mod.rs
index 30891f5f28..169c912fd9 100644
--- a/crates/openhuman-core/src/web_chat/mod.rs
+++ b/crates/openhuman-core/src/web_chat/mod.rs
@@ -75,6 +75,8 @@ pub use event_bus::fresh_approval_surface_subscription;
#[cfg(test)]
pub use ops::drain_queued_turns_for_test;
pub(crate) use ops::invalidate_thread_sessions_for_tenant;
+#[cfg(test)]
+pub(crate) use ops::lock_thread_sessions_for_test;
#[cfg(any(test, debug_assertions))]
pub use ops::parallel_in_flight_entries_for_test;
#[cfg(test)]
diff --git a/crates/openhuman-core/src/web_chat/ops.rs b/crates/openhuman-core/src/web_chat/ops.rs
index ed5d19e301..265248cf3c 100644
--- a/crates/openhuman-core/src/web_chat/ops.rs
+++ b/crates/openhuman-core/src/web_chat/ops.rs
@@ -31,6 +31,8 @@ pub use state::drain_queued_turns_for_test;
#[cfg(test)]
pub(crate) use state::in_flight;
pub(crate) use state::invalidate_thread_sessions_for_tenant;
+#[cfg(test)]
+pub(crate) use state::lock_thread_sessions_for_test;
#[cfg(any(test, debug_assertions))]
pub use state::parallel_in_flight_entries_for_test;
#[cfg(test)]
diff --git a/crates/openhuman-core/src/web_chat/ops/state.rs b/crates/openhuman-core/src/web_chat/ops/state.rs
index a2d694dc18..c57fbfb317 100644
--- a/crates/openhuman-core/src/web_chat/ops/state.rs
+++ b/crates/openhuman-core/src/web_chat/ops/state.rs
@@ -178,6 +178,12 @@ pub(crate) async fn invalidate_thread_sessions_for_tenant(
true
}
+/// Hold the real session table while exercising callback cancellation.
+#[cfg(test)]
+pub(crate) async fn lock_thread_sessions_for_test() -> impl Send + 'static {
+ thread_sessions().lock_owned().await
+}
+
/// The thread ids (as the caller chose them) with a primary or parallel turn
/// in the calling context's tables.
pub(crate) async fn live_thread_ids() -> Vec<String> {