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
docs(webhooks): add README and test files for webhook schemas and operations
Steven Enamakel9e74397960ec
diff --git a/crates/openhuman-tinyhumans/src/hosted/webhooks/README.md b/crates/openhuman-tinyhumans/src/hosted/webhooks/README.mdnew file mode 100644index 0000000000..32ee26b80f--- /dev/null+++ b/crates/openhuman-tinyhumans/src/hosted/webhooks/README.md@@ -0,0 +1,24 @@+# webhooks (hosted)++Backend-managed webhook tunnels, on the TinyHumans SDK's typed `webhooks()`+client (`/webhooks/core*`). A thin, stateless RPC adapter: the backend owns+tunnel provisioning, ownership and bandwidth quotas.++| Method | Inputs | Backend call |+| --- | --- | --- |+| `webhooks_list_tunnels` | none | `GET /webhooks/core` |+| `webhooks_create_tunnel` | `name`, `description?` | `POST /webhooks/core` |+| `webhooks_get_tunnel` | `id` | `GET /webhooks/core/{id}` |+| `webhooks_update_tunnel` | `id`, `name?`, `description?`, `isActive?` | `PATCH /webhooks/core/{id}` |+| `webhooks_delete_tunnel` | `id` | `DELETE /webhooks/core/{id}` |+| `webhooks_get_bandwidth` | none | `GET /webhooks/core/bandwidth` |++The `webhooks` namespace is shared with the core: the local webhook router+(`crates/openhuman-core/src/skills/webhooks/` — `list_registrations`,+`register_echo`, `register_agent`, `trigger_agent`, the debug log ring) stays+in the core because it routes inbound deliveries to skills and agents and+needs no TinyHumans account. These six arrive with+`openhuman_tinyhumans::install` and are absent from a core without it.++Credentials, error mapping and the no-account short-circuit come from+`hosted::client::HostedClient` (see `../client.rs`).diff --git a/crates/openhuman-tinyhumans/src/hosted/webhooks/ops_tests.rs b/crates/openhuman-tinyhumans/src/hosted/webhooks/ops_tests.rsnew file mode 100644index 0000000000..bf5cc314ef--- /dev/null+++ b/crates/openhuman-tinyhumans/src/hosted/webhooks/ops_tests.rs@@ -0,0 +1,150 @@+use super::*;+use crate::hosted::test_support;+use openhuman_core::core::observability::expected_error_kind;+use serde_json::json;+use tempfile::TempDir;+use wiremock::matchers::{body_json, header, method, path};+use wiremock::{Mock, MockServer, ResponseTemplate};++fn ok(data: Value) -> ResponseTemplate {+ ResponseTemplate::new(200).set_body_json(json!({"success": true, "data": data}))+}++// ── validation runs before the credential ─────────────────────++#[tokio::test]+async fn create_tunnel_rejects_empty_or_whitespace_name() {+ let tmp = TempDir::new().unwrap();+ let config = test_support::config(&tmp, "http://127.0.0.1:9");+ for name in ["", " "] {+ let err = create_tunnel(&config, name, None).await.unwrap_err();+ assert_eq!(err, "name is required");+ }+}++#[tokio::test]+async fn id_bearing_tunnel_ops_reject_empty_or_whitespace_id() {+ let tmp = TempDir::new().unwrap();+ let config = test_support::config(&tmp, "http://127.0.0.1:9");+ for id in ["", " "] {+ assert_eq!(get_tunnel(&config, id).await.unwrap_err(), "id is required");+ assert_eq!(+ delete_tunnel(&config, id).await.unwrap_err(),+ "id is required"+ );+ assert_eq!(+ update_tunnel(&config, id, UpdateWebhookTunnelRequest::default())+ .await+ .unwrap_err(),+ "id is required"+ );+ }+}++#[tokio::test]+async fn calls_without_a_session_fail_before_any_request() {+ let tmp = TempDir::new().unwrap();+ let config = test_support::config(&tmp, "http://127.0.0.1:9");+ assert!(list_tunnels(&config)+ .await+ .unwrap_err()+ .contains("no backend session token"));+ assert!(get_bandwidth(&config)+ .await+ .unwrap_err()+ .contains("no backend session token"));+}++#[tokio::test]+async fn local_session_is_backend_unavailable() {+ let tmp = TempDir::new().unwrap();+ let config = test_support::local_session(&tmp);+ let err = list_tunnels(&config).await.unwrap_err();+ assert!(err.starts_with("BACKEND_UNAVAILABLE:"), "{err}");+ assert!(expected_error_kind(&err).is_some());+}++// ── SDK round-trips against a mock backend ────────────────────++#[tokio::test]+async fn tunnel_crud_round_trips_through_the_sdk() {+ let server = MockServer::start().await;+ Mock::given(method("GET"))+ .and(path("/webhooks/core"))+ .and(header("authorization", "Bearer jwt.test"))+ .respond_with(ok(json!({"tunnels": [{"id": "t-1"}]})))+ .expect(1)+ .mount(&server)+ .await;+ Mock::given(method("POST"))+ .and(path("/webhooks/core"))+ .and(body_json(json!({"name": "my-hook", "description": "desc"})))+ .respond_with(ok(json!({"id": "t-2"})))+ .expect(1)+ .mount(&server)+ .await;+ Mock::given(method("POST"))+ .and(path("/webhooks/core"))+ .and(body_json(json!({"name": "nodesc"})))+ .respond_with(ok(json!({"id": "t-3"})))+ .expect(1)+ .mount(&server)+ .await;+ Mock::given(method("GET"))+ .and(path("/webhooks/core/a%3Ab"))+ .respond_with(ok(json!({"id": "a:b"})))+ .expect(1)+ .mount(&server)+ .await;+ Mock::given(method("PATCH"))+ .and(path("/webhooks/core/t-1"))+ .and(body_json(json!({"name": "renamed", "isActive": true})))+ .respond_with(ok(json!({"id": "t-1", "name": "renamed"})))+ .expect(1)+ .mount(&server)+ .await;+ Mock::given(method("DELETE"))+ .and(path("/webhooks/core/t-42"))+ .respond_with(ok(json!({"deleted": "t-42"})))+ .expect(1)+ .mount(&server)+ .await;+ Mock::given(method("GET"))+ .and(path("/webhooks/core/bandwidth"))+ .respond_with(ok(json!({"remaining": 1024})))+ .expect(1)+ .mount(&server)+ .await;++ let tmp = TempDir::new().unwrap();+ let config = test_support::signed_in(&tmp, &server.uri());++ let out = list_tunnels(&config).await.unwrap();+ assert_eq!(out.value["tunnels"][0]["id"], json!("t-1"));+ assert!(out.logs.iter().any(|l| l.contains("webhook tunnels fetched")));++ let out = create_tunnel(&config, " my-hook ", Some(" desc ".into()))+ .await+ .unwrap();+ assert_eq!(out.value["id"], json!("t-2"));+ create_tunnel(&config, "nodesc", Some(" ".into()))+ .await+ .unwrap();++ let out = get_tunnel(&config, " a:b ").await.unwrap();+ assert_eq!(out.value["id"], json!("a:b"));++ let request = UpdateWebhookTunnelRequest {+ name: Some("renamed".into()),+ description: None,+ is_active: Some(true),+ };+ let out = update_tunnel(&config, "t-1", request).await.unwrap();+ assert_eq!(out.value["name"], json!("renamed"));++ let out = delete_tunnel(&config, "t-42").await.unwrap();+ assert_eq!(out.value["deleted"], json!("t-42"));++ let out = get_bandwidth(&config).await.unwrap();+ assert_eq!(out.value["remaining"], json!(1024));+}diff --git a/crates/openhuman-tinyhumans/src/hosted/webhooks/schemas_tests.rs b/crates/openhuman-tinyhumans/src/hosted/webhooks/schemas_tests.rsnew file mode 100644index 0000000000..f1be057929--- /dev/null+++ b/crates/openhuman-tinyhumans/src/hosted/webhooks/schemas_tests.rs@@ -0,0 +1,57 @@+use super::*;+use serde_json::json;++fn required_input_names(s: &ControllerSchema) -> Vec<&'static str> {+ s.inputs+ .iter()+ .filter(|f| f.required)+ .map(|f| f.name)+ .collect()+}++#[test]+fn catalog_is_the_six_hosted_tunnel_functions_under_webhooks() {+ let schemas = all_webhooks_controller_schemas();+ let names: Vec<&str> = schemas.iter().map(|s| s.function).collect();+ assert_eq!(names, FUNCTIONS);+ assert!(schemas.iter().all(|s| s.namespace == "webhooks"));+ assert_eq!(+ all_webhooks_registered_controllers().len(),+ FUNCTIONS.len()+ );+}++#[test]+fn input_contracts_are_unchanged() {+ assert!(webhooks_schemas("list_tunnels").inputs.is_empty());+ assert!(webhooks_schemas("get_bandwidth").inputs.is_empty());+ assert_eq!(+ required_input_names(&webhooks_schemas("create_tunnel")),+ vec!["name"]+ );+ for f in ["get_tunnel", "delete_tunnel", "update_tunnel"] {+ assert_eq!(required_input_names(&webhooks_schemas(f)), vec!["id"]);+ }+ let update = webhooks_schemas("update_tunnel");+ for optional in ["name", "description", "isActive"] {+ assert!(update.inputs.iter().any(|f| f.name == optional && !f.required));+ }+}++#[test]+fn unknown_function_returns_error_fallback_schema() {+ let s = webhooks_schemas("nope");+ assert_eq!(s.function, "unknown");+ assert_eq!(s.outputs[0].name, "error");+}++#[test]+fn update_params_accept_camel_case_is_active() {+ let mut params = Map::new();+ params.insert("id".into(), json!("t-1"));+ params.insert("isActive".into(), json!(false));+ let parsed: WebhookUpdateTunnelParams = deserialize_params(params).unwrap();+ assert_eq!(parsed.id, "t-1");+ assert_eq!(parsed.is_active, Some(false));+ assert!(deserialize_params::<WebhookTunnelIdParams>(Map::new()).is_err());+}