Skip to content

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

test(threads): add snapshot hook to purge for testing

Steven Enamakel30347da722bf
diff --git a/crates/openhuman-core/src/threads/ops.rs b/crates/openhuman-core/src/threads/ops.rs
index acdbe92188..9ee2c9a38e 100644
--- a/crates/openhuman-core/src/threads/ops.rs
+++ b/crates/openhuman-core/src/threads/ops.rs
@@ -27,6 +27,8 @@ pub use live_state::{
goal_get, todos_get, ThreadGoalGetResponse, ThreadLiveStateRequest, ThreadTodosGetResponse,
};
pub use purge::threads_purge;
+#[cfg(test)]
+pub(crate) use purge::threads_purge_inner_with_snapshot_hook;
pub use search::{thread_search, ThreadSearchHit, ThreadSearchRequest, ThreadSearchResponse};
pub use title_generation::thread_generate_title;
pub use transcript::{transcript_get, TranscriptGetRequest};
diff --git a/crates/openhuman-core/src/threads/ops/purge.rs b/crates/openhuman-core/src/threads/ops/purge.rs
index 7c2c834827..08b176ea17 100644
--- a/crates/openhuman-core/src/threads/ops/purge.rs
+++ b/crates/openhuman-core/src/threads/ops/purge.rs
@@ -24,10 +24,23 @@ async fn threads_purge_inner(
ctx: DispatchCtx,
dir: PathBuf,
) -> Result<Outcome<ApiEnvelope<PurgeConversationThreadsResponse>>, String> {
+ threads_purge_inner_with_snapshot_hook(ctx, dir, || async {}).await
+}
+
+pub(crate) async fn threads_purge_inner_with_snapshot_hook<F, Fut>(
+ ctx: DispatchCtx,
+ dir: PathBuf,
+ after_snapshot: F,
+) -> Result<Outcome<ApiEnvelope<PurgeConversationThreadsResponse>>, String>
+where
+ F: FnOnce() -> Fut + Send,
+ Fut: std::future::Future<Output = ()> + Send,
+{
// Capture and fence the parents before deleting their rows. The owner
// index is keyed by thread, and the permanent fence prevents another child
// from being admitted while the purge settles the jobs already running.
let threads = conversations::blocking::list_threads(ctx.clone(), dir.clone()).await?;
+ after_snapshot().await;
let thread_ids = threads
.into_iter()
.map(|thread| thread.id)