The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(web_chat): update event bus tests for typed event API
Steven Enamakeld90f0ff93ac9
diff --git a/crates/openhuman-core/src/web_chat/event_bus_tests.rs b/crates/openhuman-core/src/web_chat/event_bus_tests.rsindex ddbb70a24d..aa36c7cbee 100644--- a/crates/openhuman-core/src/web_chat/event_bus_tests.rs+++ b/crates/openhuman-core/src/web_chat/event_bus_tests.rs@@ -287,8 +287,8 @@ async fn agent_surface_bridges_thread_goal_updated() {});let ev = find_agent_web_event(&mut web_rx, "thread_goal_updated", thread_id).await;- assert_eq!(ev.client_id, "");- assert_eq!(ev.goal, Some(goal));+ assert_eq!(ev.context().client_id, "");+ assert_eq!(wire(&ev)["goal"], goal);}/// `ThreadGoalCleared` bridges to `thread_goal_cleared`.@@ -304,7 +304,7 @@ async fn agent_surface_bridges_thread_goal_cleared() {});let ev = find_agent_web_event(&mut web_rx, "thread_goal_cleared", thread_id).await;- assert_eq!(ev.client_id, "");+ assert_eq!(ev.context().client_id, "");}/// `ThreadTodosChanged` bridges to `thread_todos_changed` carrying the todos@@ -323,7 +323,7 @@ async fn agent_surface_bridges_thread_todos_changed() {});let ev = find_agent_web_event(&mut web_rx, "thread_todos_changed", thread_id).await;- assert_eq!(ev.todos, Some(todos));+ assert_eq!(wire(&ev)["todos"], todos);}/// `RunQueueMessageQueued` bridges to `queue_item_queued` with the item's id@@ -344,7 +344,8 @@ async fn agent_surface_bridges_queue_item_queued() {});let ev = find_agent_web_event(&mut web_rx, "queue_item_queued", thread_id).await;- let item = ev.queue_item.expect("queue_item");+ let item: QueueItemPayload = serde_json::from_value(wire(&ev)["queue_item"].clone())+ .expect("queue_item");assert_eq!(item.id, "item-1");assert_eq!(item.text_preview, Some("hello".to_string()));}@@ -371,7 +372,7 @@ async fn agent_surface_skips_queue_item_queued_without_item_id() {thread_id: thread_id.to_string(),});let ev = find_agent_web_event(&mut web_rx, "thread_goal_cleared", thread_id).await;- assert_eq!(ev.thread_id, thread_id);+ assert_eq!(ev.context().thread_id, thread_id);}/// `RunQueueMessageDelivered` bridges to `queue_item_delivered` carrying the@@ -392,7 +393,8 @@ async fn agent_surface_bridges_queue_item_delivered_with_lane() {});let ev = find_agent_web_event(&mut web_rx, "queue_item_delivered", thread_id).await;- let item = ev.queue_item.expect("queue_item");+ let item: QueueItemPayload = serde_json::from_value(wire(&ev)["queue_item"].clone())+ .expect("queue_item");assert_eq!(item.id, "item-2");assert_eq!(item.lane, Some("collect".to_string()));}@@ -413,8 +415,8 @@ async fn agent_surface_bridges_run_mode_changed() {});let ev = find_agent_web_event(&mut web_rx, "run_mode_changed", thread_id).await;- assert_eq!(ev.client_id, "");- assert_eq!(ev.message, Some("plan".to_string()));+ assert_eq!(ev.context().client_id, "");+ assert_eq!(wire(&ev)["message"], "plan");}/// `ApprovalDecided` with both `thread_id`/`client_id` set bridges to@@ -438,11 +440,11 @@ async fn approval_surface_bridges_approval_decided_with_resolution() {});let ev = find_agent_web_event(&mut web_rx, "approval_decided", "thread-decided-1").await;- assert_eq!(ev.client_id, "client-decided-1");- assert_eq!(ev.request_id, "req-decided-1");- assert_eq!(ev.tool_call_id, Some("call-decided-1".to_string()));- assert_eq!(ev.cancel_reason, Some("expired".to_string()));- assert_eq!(ev.message, Some("deny".to_string()));+ assert_eq!(ev.context().client_id, "client-decided-1");+ assert_eq!(ev.context().request_id, "req-decided-1");+ assert_eq!(wire(&ev)["tool_call_id"], "call-decided-1");+ assert_eq!(wire(&ev)["cancel_reason"], "expired");+ assert_eq!(wire(&ev)["message"], "deny");}/// `ApprovalDecided` with no thread/client routing (a non-chat origin) is@@ -475,8 +477,8 @@ async fn approval_surface_drops_approval_decided_without_chat_routing() {loop {match web_rx.recv().await {Ok(ev)- if ev.event == "approval_decided"- && ev.request_id == "req-decided-no-route" =>+ if ev.event_name() == "approval_decided"+ && ev.context().request_id == "req-decided-no-route" =>{return Some(ev);}@@ -511,10 +513,10 @@ async fn plan_review_surface_bridges_plan_review_decided() {let ev =find_agent_web_event(&mut web_rx, "plan_review_decided", "thread-plan-decided-1").await;- assert_eq!(ev.client_id, "client-plan-decided-1");- assert_eq!(ev.tool_call_id, Some("call-plan-decided-1".to_string()));- assert_eq!(ev.cancel_reason, None);- assert_eq!(ev.message, Some("approve".to_string()));+ assert_eq!(ev.context().client_id, "client-plan-decided-1");+ assert_eq!(wire(&ev)["tool_call_id"], "call-plan-decided-1");+ assert!(wire(&ev).get("cancel_reason").is_none());+ assert_eq!(wire(&ev)["message"], "approve");}/// `publish_web_channel_event` stamps `ts` (epoch ms) when the caller left it@@ -550,20 +552,28 @@ async fn publish_web_channel_event_stamps_ts_when_unset() {async fn publish_web_channel_event_preserves_an_explicit_ts() {let mut web_rx = subscribe_web_channel_events();- publish_web_channel_event(WebChannelEvent {- event: "ts_stamp_probe_explicit".to_string(),- thread_id: "thread-ts-stamp-probe-explicit".to_string(),- ts: Some(123),- ..Default::default()+ publish_web_channel_event(WebChannelEvent::ChatDone {+ context: WebEventContext {+ client_id: "ts-probe".into(),+ thread_id: "thread-ts-stamp-probe-explicit".into(),+ request_id: "ts-probe".into(),+ seq: None,+ ts: Some(123),+ },+ full_response: None,+ citations: None,+ usage: None,+ timing: None,+ parts: None,});let ev = find_agent_web_event(&mut web_rx,- "ts_stamp_probe_explicit",+ "chat_done","thread-ts-stamp-probe-explicit",).await;- assert_eq!(ev.ts, Some(123));+ assert_eq!(ev.context().ts, Some(123));}/// A SaaS user's stream carries only events stamped with that user's agent:@@ -584,32 +594,54 @@ async fn published_events_carry_the_publishing_agent() {.profile("p-alice"),);CoreContext::scope(ctx, async {- publish_web_channel_event(WebChannelEvent {- event: "chat_done".into(),- thread_id: marker.clone(),- ..Default::default()+ publish_web_channel_event(WebChannelEvent::ChatDone {+ context: WebEventContext {+ client_id: String::new(),+ thread_id: marker.clone(),+ request_id: "agent-stamp".into(),+ ..WebEventContext::default()+ },+ full_response: None,+ citations: None,+ usage: None,+ timing: None,+ parts: None,});}).await;- publish_web_channel_event(WebChannelEvent {- event: "chat_done".into(),- thread_id: format!("{marker}-unscoped"),- ..Default::default()+ publish_web_channel_event(WebChannelEvent::ChatDone {+ context: WebEventContext {+ client_id: String::new(),+ thread_id: format!("{marker}-unscoped"),+ request_id: "agent-stamp-unscoped".into(),+ ..WebEventContext::default()+ },+ full_response: None,+ citations: None,+ usage: None,+ timing: None,+ parts: None,});let mut seen = Vec::new();while seen.len() < 2 {let ev = rx.recv().await.unwrap();- if ev.thread_id.starts_with(&marker) {+ if ev.context().thread_id.starts_with(&marker) {seen.push(ev);}}- let scoped = seen.iter().find(|e| e.thread_id == marker).unwrap();+ let scoped = seen+ .iter()+ .find(|e| e.context().thread_id == marker)+ .unwrap();assert!(scoped.belongs_to("u-alice"));assert!(!scoped.belongs_to("u-bob"));assert!(scoped.belongs_to_profile("p-alice"));assert!(!scoped.belongs_to_profile("p-bob"));- let unscoped = seen.iter().find(|e| e.thread_id != marker).unwrap();+ let unscoped = seen+ .iter()+ .find(|e| e.context().thread_id != marker)+ .unwrap();assert!(!unscoped.belongs_to("u-alice") && !unscoped.belongs_to_profile("p-alice"),"unstamped events belong to no user"