Skip to content

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

test: cover plan review replay and run mode event paths

Steven Enamakel35062071c9e8
diff --git a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
index 5b27510545..18a568503e 100644
--- a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
+++ b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
@@ -901,6 +901,34 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
});
});
+ it('clears a parked plan review when its decision event arrives', () => {
+ const listeners = renderProvider();
+ act(() => {
+ listeners.onPlanReviewRequest?.({
+ thread_id: 't-plan-decided',
+ request_id: 'pr-decided',
+ message: 'Ship the release',
+ args: { steps: ['build'] },
+ });
+ });
+ expect(
+ store.getState().chatRuntime.pendingPlanReviewByThread['t-plan-decided']?.requestId
+ ).toBe('pr-decided');
+
+ act(() => {
+ listeners.onPlanReviewDecided?.({
+ thread_id: 't-plan-decided',
+ request_id: 'pr-decided',
+ decision: 'reject',
+ resolution: 'cancelled',
+ });
+ });
+
+ expect(
+ store.getState().chatRuntime.pendingPlanReviewByThread['t-plan-decided']
+ ).toBeUndefined();
+ });
+
it('clears a parked plan review when the turn ends or errors', () => {
const listeners = renderProvider();
const park = () =>
diff --git a/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs b/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs
index a894409a8e..a277e2f606 100644
--- a/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs
+++ b/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs
@@ -3,6 +3,21 @@ use crate::plan_review::PlanReviewResolution;
use serde_json::json;
use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolRunContext};
+struct RunModeEventCollector(tokio::sync::mpsc::UnboundedSender<(String, String)>);
+
+#[async_trait::async_trait]
+impl tinybus::EventHandler<crate::core::events::DomainEvent> for RunModeEventCollector {
+ fn name(&self) -> &str {
+ "plan-exit-test"
+ }
+
+ async fn handle(&self, event: &crate::core::events::DomainEvent) {
+ if let crate::core::events::DomainEvent::ThreadRunModeChanged { thread_id, mode } = event {
+ let _ = self.0.send((thread_id.clone(), mode.clone()));
+ }
+ }
+}
+
struct ThreadContext(&'static str);
impl ToolRunContext for ThreadContext {
fn thread_id(&self) -> Option<&str> {
@@ -108,10 +123,10 @@ async fn plan_exit_emits_marker() {
#[tokio::test]
async fn plan_exit_publishes_build_run_mode_change() {
crate::core::bus::init().await.expect("bus init");
- let _handle = crate::core::bus::BUS.subscribe(std::sync::Arc::new(
- crate::web_chat::event_bus::AgentSurfaceSubscriber,
- ));
- let mut events = crate::web_chat::event_bus_channel::subscribe_web_channel_events();
+ let (tx, mut events) = tokio::sync::mpsc::unbounded_channel();
+ let _subscription = crate::core::bus::BUS
+ .subscribe(std::sync::Arc::new(RunModeEventCollector(tx)))
+ .expect("subscribe to core events");
let thread_id = "plan-exit-publishes-run-mode";
crate::threads::run_mode::set_mode(
&crate::core::runtime::DispatchCtx::ambient(),
@@ -132,17 +147,17 @@ async fn plan_exit_publishes_build_run_mode_change() {
let event = tokio::time::timeout(std::time::Duration::from_secs(1), async {
loop {
match events.recv().await {
- Ok(event) if event.event == "run_mode_changed" && event.thread_id == thread_id => {
+ Some((event_thread_id, mode)) if event_thread_id == thread_id && mode == "build" => {
break event;
}
- Ok(_) | Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
- Err(error) => panic!("run mode event stream ended: {error}"),
+ Some(_) => continue,
+ None => panic!("run mode event stream ended"),
}
}
})
.await
.expect("plan_exit must publish run_mode_changed");
- assert_eq!(event.args.unwrap()["mode"], "build");
+ assert_eq!(event, (thread_id.into(), "build".into()));
}
#[tokio::test]
diff --git a/crates/openhuman-rpc/src/server/socketio_tests.rs b/crates/openhuman-rpc/src/server/socketio_tests.rs
index cd6ae1d5e4..50c2c80cda 100644
--- a/crates/openhuman-rpc/src/server/socketio_tests.rs
+++ b/crates/openhuman-rpc/src/server/socketio_tests.rs
@@ -1,8 +1,18 @@
use super::{
channel_connection_update_payload, event_alias, origin_is_allowed_with_extra,
- publish_companion_state_changed, subscribe_companion_state_changed,
+ publish_companion_state_changed, socket_replay_tenant, subscribe_companion_state_changed,
};
+#[test]
+fn plan_review_replay_uses_the_joining_sockets_profile() {
+ let ambient = crate::core_host::core::runtime::Tenant {
+ profile: Some("ambient-profile".into()),
+ agent: None,
+ };
+ let actual = socket_replay_tenant(Some("socket-profile"), Ok(ambient)).unwrap();
+ assert_eq!(actual.profile.as_deref(), Some("socket-profile"));
+}
+
#[test]
fn companion_state_transport_delivers_payload_to_bridge() {
let mut rx = subscribe_companion_state_changed();