Skip to content

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

test(backend): add integration tests for channel routing and credential handling

Steven Enamakel31a93c3420f3
diff --git a/crates/openhuman-core/src/agent/progress_tracing/langfuse_batch_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/langfuse_batch_tests.rs
index e55c537c3e..3c0e487dac 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/langfuse_batch_tests.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/langfuse_batch_tests.rs
@@ -100,6 +100,49 @@ async fn push_spans_skips_external_without_a_session_or_a_request() {
);
}
+#[tokio::test]
+async fn api_key_credentials_are_not_used_for_langfuse_proxy_exports() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = Config::default();
+ config.config_path = dir.path().join("config.toml");
+ config.workspace_dir = dir.path().join("workspace");
+ config.secrets.encrypt = false;
+ config.api_url = Some("http://127.0.0.1:9".to_string());
+ crate::security::credentials::api_key::store_api_key(&config, "th_live_test").unwrap();
+
+ let spans = vec![span(
+ "trace:req-1",
+ "span-1",
+ None,
+ "agent.turn",
+ SpanKind::Turn,
+ SpanStatus::Ok,
+ 1_000,
+ Some(2_000),
+ )];
+ assert_eq!(push_spans(&config, &spans).await, Ok(()));
+
+ let ctx = TraceContext::new("trace:req-1", Some("user-1".to_string()));
+ let observations = vec![obs(
+ 1,
+ AgentEvent::ModelCompleted {
+ call_id: CallId::new("model-1"),
+ started_at_ms: Some(1_000),
+ usage: Some(Usage::new(10, 3)),
+ input: None,
+ output: None,
+ },
+ )];
+ assert!(!super::langfuse::journal_export::journal_push_ready(
+ &config
+ ));
+ assert_eq!(
+ super::langfuse::journal_export::push_observations(&config, &ctx, &observations, None)
+ .await,
+ Ok(())
+ );
+}
+
#[tokio::test]
async fn push_observations_skips_external_too() {
let mut config = Config::default();
diff --git a/crates/openhuman-core/src/backend/client_channel_tests.rs b/crates/openhuman-core/src/backend/client_channel_tests.rs
index faa36bf8cf..225a8cfff6 100644
--- a/crates/openhuman-core/src/backend/client_channel_tests.rs
+++ b/crates/openhuman-core/src/backend/client_channel_tests.rs
@@ -1,5 +1,125 @@
use super::*;
+#[tokio::test]
+async fn channel_routes_build_expected_requests_and_validate_inputs() {
+ type Requests = Arc<Mutex<Vec<(String, String, Value)>>>;
+ async fn capture(
+ State(seen): State<Requests>,
+ request: axum::http::Request<axum::body::Body>,
+ ) -> Json<Value> {
+ let method = request.method().to_string();
+ let path = request.uri().to_string();
+ let bytes = axum::body::to_bytes(request.into_body(), usize::MAX)
+ .await
+ .unwrap();
+ let body = if bytes.is_empty() {
+ Value::Null
+ } else {
+ serde_json::from_slice(&bytes).unwrap()
+ };
+ seen.lock().unwrap().push((method, path, body));
+ Json(json!({ "success": true, "data": { "ok": true } }))
+ }
+
+ let seen = Requests::default();
+ let app = Router::new().fallback(capture).with_state(seen.clone());
+ let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let addr = listener.local_addr().unwrap();
+ tokio::spawn(async move {
+ axum::serve(listener, app).await.unwrap();
+ });
+ let client = BackendClient::new(&format!("http://{addr}")).unwrap();
+
+ client
+ .send_channel_message(" /telegram/ ", "jwt", json!({ "text": "hello" }))
+ .await
+ .unwrap();
+ client
+ .send_channel_reaction("telegram", "jwt", json!({ "emoji": "👍" }))
+ .await
+ .unwrap();
+ client
+ .create_channel_thread("telegram", "jwt", " topic ")
+ .await
+ .unwrap();
+ client
+ .update_channel_thread("telegram", "jwt", "thread-1", "close")
+ .await
+ .unwrap();
+ client
+ .list_channel_threads("telegram", "jwt", Some(true))
+ .await
+ .unwrap();
+ client
+ .list_channel_threads("telegram", "jwt", Some(false))
+ .await
+ .unwrap();
+ client
+ .list_channel_threads("telegram", "jwt", None)
+ .await
+ .unwrap();
+
+ let requests = seen.lock().unwrap();
+ assert_eq!(
+ requests[0],
+ (
+ "POST".into(),
+ "/channels/telegram/messages".into(),
+ json!({ "text": "hello" })
+ )
+ );
+ assert_eq!(
+ requests[1],
+ (
+ "POST".into(),
+ "/channels/telegram/reactions".into(),
+ json!({ "emoji": "👍" })
+ )
+ );
+ assert_eq!(
+ requests[2],
+ (
+ "POST".into(),
+ "/channels/telegram/threads".into(),
+ json!({ "title": "topic" })
+ )
+ );
+ assert_eq!(
+ requests[3],
+ (
+ "PATCH".into(),
+ "/channels/telegram/threads/thread-1".into(),
+ json!({ "action": "close" })
+ )
+ );
+ assert_eq!(requests[4].1, "/channels/telegram/threads?active=true");
+ assert_eq!(requests[5].1, "/channels/telegram/threads?active=false");
+ assert_eq!(requests[6].1, "/channels/telegram/threads");
+ drop(requests);
+
+ assert!(client
+ .send_channel_message(" / ", "jwt", json!({}))
+ .await
+ .is_err());
+ assert!(client
+ .send_channel_reaction(" ", "jwt", json!({}))
+ .await
+ .is_err());
+ assert!(client
+ .create_channel_thread("telegram", "jwt", " ")
+ .await
+ .is_err());
+ assert!(client
+ .update_channel_thread("telegram", "jwt", " ", "close")
+ .await
+ .is_err());
+ assert!(client
+ .update_channel_thread("telegram", "jwt", "thread-1", "delete")
+ .await
+ .is_err());
+ assert!(client.list_channel_threads("", "jwt", None).await.is_err());
+}
+
#[tokio::test]
async fn authed_json_reports_non_channel_404_still_propagates() {
// TAURI-RUST-8C: a GET 404 on a non-channel path (e.g. `/teams/me/usage`)
diff --git a/crates/openhuman-core/src/flows/tinyflows/langfuse_export_tests.rs b/crates/openhuman-core/src/flows/tinyflows/langfuse_export_tests.rs
index 4ae352ca28..e59e857cd2 100644
--- a/crates/openhuman-core/src/flows/tinyflows/langfuse_export_tests.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/langfuse_export_tests.rs
@@ -198,6 +198,28 @@ async fn export_with_empty_observations_is_a_noop() {
.await;
}
+#[tokio::test]
+async fn export_skips_api_key_credentials() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = Config::default();
+ config.config_path = dir.path().join("config.toml");
+ config.workspace_dir = dir.path().join("workspace");
+ config.secrets.encrypt = false;
+ config.api_url = Some("http://127.0.0.1:9".to_string());
+ crate::security::credentials::api_key::store_api_key(&config, "th_live_test").unwrap();
+
+ export_flow_run_trace(
+ &config,
+ "Daily digest",
+ "flow-1",
+ "flow:flow-1:uuid-1",
+ "completed",
+ FlowRunTrigger::Rpc,
+ &sample_observations("flow:flow-1:uuid-1"),
+ )
+ .await;
+}
+
/// The re-typing hop is a serde round-trip between two independently
/// declared types, so nothing but a test notices when one of them grows,
/// renames, or re-tags a field: `to_exporter_observations` would start