Skip to content

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

test(inbound): cover external event keying, source config, and origin parking

Steven Enamakelc7e5f5d13e31
diff --git a/crates/openhuman-core/src/inbound/events_tests.rs b/crates/openhuman-core/src/inbound/events_tests.rs
index 8e6fa0f07d..10d9f362b4 100644
--- a/crates/openhuman-core/src/inbound/events_tests.rs
+++ b/crates/openhuman-core/src/inbound/events_tests.rs
@@ -131,3 +131,31 @@ fn a_digest_lists_every_folded_event() {
);
assert_eq!(digest.payload["events"][1]["text"], "hello");
}
+
+#[test]
+fn an_external_event_is_keyed_by_its_source_and_key_and_round_trips() {
+ let payload = json!({ "author": "@alice", "conversation_id": "c1" });
+ let event = external("x:mentions", "mentions", "t1", "hi @bot", payload.clone(), 42).unwrap();
+ assert_eq!(event.source, "x:mentions");
+ assert_eq!(event.event_id, "t1");
+ assert_eq!(event.conversation_key, "mentions");
+ assert_eq!(event.sender.id, "x:mentions");
+ assert_eq!(event.kind, EventKind::Trigger);
+ assert_eq!(event.received_at_ms, 42);
+ assert_eq!(event.text, "hi @bot");
+ assert!(envelope_of(&event).is_none(), "not a trigger envelope");
+ let item = external_of(&event).unwrap();
+ assert_eq!(
+ serde_json::to_value(&item).unwrap(),
+ json!({ "id": "t1", "text": "hi @bot", "payload": payload, "received_at_ms": 42 })
+ );
+ let trigger = composio(&composio_envelope("u", "i")).unwrap();
+ assert!(external_of(&trigger).is_none());
+}
+
+#[test]
+fn an_oversize_external_event_is_refused() {
+ let big = "x".repeat(MAX_RAW_BYTES);
+ let refused = external("x:mentions", "mentions", "t1", "", json!({ "blob": big }), 0);
+ assert!(matches!(refused, Err(Unqueueable::Oversize(_))));
+}
diff --git a/crates/openhuman-core/src/inbound/settings_tests.rs b/crates/openhuman-core/src/inbound/settings_tests.rs
index 3130af4880..03cba12ff1 100644
--- a/crates/openhuman-core/src/inbound/settings_tests.rs
+++ b/crates/openhuman-core/src/inbound/settings_tests.rs
@@ -126,3 +126,48 @@ async fn the_module_config_is_what_the_storage_grant_declares() {
);
assert_eq!(queue_grant().unwrap().manifest, shipped().manifest);
}
+
+fn with_mentions() -> Config {
+ let mut config = Config::default();
+ config.inbound.sources.insert(
+ "x:mentions".into(),
+ crate::config::schema::InboundSourceConfig {
+ agent_id: "teeny-mentions".into(),
+ debounce_ms: 30_000,
+ max_wait_ms: 300_000,
+ max_batch: 20,
+ ..Default::default()
+ },
+ );
+ // Unusable: left out of the pipeline.
+ config.inbound.sources.insert(
+ "composio:gmail".into(),
+ crate::config::schema::InboundSourceConfig {
+ agent_id: "a".into(),
+ ..Default::default()
+ },
+ );
+ config
+}
+
+#[test]
+fn configured_sources_lead_the_pipeline_sources() {
+ let resolved = resolve(&with_mentions()).unwrap();
+ let sources = resolved.pipeline_json["sources"].as_array().unwrap();
+ assert_eq!(
+ sources[0],
+ json!({
+ "match": "x:mentions",
+ "ack": "after_ingest",
+ "weight": 50,
+ "cadence": "instant",
+ "coalesce": {"debounce_ms": 30_000, "max_wait_ms": 300_000, "max_events": 20},
+ })
+ );
+ assert_eq!(sources.len(), shipped().pipeline.sources.len() + 1);
+ // The parsed pipeline agrees: the first match wins for the source.
+ let policy = resolved.pipeline.source_policy("x:mentions");
+ assert_eq!(policy.weight, 50);
+ assert_eq!(policy.coalesce.unwrap().max_events, Some(20));
+ assert_eq!(resolved.pipeline.source_policy("composio:gmail").weight, 0);
+}
diff --git a/crates/openhuman-core/src/triage/origin_tests.rs b/crates/openhuman-core/src/triage/origin_tests.rs
index 7e61df7594..96616e8430 100644
--- a/crates/openhuman-core/src/triage/origin_tests.rs
+++ b/crates/openhuman-core/src/triage/origin_tests.rs
@@ -226,3 +226,20 @@ fn remote_triage_scopes_the_remote_origin() {
assert!(apply.contains("with_origin(origin, apply_decision("));
assert!(!apply.contains("local_trigger_origin"));
}
+
+#[test]
+fn an_external_inbound_turn_parks_external_effects() {
+ match external_inbound_origin("x:mentions", "turn-1") {
+ AgentTurnOrigin::TrustedAutomation { job_id, source } => {
+ assert_eq!(job_id, "inbound:x:mentions:turn-1");
+ assert_eq!(
+ source,
+ TrustedAutomationSource::Workflow {
+ require_approval: true
+ },
+ "pushed content must force a park, not auto-allow"
+ );
+ }
+ other => panic!("an inbound turn must not run as {}", other.class()),
+ }
+}