Skip to content

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

test(web_chat): add tests for artifact surface bridging tool_call_id and request_id

Steven Enamakelda49eecc44e6
diff --git a/crates/openhuman-core/src/web_chat/event_bus_tests.rs b/crates/openhuman-core/src/web_chat/event_bus_tests.rs
index ec41760f3d..080119283d 100644
--- a/crates/openhuman-core/src/web_chat/event_bus_tests.rs
+++ b/crates/openhuman-core/src/web_chat/event_bus_tests.rs
@@ -132,3 +132,119 @@ async fn egress_surface_drops_pending_without_chat_context() {
}
}
}
+
+/// Drain the web-channel receiver until an event of the given name whose
+/// `args.artifact_id` matches `marker` arrives.
+async fn find_artifact_web_event(
+ rx: &mut broadcast::Receiver<WebChannelEvent>,
+ event_name: &str,
+ marker: &str,
+) -> WebChannelEvent {
+ loop {
+ match rx.recv().await {
+ Ok(ev)
+ if ev.event == event_name
+ && ev
+ .args
+ .as_ref()
+ .and_then(|a| a.get("artifact_id"))
+ .and_then(|s| s.as_str())
+ == Some(marker) =>
+ {
+ return ev;
+ }
+ Ok(_) => continue,
+ Err(broadcast::error::RecvError::Lagged(_)) => continue,
+ Err(broadcast::error::RecvError::Closed) => {
+ panic!("web-channel bus closed before {event_name} arrived")
+ }
+ }
+ }
+}
+
+/// `ArtifactPending`/`Ready`/`Failed` carry `tool_call_id`/`request_id`
+/// (C5, correlating a generated artifact card with the tool-call bubble
+/// that produced it). The artifact-surface subscriber must bridge both onto
+/// `WebChannelEvent.tool_call_id` / `.turn_request_id` for every one of the
+/// three lifecycle events.
+#[tokio::test]
+async fn artifact_surface_bridges_tool_call_id_and_request_id() {
+ crate::core::bus::init().await.expect("bus init");
+ let _handle = crate::core::bus::BUS.subscribe(Arc::new(ArtifactSurfaceSubscriber));
+ let mut web_rx = subscribe_web_channel_events();
+
+ let pending_id = "artifact-corr-pending";
+ crate::core::bus::BUS.publish(DomainEvent::ArtifactPending {
+ artifact_id: pending_id.to_string(),
+ kind: "image".to_string(),
+ title: "A cat".to_string(),
+ workspace_dir: "/tmp/ws".to_string(),
+ path: format!("{pending_id}/a-cat.png"),
+ thread_id: Some("thread-1".to_string()),
+ client_id: Some("client-1".to_string()),
+ tool_call_id: Some("call-1".to_string()),
+ request_id: Some("req-1".to_string()),
+ });
+ let ev = find_artifact_web_event(&mut web_rx, "artifact_pending", pending_id).await;
+ assert_eq!(ev.tool_call_id, Some("call-1".to_string()));
+ assert_eq!(ev.turn_request_id, Some("req-1".to_string()));
+
+ let ready_id = "artifact-corr-ready";
+ crate::core::bus::BUS.publish(DomainEvent::ArtifactReady {
+ artifact_id: ready_id.to_string(),
+ kind: "image".to_string(),
+ title: "A cat".to_string(),
+ workspace_dir: "/tmp/ws".to_string(),
+ path: format!("{ready_id}/a-cat.png"),
+ size_bytes: 42,
+ thread_id: Some("thread-1".to_string()),
+ client_id: Some("client-1".to_string()),
+ tool_call_id: Some("call-2".to_string()),
+ request_id: Some("req-2".to_string()),
+ });
+ let ev = find_artifact_web_event(&mut web_rx, "artifact_ready", ready_id).await;
+ assert_eq!(ev.tool_call_id, Some("call-2".to_string()));
+ assert_eq!(ev.turn_request_id, Some("req-2".to_string()));
+
+ let failed_id = "artifact-corr-failed";
+ crate::core::bus::BUS.publish(DomainEvent::ArtifactFailed {
+ artifact_id: failed_id.to_string(),
+ kind: "image".to_string(),
+ title: "A cat".to_string(),
+ workspace_dir: "/tmp/ws".to_string(),
+ error: "provider timeout".to_string(),
+ thread_id: Some("thread-1".to_string()),
+ client_id: Some("client-1".to_string()),
+ tool_call_id: Some("call-3".to_string()),
+ request_id: Some("req-3".to_string()),
+ });
+ let ev = find_artifact_web_event(&mut web_rx, "artifact_failed", failed_id).await;
+ assert_eq!(ev.tool_call_id, Some("call-3".to_string()));
+ assert_eq!(ev.turn_request_id, Some("req-3".to_string()));
+}
+
+/// A producer that ran outside a harness tool-call context (CLI, cron)
+/// carries `tool_call_id: None` — the bridged event must not fabricate one.
+#[tokio::test]
+async fn artifact_surface_leaves_tool_call_id_none_when_absent() {
+ crate::core::bus::init().await.expect("bus init");
+ let _handle = crate::core::bus::BUS.subscribe(Arc::new(ArtifactSurfaceSubscriber));
+ let mut web_rx = subscribe_web_channel_events();
+
+ let ready_id = "artifact-corr-no-call-id";
+ crate::core::bus::BUS.publish(DomainEvent::ArtifactReady {
+ artifact_id: ready_id.to_string(),
+ kind: "document".to_string(),
+ title: "A doc".to_string(),
+ workspace_dir: "/tmp/ws".to_string(),
+ path: format!("{ready_id}/a-doc.docx"),
+ size_bytes: 7,
+ thread_id: Some("thread-1".to_string()),
+ client_id: Some("client-1".to_string()),
+ tool_call_id: None,
+ request_id: None,
+ });
+ let ev = find_artifact_web_event(&mut web_rx, "artifact_ready", ready_id).await;
+ assert_eq!(ev.tool_call_id, None);
+ assert_eq!(ev.turn_request_id, None);
+}