Skip to content

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

test(web_chat): use accessor methods for event fields

Steven Enamakel72758eb5e077
diff --git a/crates/openhuman-core/src/web_chat/ops/state_tests.rs b/crates/openhuman-core/src/web_chat/ops/state_tests.rs
index dbbdd48563..6f62824857 100644
--- a/crates/openhuman-core/src/web_chat/ops/state_tests.rs
+++ b/crates/openhuman-core/src/web_chat/ops/state_tests.rs
@@ -101,9 +101,9 @@ async fn a_user_cancel_under_the_fence_placeholder_id_keeps_the_callers_client()
loop {
match events.recv().await {
Ok(event)
- if event.event == "chat_cancelled" && event.thread_id == "fence-thread" =>
+ if event.event_name() == "chat_cancelled" && event.context().thread_id == "fence-thread" =>
{
- return event.client_id;
+ return event.context().client_id;
}
Ok(_) | Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
Err(error) => panic!("event stream closed: {error}"),
diff --git a/crates/openhuman-core/src/web_chat/presentation_tests.rs b/crates/openhuman-core/src/web_chat/presentation_tests.rs
index 23beca225a..3b09a3f0a2 100644
--- a/crates/openhuman-core/src/web_chat/presentation_tests.rs
+++ b/crates/openhuman-core/src/web_chat/presentation_tests.rs
@@ -22,7 +22,7 @@ fn single_bubble_delivery_emits_one_unsegmented_chat_done() {
let mut mine = Vec::new();
loop {
match rx.try_recv() {
- Ok(event) if event.request_id == request_id => mine.push(event),
+ Ok(event) if event.context().request_id == request_id => mine.push(event),
Ok(_) => continue,
Err(tokio::sync::broadcast::error::TryRecvError::Lagged(_)) => continue,
Err(_) => break,
@@ -80,7 +80,7 @@ async fn chat_done_carries_timing_when_a_snapshot_is_supplied() {
let done = loop {
match rx.try_recv() {
- Ok(event) if event.request_id == request_id && event.event == "chat_done" => {
+ Ok(event) if event.context().request_id == request_id && event.event_name() == "chat_done" => {
break event;
}
Ok(_) => continue,
@@ -121,7 +121,7 @@ async fn chat_done_omits_timing_when_no_snapshot_is_supplied() {
let done = loop {
match rx.try_recv() {
- Ok(event) if event.request_id == request_id && event.event == "chat_done" => {
+ Ok(event) if event.context().request_id == request_id && event.event_name() == "chat_done" => {
break event;
}
Ok(_) => continue,
diff --git a/crates/openhuman-core/src/web_chat/progress_tests.rs b/crates/openhuman-core/src/web_chat/progress_tests.rs
index 8fc119ad8f..4f8d4e43b8 100644
--- a/crates/openhuman-core/src/web_chat/progress_tests.rs
+++ b/crates/openhuman-core/src/web_chat/progress_tests.rs
@@ -615,8 +615,8 @@ mod tool_progress_tests {
.unwrap();
let event = recv_for_thread(&mut events, thread_id).await;
- assert_eq!(event.event, "tool_progress");
- assert_eq!(event.request_id, "req-tool-progress");
+ assert_eq!(event.event_name(), "tool_progress");
+ assert_eq!(event.context().request_id, "req-tool-progress");
assert_eq!(event.tool_call_id.as_deref(), Some("call-1"));
assert_eq!(
event.message.as_deref(),
diff --git a/crates/openhuman-core/src/web_chat/turn_events_tests.rs b/crates/openhuman-core/src/web_chat/turn_events_tests.rs
index 679dd936f4..2ab081fa25 100644
--- a/crates/openhuman-core/src/web_chat/turn_events_tests.rs
+++ b/crates/openhuman-core/src/web_chat/turn_events_tests.rs
@@ -38,7 +38,7 @@ async fn events_for(
let mut seen = Vec::new();
while seen.len() < count {
match rx.recv().await {
- Ok(event) if event.request_id == request_id => seen.push(event),
+ Ok(event) if event.context().request_id == request_id => seen.push(event),
Ok(_) | Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
Err(error) => panic!("bus closed: {error}"),
}
@@ -154,7 +154,7 @@ async fn a_stopped_turn_announces_cancelled_to_the_client_that_stopped_it() {
assert_eq!(seen[0].message.as_deref(), Some("Cancelled"));
assert_eq!(seen[1].event, "chat_cancelled");
assert_eq!(seen[1].cancel_reason.as_deref(), Some("user_stop"));
- assert!(seen.iter().all(|event| event.client_id == "stopper"));
+ assert!(seen.iter().all(|event| event.context().client_id == "stopper"));
}
#[tokio::test]
@@ -213,10 +213,10 @@ async fn a_queued_message_dropped_before_it_started_is_silent() {
loop {
match rx.recv().await {
Ok(event)
- if event.request_id == "events-queued"
- || event.request_id == "events-sibling" =>
+ if event.context().request_id == "events-queued"
+ || event.context().request_id == "events-sibling" =>
{
- return event.request_id;
+ return event.context().request_id;
}
Ok(_) | Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
Err(error) => panic!("bus closed: {error}"),
diff --git a/crates/openhuman-core/src/web_chat/turn_host_tests.rs b/crates/openhuman-core/src/web_chat/turn_host_tests.rs
index 82d055cfe1..df74be1af3 100644
--- a/crates/openhuman-core/src/web_chat/turn_host_tests.rs
+++ b/crates/openhuman-core/src/web_chat/turn_host_tests.rs
@@ -159,8 +159,8 @@ async fn the_heartbeat_beats_only_for_a_live_turn() {
tokio::time::sleep(Duration::from_secs(INFERENCE_HEARTBEAT_SECS + 1)).await;
let mut names = Vec::new();
while let Ok(event) = bus.try_recv() {
- if event.thread_id == "host-hb-thread" {
- names.push(event.event);
+ if event.context().thread_id == "host-hb-thread" {
+ names.push(event.event_name());
}
}
assert_eq!(names[0], "inference_start");
diff --git a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs
index cf601d2d82..e7d8735b74 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs
@@ -485,7 +485,7 @@ async fn chat_done_is_published_only_after_the_in_flight_slot_is_released() {
let request_id = start_parked_turn(thread_id, &block).await;
let mut events = crate::web_chat::subscribe_web_channel_events();
let is_done = |event: &crate::web_chat::WebChannelEvent| {
- event.event == "chat_done" && event.request_id == request_id
+ event.event_name() == "chat_done" && event.context().request_id == request_id
};
block.release.notify_one();
diff --git a/crates/openhuman-core/src/web_chat/web_tests_rate_limit_classification_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_rate_limit_classification_tests.rs
index b92edbebfc..cbe6312a11 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_rate_limit_classification_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_rate_limit_classification_tests.rs
@@ -201,10 +201,10 @@ async fn start_chat_chat_error_event_serializes_structured_fields_to_json_wire()
let recv = timeout(Duration::from_secs(20), async move {
loop {
let event = rx.recv().await.expect("event stream should stay open");
- if event.event != "chat_error" {
+ if event.event_name() != "chat_error" {
continue;
}
- if event.request_id != request_id {
+ if event.context().request_id != request_id {
continue;
}
return event;
@@ -296,10 +296,10 @@ async fn start_chat_emits_structured_rate_limit_metadata_on_chat_error_event() {
let recv = timeout(Duration::from_secs(20), async move {
loop {
let event = rx.recv().await.expect("event stream should stay open");
- if event.event != "chat_error" {
+ if event.event_name() != "chat_error" {
continue;
}
- if event.request_id != request_id {
+ if event.context().request_id != request_id {
continue;
}
return event;
diff --git a/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs
index 6229bc1e27..5328ebd95f 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_session_and_concurrency_tests.rs
@@ -675,8 +675,8 @@ async fn terminal_event(
) -> crate::web_chat::WebChannelEvent {
loop {
let event = rx.recv().await.expect("event stream should stay open");
- if event.request_id == request_id
- && matches!(event.event.as_str(), "chat_done" | "chat_error")
+ if event.context().request_id == request_id
+ && matches!(event.event_name(), "chat_done" | "chat_error")
{
return event;
}
@@ -685,7 +685,7 @@ async fn terminal_event(
/// A graceful, retryable `turn_timeout` whose user copy hides the marker.
fn assert_turn_timeout(event: &crate::web_chat::WebChannelEvent) {
- assert_eq!(event.event, "chat_error", "{event:?}");
+ assert_eq!(event.event_name(), "chat_error", "{event:?}");
assert_eq!(event.error_type.as_deref(), Some("turn_timeout"));
assert_eq!(event.error_retryable, Some(true));
let message = event.message.clone().unwrap_or_default();
diff --git a/crates/openhuman-core/src/web_chat/web_tests_start_chat_ingress_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_start_chat_ingress_tests.rs
index 63b1fe92b8..3641f2de77 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_start_chat_ingress_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_start_chat_ingress_tests.rs
@@ -136,10 +136,10 @@ async fn start_chat_emits_sanitized_chat_error_on_inference_failure() {
let recv = timeout(Duration::from_secs(20), async move {
loop {
let event = rx.recv().await.expect("event stream should stay open");
- if event.event != "chat_error" {
+ if event.event_name() != "chat_error" {
continue;
}
- if event.request_id != request_id {
+ if event.context().request_id != request_id {
continue;
}
return event;
diff --git a/crates/openhuman-core/src/web_chat/web_tests_turn_lifecycle_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_turn_lifecycle_tests.rs
index a74dd2ec72..710cafd312 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_turn_lifecycle_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_turn_lifecycle_tests.rs
@@ -29,7 +29,7 @@ async fn wait_for_event(
timeout(Duration::from_secs(10), async {
loop {
match rx.recv().await {
- Ok(event) if event.request_id == request_id && event.event == name => {
+ Ok(event) if event.context().request_id == request_id && event.event_name() == name => {
return event;
}
Ok(_) | Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
@@ -122,7 +122,7 @@ async fn queued_messages_dropped_with_their_turn_are_not_announced() {
wait_for_event(&mut rx, &primary, "chat_cancelled").await;
loop {
match rx.try_recv() {
- Ok(event) => assert_ne!(event.request_id, queued, "{}", event.event),
+ Ok(event) => assert_ne!(event.context().request_id, queued, "{}", event.event_name()),
Err(tokio::sync::broadcast::error::TryRecvError::Lagged(_)) => continue,
Err(_) => break,
}
@@ -157,7 +157,7 @@ async fn a_refused_message_publishes_no_turn_events() {
.any(|(k, _)| k == "lifecycle-refused")
);
while let Ok(event) = rx.try_recv() {
- assert_ne!(event.thread_id, "lifecycle-refused", "{}", event.event);
+ assert_ne!(event.context().thread_id, "lifecycle-refused", "{}", event.event_name());
}
}
@@ -222,7 +222,7 @@ async fn a_turn_with_an_unavailable_local_provider_ends_in_one_classified_chat_e
let error = match timeout(Duration::from_secs(75), async {
loop {
match rx.recv().await {
- Ok(event) if event.request_id == request_id && event.event == "chat_error" => {
+ Ok(event) if event.context().request_id == request_id && event.event_name() == "chat_error" => {
return event;
}
Ok(_) | Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
@@ -302,9 +302,9 @@ async fn a_turn_with_an_unavailable_local_provider_ends_in_one_classified_chat_e
);
let extra_terminal_events = std::iter::from_fn(|| rx.try_recv().ok())
.filter(|event| {
- event.request_id == request_id
+ event.context().request_id == request_id
&& matches!(
- event.event.as_str(),
+ event.event_name(),
"chat_done" | "chat_error" | "chat_cancelled"
)
})