Skip to content

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

test(flows): add session tests for runs adapter

Steven Enamakel30960fcf6ab5
diff --git a/crates/openhuman-core/src/flows/runs_adapter/session_tests.rs b/crates/openhuman-core/src/flows/runs_adapter/session_tests.rs
new file mode 100644
index 0000000000..6d98703059
--- /dev/null
+++ b/crates/openhuman-core/src/flows/runs_adapter/session_tests.rs
@@ -0,0 +1,111 @@
+use super::*;
+
+#[tokio::test]
+async fn private_agent_progress_advances_cursor_without_leaking_text_or_replaying_terminal() {
+ use crate::core::events::DomainEvent;
+ use async_trait::async_trait;
+ use std::sync::Mutex as StdMutex;
+ use tinybus::EventHandler;
+
+ #[derive(Default)]
+ struct Collector {
+ finished: Arc<StdMutex<Vec<(String, String)>>>,
+ progress: Arc<StdMutex<Vec<String>>>,
+ }
+
+ #[async_trait]
+ impl EventHandler<DomainEvent> for Collector {
+ fn name(&self) -> &str {
+ "test::flows::poll_run_projection_collector"
+ }
+
+ fn domains(&self) -> Option<&[&str]> {
+ Some(&["cron"])
+ }
+
+ async fn handle(&self, event: &DomainEvent) {
+ match event {
+ DomainEvent::FlowRunFinished { run_id, status, .. } => self
+ .finished
+ .lock()
+ .unwrap()
+ .push((run_id.clone(), status.clone())),
+ DomainEvent::FlowRunProgress { run_id, status, .. } => self
+ .progress
+ .lock()
+ .unwrap()
+ .push(format!("{run_id}:{status}")),
+ _ => {}
+ }
+ }
+ }
+
+ crate::core::bus::BUS.init().await.expect("bus init");
+ let collector = Arc::new(Collector::default());
+ let _subscription = crate::core::bus::BUS
+ .subscribe(Arc::clone(&collector))
+ .expect("subscriber installed");
+
+ let tmp = tempfile::TempDir::new().unwrap();
+ let config = Config {
+ workspace_dir: tmp.path().join("workspace"),
+ action_dir: tmp.path().join("workspace"),
+ config_path: tmp.path().join("config.toml"),
+ ..Config::default()
+ };
+ std::fs::create_dir_all(&config.workspace_dir).unwrap();
+ let run_id = format!("flow:projection:{}", uuid::Uuid::new_v4());
+ let flow = Flow {
+ id: format!("projection:{}", uuid::Uuid::new_v4()),
+ name: "Projection test".into(),
+ enabled: true,
+ graph: tinyflows::model::WorkflowGraph::default(),
+ created_at: "2026-01-01T00:00:00Z".into(),
+ updated_at: "2026-01-01T00:00:00Z".into(),
+ last_run_at: None,
+ last_status: None,
+ require_approval: false,
+ };
+ let ctx = crate::core::runtime::DispatchCtx::host_default();
+ let bindings = super::super::register_bindings(&ctx, &config, &flow, &run_id)
+ .await
+ .expect("scoped run callbacks registered");
+ let session = RunSession::new(bindings, Arc::new(config), flow, FlowRunTrigger::Rpc, 0);
+
+ let agent_progress = RunEvent {
+ seq: 1,
+ kind: "agent_progress".into(),
+ data: serde_json::json!({
+ "node_id": "agent-node",
+ "event_kind": "text_delta",
+ "text": "private agent output must stay off DomainEvent",
+ "agent_seq": 1
+ }),
+ graph_run_id: None,
+ };
+ assert!(session.consume(&agent_progress, true).await);
+ assert_eq!(session.cursor(), 1);
+ assert!(collector.progress.lock().unwrap().is_empty());
+
+ let finished = RunEvent {
+ seq: 2,
+ kind: "finished".into(),
+ data: serde_json::json!({
+ "status": "completed",
+ "successful": true,
+ "error": null,
+ "graph_run_id": null,
+ "output": {"ok": true},
+ "timed_out": false
+ }),
+ graph_run_id: None,
+ };
+ assert!(session.consume(&finished, true).await);
+ assert_eq!(session.cursor(), 2);
+ assert!(!session.consume(&finished, true).await);
+
+ let mut terminal_events = collector.finished.lock().unwrap().clone();
+ terminal_events.retain(|(id, _)| id == &run_id);
+ assert_eq!(terminal_events, [(run_id, "completed".into())]);
+ assert!(collector.progress.lock().unwrap().is_empty());
+}