Skip to content

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

test(plan_review): assert decision events for timeout and cancellation

Steven Enamakelb1a995e9d624
diff --git a/crates/openhuman-core/src/plan_review/gate_tests.rs b/crates/openhuman-core/src/plan_review/gate_tests.rs
index b4df1d4c4d..95e5f27d38 100644
--- a/crates/openhuman-core/src/plan_review/gate_tests.rs
+++ b/crates/openhuman-core/src/plan_review/gate_tests.rs
@@ -1,5 +1,31 @@
use super::*;
+struct DecisionCollector(tokio::sync::mpsc::UnboundedSender<(String, Option<String>)>);
+
+#[async_trait::async_trait]
+impl tinybus::EventHandler<crate::core::events::DomainEvent> for DecisionCollector {
+ fn name(&self) -> &str {
+ "plan-review-gate-test"
+ }
+
+ async fn handle(&self, event: &crate::core::events::DomainEvent) {
+ if let crate::core::events::DomainEvent::PlanReviewDecided { decision, resolution, .. } = event {
+ let _ = self.0.send((decision.clone(), resolution.clone()));
+ }
+ }
+}
+
+async fn decision_events() -> (
+ impl Drop,
+ tokio::sync::mpsc::UnboundedReceiver<(String, Option<String>)>,
+) {
+ crate::core::bus::init().await.expect("bus init");
+ let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
+ let handle = crate::core::bus::BUS.subscribe(std::sync::Arc::new(DecisionCollector(tx)))
+ .expect("subscribe to core events");
+ (handle, rx)
+}
+
fn tenant() -> crate::core::runtime::Tenant {
crate::core::runtime::Tenant::default()
}
@@ -59,6 +85,7 @@ async fn revise_carries_feedback_back() {
#[tokio::test]
async fn timeout_fails_closed_to_reject() {
+ let (_subscription, mut decisions) = decision_events().await;
let gate = PlanReviewGate::new(Duration::from_millis(40));
let resolution = gate
.request_review(
@@ -71,10 +98,33 @@ async fn timeout_fails_closed_to_reject() {
)
.await;
assert_eq!(resolution, PlanReviewResolution::Reject);
+ assert_eq!(decisions.recv().await, Some(("reject".into(), Some("expired".into()))));
// The waiter is cleaned up after timeout.
assert!(!gate.decide_by_thread(&tenant(), "t3", PlanReviewResolution::Approve));
}
+#[tokio::test]
+async fn cancelled_park_publishes_cancelled_decision() {
+ let (_subscription, mut decisions) = decision_events().await;
+ let gate = std::sync::Arc::new(PlanReviewGate::new(Duration::from_secs(30)));
+ let g2 = gate.clone();
+ let handle = tokio::spawn(async move {
+ g2.request_review(
+ tenant(), Some("t-cancel-event".into()), Some("client-cancel".into()),
+ "Plan".into(), vec![], None,
+ ).await
+ });
+ tokio::time::sleep(Duration::from_millis(20)).await;
+ handle.abort();
+ let _ = handle.await;
+
+ assert_eq!(
+ tokio::time::timeout(Duration::from_secs(1), decisions.recv()).await.unwrap(),
+ Some(("reject".into(), Some("cancelled".into()))),
+ "cancelling a parked review must tell the frontend to clear its card"
+ );
+}
+
#[tokio::test]
async fn decide_unknown_request_is_false() {
let gate = PlanReviewGate::new(Duration::from_secs(5));