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
chore: files changed crates/openhuman-core/src/inbound/deliver_tests.rs,crates/openhuman-core/src/in
Steven Enamakeld30aaba9ffc3
diff --git a/crates/openhuman-core/src/inbound/deliver_tests.rs b/crates/openhuman-core/src/inbound/deliver_tests.rsindex 8b13789179..8d34e4cd9b 100644--- a/crates/openhuman-core/src/inbound/deliver_tests.rs+++ b/crates/openhuman-core/src/inbound/deliver_tests.rs@@ -1 +1,227 @@+//! Tests for `Deliver` and `ClassifySalience`: the ack semantics of each+//! triage outcome, digests, classification and its reuse on delivery.+use std::sync::Arc;+use std::time::Duration;++use serde_json::json;+use tinyeventqueues_bus::{EventKind, Sender};++use super::*;+use crate::inbound::events;+use crate::inbound::fixture::{decision, decision_outcome, deferred, ScriptedTriage, Step};+use crate::triage::TriggerEnvelope;++const NOW_MS: i64 = 1_000_000;++fn now() -> i64 {+ NOW_MS+}++fn deliverer(triage: &Arc<ScriptedTriage>) -> Deliverer {+ Deliverer::new(+ triage.clone() as Arc<dyn TriageRunner>,+ DispatchCtx::host_default(),+ Duration::from_millis(200),+ )+ .with_clock(now)+ .with_max_attempts(|_| Some(3))+}++fn trigger_event(uuid: &str) -> InboundEvent {+ let envelope = TriggerEnvelope::from_composio(+ "github",+ "GITHUB_ISSUE_OPENED",+ "",+ uuid,+ json!({ "title": "flaky test" }),+ );+ events::composio(&envelope).unwrap()+}++fn turn(events: Vec<InboundEvent>, lane: Lane, attempt: u32) -> DeliverRequest {+ let mut turn = Turn::new("turn-1", lane, "c", events);+ turn.attempt = attempt;+ DeliverRequest::new(turn)+}++#[test]+fn every_action_has_a_salience_class() {+ assert_eq!(class_of(TriageAction::Drop), SalienceClass::Noise);+ assert_eq!(class_of(TriageAction::Acknowledge), SalienceClass::Fyi);+ assert_eq!(class_of(TriageAction::React), SalienceClass::Actionable);+ assert_eq!(class_of(TriageAction::Escalate), SalienceClass::Urgent);+}++#[tokio::test]+async fn a_decision_is_accepted_and_applied() {+ let triage = ScriptedTriage::new([decision(TriageAction::React)]);+ let response = deliverer(&triage)+ .deliver(turn(vec![trigger_event("u1")], Lane::Background, 1))+ .await;+ assert_eq!(response.status, DeliverStatus::Accepted);+ let applied = triage.until_applied(1, Duration::from_secs(5)).await;+ assert_eq!(applied, vec!["composio/github/GITHUB_ISSUE_OPENED".to_owned()]);+}++#[tokio::test]+async fn a_deferral_is_retried_when_it_asked_to_run_again() {+ let triage = ScriptedTriage::new([Step::Answer(TriageOutcome::Deferred {+ defer_until_ms: NOW_MS + 5_000,+ reason: "busy".into(),+ })]);+ let response = deliverer(&triage)+ .deliver(turn(vec![trigger_event("u1")], Lane::Background, 1))+ .await;+ assert_eq!(+ response.status,+ DeliverStatus::Retry {+ after_ms: Some(5_000)+ }+ );+ assert!(triage.applied().is_empty());+}++#[tokio::test]+async fn a_deferral_already_due_is_retried_at_once() {+ let triage = ScriptedTriage::new([Step::Answer(TriageOutcome::Deferred {+ defer_until_ms: NOW_MS - 1,+ reason: "late".into(),+ })]);+ let response = deliverer(&triage)+ .deliver(turn(vec![trigger_event("u1")], Lane::Background, 3))+ .await;+ assert_eq!(response.status, DeliverStatus::Retry { after_ms: Some(0) });+}++#[tokio::test]+async fn a_terminal_triage_is_rejected() {+ let triage = ScriptedTriage::new([Step::Answer(TriageOutcome::Terminal {+ reason: "no fallback".into(),+ })]);+ let response = deliverer(&triage)+ .deliver(turn(vec![trigger_event("u1")], Lane::Actionable, 1))+ .await;+ assert_eq!(+ response.status,+ DeliverStatus::Rejected {+ detail: "no fallback".into()+ }+ );+}++#[tokio::test]+async fn a_failed_or_slow_triage_backs_off() {+ let triage = ScriptedTriage::new([Step::Fail("provider down"), Step::Hang]);+ let deliverer = deliverer(&triage);+ for attempt in [1, 3] {+ let response = deliverer+ .deliver(turn(vec![trigger_event("u1")], Lane::Background, attempt))+ .await;+ assert_eq!(response.status, DeliverStatus::Retry { after_ms: None });+ }+ assert_eq!(triage.runs(), 2);+}++#[tokio::test]+async fn a_turn_without_a_trigger_is_rejected() {+ let triage = ScriptedTriage::new(Vec::<Step>::new());+ let deliverer = deliverer(&triage);+ let empty = deliverer.deliver(turn(vec![], Lane::Background, 1)).await;+ assert!(matches!(empty.status, DeliverStatus::Rejected { .. }));+ let chat = InboundEvent::new(+ "channel:telegram",+ "1",+ "c",+ Sender::new("u"),+ EventKind::Message,+ 0,+ );+ let foreign = deliverer+ .deliver(turn(vec![chat], Lane::Interactive, 1))+ .await;+ assert!(matches!(foreign.status, DeliverStatus::Rejected { .. }));+ assert_eq!(triage.runs(), 0);+}++#[tokio::test]+async fn a_digest_is_triaged_once_for_all_its_events() {+ let triage = ScriptedTriage::new([decision(TriageAction::Escalate)]);+ let response = deliverer(&triage)+ .deliver(turn(+ vec![trigger_event("u1"), trigger_event("u2")],+ Lane::Digest,+ 1,+ ))+ .await;+ assert_eq!(response.status, DeliverStatus::Accepted);+ assert_eq!(triage.runs(), 1);+ let applied = triage.until_applied(1, Duration::from_secs(5)).await;+ assert_eq!(applied, vec!["external/inbound-digest/turn-1".to_owned()]);+}++#[tokio::test]+async fn a_classification_is_reused_by_the_delivery() {+ let triage = ScriptedTriage::new([decision(TriageAction::Escalate)]);+ let deliverer = deliverer(&triage);+ let event = trigger_event("u1");+ let classified = deliverer+ .classify(ClassifySalienceRequest::new(event.clone(), 40))+ .await+ .unwrap();+ assert_eq!(classified.class, SalienceClass::Urgent);+ let response = deliverer+ .deliver(turn(vec![event], Lane::Interactive, 1))+ .await;+ assert_eq!(response.status, DeliverStatus::Accepted);+ assert_eq!(triage.runs(), 1, "the delivery triaged a classified event again");+}++#[tokio::test]+async fn a_classification_without_a_decision_keeps_the_score() {+ let triage = ScriptedTriage::new([deferred(10), Step::Fail("down"), Step::Hang]);+ let deliverer = deliverer(&triage);+ for _ in 0..3 {+ let refused = deliverer+ .classify(ClassifySalienceRequest::new(trigger_event("u1"), 40))+ .await;+ assert!(refused.is_err());+ }+ let chat = InboundEvent::new("web:chat", "1", "c", Sender::new("u"), EventKind::Message, 0);+ assert!(deliverer+ .classify(ClassifySalienceRequest::new(chat, 40))+ .await+ .is_err());+ assert!(format!("{deliverer:?}").contains("Deliverer"));+}++#[test]+fn classifications_are_bounded() {+ let mut classified = Classified::default();+ let run = match decision_outcome(TriageAction::Drop) {+ TriageOutcome::Decision(run) => run,+ _ => unreachable!(),+ };+ for n in 0..=CLASSIFIED_CAPACITY {+ classified.keep(format!("k{n}"), run.clone());+ }+ classified.keep("k1".to_owned(), run.clone());+ assert_eq!(classified.runs.len(), CLASSIFIED_CAPACITY);+ assert!(classified.take("k0").is_none(), "the oldest was not evicted");+ assert!(classified.take("k1").is_some());+ assert!(classified.take("k1").is_none());+}++#[tokio::test]+async fn the_default_deliverer_reads_attempts_from_the_configured_queues() {+ let triage = ScriptedTriage::new([Step::Fail("down")]);+ let deliverer = Deliverer::new(+ triage.clone() as Arc<dyn TriageRunner>,+ DispatchCtx::host_default(),+ Duration::from_millis(100),+ );+ let response = deliverer+ .deliver(turn(vec![trigger_event("u1")], Lane::Background, 99))+ .await;+ assert_eq!(response.status, DeliverStatus::Retry { after_ms: None });+}diff --git a/crates/openhuman-core/src/inbound/events_tests.rs b/crates/openhuman-core/src/inbound/events_tests.rsindex 8b13789179..bd19f53613 100644--- a/crates/openhuman-core/src/inbound/events_tests.rs+++ b/crates/openhuman-core/src/inbound/events_tests.rs@@ -1 +1,119 @@+//! Tests for a trigger envelope as an inbound event, and back.+use serde_json::json;+use tinyeventqueues_bus::Lane;++use super::*;++fn composio_envelope(uuid: &str, id: &str) -> TriggerEnvelope {+ TriggerEnvelope::from_composio(+ "gmail",+ "GMAIL_NEW_GMAIL_MESSAGE",+ id,+ uuid,+ json!({ "subject": "hi" }),+ )+}++#[test]+fn a_composio_trigger_round_trips_with_a_stable_identity() {+ let envelope = composio_envelope("uuid-1", "id-1");+ let event = composio(&envelope).unwrap();+ assert_eq!(event.source, "composio:gmail");+ assert_eq!(event.event_id, "uuid-1");+ assert_eq!(event.conversation_key, "composio:gmail:uuid-1");+ assert_eq!(event.kind, EventKind::Trigger);+ assert!(event.text.starts_with("composio/gmail/GMAIL_NEW_GMAIL_MESSAGE"));+ // A redelivery is the same event to the queues.+ assert_eq!(+ composio(&composio_envelope("uuid-1", "id-1")).unwrap().dedupe_key(),+ event.dedupe_key()+ );++ let back = envelope_of(&event).unwrap();+ assert_eq!(back.external_id, envelope.external_id);+ assert_eq!(back.display_label, envelope.display_label);+ assert_eq!(back.payload, envelope.payload);+ assert_eq!(+ back.received_at.timestamp_millis(),+ envelope.received_at.timestamp_millis()+ );+ assert!(matches!(+ back.source,+ TriggerSource::Composio { ref toolkit, ref trigger }+ if toolkit == "gmail" && trigger == "GMAIL_NEW_GMAIL_MESSAGE"+ ));+}++#[test]+fn a_composio_trigger_without_a_uuid_uses_its_id_or_a_fresh_one() {+ assert_eq!(composio(&composio_envelope("", "id-7")).unwrap().event_id, "id-7");+ let fresh = composio(&composio_envelope("", "")).unwrap();+ assert!(uuid::Uuid::parse_str(&fresh.event_id).is_ok());+}++#[test]+fn a_webhook_is_identified_by_its_correlation_id() {+ let envelope = TriggerEnvelope::from_webhook("tunnel-1", "POST", "hooks/x", json!({"a": 1}));+ let event = webhook(&envelope, "corr-1").unwrap();+ assert_eq!(event.source, "webhook:tunnel-1");+ assert_eq!(event.event_id, "corr-1");+ let back = envelope_of(&event).unwrap();+ assert!(matches!(+ back.source,+ TriggerSource::Webhook { ref tunnel_id, ref method, ref path }+ if tunnel_id == "tunnel-1" && method == "POST" && path == "hooks/x"+ ));+ assert!(!webhook(&envelope, " ").unwrap().event_id.trim().is_empty());+}++#[test]+fn only_matching_sources_are_queued() {+ let cron = TriggerEnvelope::from_cron("job", "nightly", "ok");+ assert_eq!(composio(&cron).unwrap_err(), Unqueueable::Source);+ assert_eq!(webhook(&cron, "c").unwrap_err(), Unqueueable::Source);+ assert_eq!(Unqueueable::Source.to_string(), "source not queued");+}++#[test]+fn an_oversize_envelope_takes_the_direct_path() {+ let big = "x".repeat(MAX_RAW_BYTES);+ let envelope = TriggerEnvelope::from_composio("gmail", "T", "", "u", json!({ "body": big }));+ let refused = composio(&envelope).unwrap_err();+ assert!(matches!(refused, Unqueueable::Oversize(bytes) if bytes > MAX_RAW_BYTES));+ assert!(refused.to_string().contains("exceeds the queue limit"));+}++#[test]+fn an_event_that_is_not_a_trigger_has_no_envelope() {+ let mut event = composio(&composio_envelope("u", "")).unwrap();+ event.raw = None;+ assert!(envelope_of(&event).is_none());+ event.raw = Some(json!({+ "kind": "carrier-pigeon",+ "external_id": "x",+ "display_label": "x",+ "payload": {},+ "received_at_ms": 0,+ }));+ assert!(envelope_of(&event).is_none());+ event.raw = Some(json!({ "kind": "composio" }));+ assert!(envelope_of(&event).is_none());+}++#[test]+fn a_digest_lists_every_folded_event() {+ let trigger = composio(&composio_envelope("u1", "")).unwrap();+ let chat = InboundEvent::new("web:chat", "9", "c", Sender::new("x"), EventKind::Message, 0)+ .text("hello");+ let turn = Turn::new("t-9", Lane::Digest, "c", vec![trigger, chat]);+ let digest = digest_envelope(&turn);+ assert_eq!(digest.display_label, "external/inbound-digest/t-9");+ assert_eq!(digest.payload["count"], 2);+ assert_eq!(digest.payload["events"][0]["event_id"], "u1");+ assert_eq!(+ digest.payload["events"][0]["label"],+ "composio/gmail/GMAIL_NEW_GMAIL_MESSAGE"+ );+ assert_eq!(digest.payload["events"][1]["text"], "hello");+}diff --git a/crates/openhuman-core/src/inbound/host_tests.rs b/crates/openhuman-core/src/inbound/host_tests.rsindex 8b13789179..51ac7b1b7a 100644--- a/crates/openhuman-core/src/inbound/host_tests.rs+++ b/crates/openhuman-core/src/inbound/host_tests.rs@@ -1 +1,66 @@+//! Tests for the served host callbacks.+use std::sync::Arc;++use serde_json::json;+use tinybus::Interface;+use tinyeventqueues_bus::{DeliverStatus, Lane, Turn};++use super::*;+use crate::inbound::events;+use crate::inbound::fixture::{decision, ScriptedTriage, Step};+use crate::triage::{TriageAction, TriageRunner, TriggerEnvelope};++fn host(triage: &Arc<ScriptedTriage>) -> InboundHost {+ InboundHost::new(Arc::new(Deliverer::new(+ triage.clone() as Arc<dyn TriageRunner>,+ DispatchCtx::host_default(),+ Duration::from_millis(200),+ )))+}++fn trigger() -> tinyeventqueues_bus::InboundEvent {+ let envelope = TriggerEnvelope::from_composio("jira", "JIRA_ISSUE", "", "u", json!({}));+ events::composio(&envelope).unwrap()+}++#[test]+fn the_interface_is_the_contract() {+ let host = host(&ScriptedTriage::new(Vec::<Step>::new()));+ assert_eq!(host.name().to_string(), NAME);+ let members: Vec<String> = host.members().into_iter().map(|m| m.to_string()).collect();+ assert_eq!(members, tinyeventqueues_bus::names::host::METHODS.to_vec());+}++#[tokio::test]+async fn deliver_and_classify_go_to_the_deliverer() {+ let triage = ScriptedTriage::new([decision(TriageAction::React), Step::Fail("down")]);+ let host = host(&triage);+ let delivered = host+ .deliver(DeliverRequest::new(Turn::new(+ "t",+ Lane::Background,+ "c",+ vec![trigger()],+ )))+ .await+ .unwrap();+ assert_eq!(delivered.status, DeliverStatus::Accepted);+ let refused = host+ .classify_salience(ClassifySalienceRequest::new(trigger(), 35))+ .await+ .unwrap_err();+ assert!(refused.to_string().contains("triage failed"), "{refused}");+}++#[tokio::test]+async fn install_serves_the_callbacks_under_the_contract_name() {+ let bus = tinybus::transport::memory::MemoryBus::new();+ tinybus::broker::Broker::new().spawn(bus.clone());+ let connection = tinybus::Connection::connect(bus.connect().await.unwrap())+ .await+ .unwrap();+ install(&connection).await.unwrap();+ let names = connection.list_names().await.unwrap();+ assert!(names.iter().any(|name| name.as_str() == NAME));+}diff --git a/crates/openhuman-core/src/inbound/linked_fixture.rs b/crates/openhuman-core/src/inbound/linked_fixture.rsindex 81454d6b03..bf8ad49ef5 100644--- a/crates/openhuman-core/src/inbound/linked_fixture.rs+++ b/crates/openhuman-core/src/inbound/linked_fixture.rs@@ -57,6 +57,10 @@ pub(crate) enum Step {Answer(TriageOutcome),/// Defer until `after_ms` after the triage that answers it.DeferFor(i64),+ /// Fail the triage with this message.+ Fail(&'static str),+ /// Never answer (until the caller's timeout).+ Hang,}impl From<TriageOutcome> for Step {@@ -119,13 +123,21 @@ impl TriageRunner for ScriptedTriage {) -> anyhow::Result<TriageOutcome> {self.runs.fetch_add(1, Ordering::SeqCst);let next = self.script.lock().unwrap().pop_front();+ match next {+ Some(Step::Fail(message)) => return Err(anyhow::anyhow!(message)),+ Some(Step::Hang) => {+ tokio::time::sleep(Duration::from_secs(3600)).await;+ return Err(anyhow::anyhow!("hung"));+ }+ _ => {}+ }Ok(match next {Some(Step::Answer(outcome)) => outcome,Some(Step::DeferFor(after_ms)) => TriageOutcome::Deferred {defer_until_ms: chrono::Utc::now().timestamp_millis() + after_ms,reason: "scripted deferral".to_owned(),},- None => decision_outcome(TriageAction::Acknowledge),+ Some(Step::Fail(_) | Step::Hang) | None => decision_outcome(TriageAction::Acknowledge),})}diff --git a/crates/openhuman-core/src/inbound/ops_tests.rs b/crates/openhuman-core/src/inbound/ops_tests.rsindex 8b13789179..a28a9f07f9 100644--- a/crates/openhuman-core/src/inbound/ops_tests.rs+++ b/crates/openhuman-core/src/inbound/ops_tests.rs@@ -1 +1,41 @@+//! Tests for `inbound.stats`, `inbound.dead` and `inbound.redrive`.+use super::*;+use crate::inbound::fixture::{active_config, Rig, ScriptedTriage, Step};++#[tokio::test]+async fn the_component_switch_refuses_every_operation() {+ let mut config = active_config();+ config.components.eventqueues = false;+ let client = crate::modules::ops::client(config.clone());+ for refused in [+ stats(&config, &client).await.map(|_| ()),+ dead(&config, &client, None).await.map(|_| ()),+ redrive(&config, &client, "x").await.map(|_| ()),+ ] {+ assert!(refused.unwrap_err().contains("COMPONENT_DISABLED:eventqueues"));+ }+}++#[tokio::test(flavor = "multi_thread", worker_threads = 2)]+async fn the_operations_reach_the_module() {+ let rig = Rig::new(ScriptedTriage::new(Vec::<Step>::new())).await;+ let config = active_config();++ let depths = stats(&config, &rig.client).await.unwrap();+ assert!(depths.value.queues.iter().any(|q| q.queue == "teq.ingress"));++ let parked = dead(&config, &rig.client, Some(10_000)).await.unwrap();+ assert!(parked.value.items.is_empty());++ let gone = redrive(&config, &rig.client, "teq.dead/none").await.unwrap();+ assert!(!gone.value.redriven);+ assert!(redrive(&config, &rig.client, " ")+ .await+ .unwrap_err()+ .contains("id is required"));+ assert!(redrive(&config, &rig.client, "nope")+ .await+ .unwrap_err()+ .starts_with("inbound.redrive:"));+}diff --git a/crates/openhuman-core/src/inbound/route_tests.rs b/crates/openhuman-core/src/inbound/route_tests.rsindex 8b13789179..6c4147263e 100644--- a/crates/openhuman-core/src/inbound/route_tests.rs+++ b/crates/openhuman-core/src/inbound/route_tests.rs@@ -1 +1,57 @@+//! Tests for the hand-off to the queues.+use std::time::Duration;++use serde_json::json;++use super::*;+use crate::inbound::events;+use crate::inbound::fixture::{active_config, Rig, ScriptedTriage, Step};+use crate::triage::TriggerEnvelope;++fn event(uuid: &str) -> InboundEvent {+ let envelope = TriggerEnvelope::from_composio("slack", "SLACK_MESSAGE", "", uuid, json!({}));+ events::composio(&envelope).unwrap()+}++#[tokio::test(flavor = "multi_thread", worker_threads = 2)]+async fn an_accepted_event_is_queued_and_a_redelivery_ends_at_ingress() {+ let rig = Rig::new(ScriptedTriage::new(Vec::<Step>::new())).await;+ let config = active_config();+ let first = offer(&config, &rig.client, event("u1")).await;+ assert_eq!(first, Offered::Queued(Disposition::Accepted));+ assert!(first.is_queued());+ let again = offer(&config, &rig.client, event("u1")).await;+ assert_eq!(again, Offered::Queued(Disposition::Duplicate));+ let _ = rig.triage.until_applied(1, Duration::from_secs(5)).await;+}++#[tokio::test]+async fn inactive_queues_send_the_event_down_the_direct_path() {+ let mut config = active_config();+ config.inbound.enabled = false;+ let client = crate::modules::ops::client(config.clone());+ let offered = offer(&config, &client, event("u2")).await;+ assert!(matches!(offered, Offered::Direct(ref why) if why.contains("inactive")));+ assert!(!offered.is_queued());+}++#[tokio::test(flavor = "multi_thread", worker_threads = 2)]+async fn an_unreachable_module_sends_the_event_down_the_direct_path() {+ // A client bound to an object nobody serves: the call fails.+ let bus = tinybus::transport::memory::MemoryBus::new();+ tinybus::broker::Broker::new().spawn(bus.clone());+ let caller = tinybus::Connection::connect(bus.connect().await.unwrap())+ .await+ .unwrap();+ let proxy = caller+ .proxy(+ tinyeventqueues_bus::INTERFACE,+ tinyeventqueues_bus::OBJECT_PATH,+ tinyeventqueues_bus::INTERFACE,+ )+ .unwrap();+ let client = crate::modules::ops::fixture_client(proxy);+ let offered = offer(&active_config(), &client, event("u3")).await;+ assert!(matches!(offered, Offered::Direct(ref why) if why.contains("ingest failed")));+}diff --git a/crates/openhuman-core/src/inbound/schemas_tests.rs b/crates/openhuman-core/src/inbound/schemas_tests.rsindex 8b13789179..f7146a1621 100644--- a/crates/openhuman-core/src/inbound/schemas_tests.rs+++ b/crates/openhuman-core/src/inbound/schemas_tests.rs@@ -1 +1,25 @@+//! Tests for the `inbound` controller schemas.+use super::*;++#[test]+fn every_function_has_a_schema_and_a_controller() {+ let schemas = all_controller_schemas();+ let names: Vec<&str> = schemas.iter().map(|schema| schema.function).collect();+ assert_eq!(names, vec!["stats", "dead", "redrive"]);+ assert!(schemas.iter().all(|schema| schema.namespace == "inbound"));+ let controllers = all_registered_controllers();+ assert_eq!(controllers.len(), 3);+ assert_eq!(schemas("unknown").function, "unknown");+ assert!(schemas("redrive").inputs.iter().any(|input| input.name == "id" && input.required));+}++#[tokio::test]+async fn malformed_params_are_refused_before_the_module_is_reached() {+ let mut params = Map::new();+ params.insert("limit".into(), Value::String("ten".into()));+ let refused = handle_dead(DispatchCtx::host_default(), params).await;+ assert!(refused.unwrap_err().contains("invalid params"));+ let refused = handle_redrive(DispatchCtx::host_default(), Map::new()).await;+ assert!(refused.unwrap_err().contains("invalid params"));+}diff --git a/crates/openhuman-core/src/inbound/settings_tests.rs b/crates/openhuman-core/src/inbound/settings_tests.rsindex 8b13789179..e36de774e7 100644--- a/crates/openhuman-core/src/inbound/settings_tests.rs+++ b/crates/openhuman-core/src/inbound/settings_tests.rs@@ -1 +1,115 @@+//! Tests for resolving `[inbound]`.+use std::io::Write;++use super::*;++/// Serializes the tests that write the process-wide last resolution.+static CURRENT_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());++fn file(text: &str) -> tempfile::NamedTempFile {+ let mut file = tempfile::NamedTempFile::new().unwrap();+ file.write_all(text.as_bytes()).unwrap();+ file+}++#[test]+fn routing_needs_modules_the_component_and_the_switch() {+ let mut config = Config::default();+ assert!(active(&config));+ config.inbound.enabled = false;+ assert!(!active(&config));+ config.inbound.enabled = true;+ config.components.eventqueues = false;+ assert!(!active(&config));+ config.components.eventqueues = true;+ config.modules.enabled = false;+ assert!(!active(&config));+}++#[test]+fn the_defaults_resolve_to_the_shipped_files_in_storage() {+ let resolved = resolve(&Config::default()).unwrap();+ let shipped = shipped();+ assert_eq!(resolved.manifest, shipped.manifest);+ assert_eq!(resolved.pipeline, shipped.pipeline);+ assert_eq!(resolved.backend, QueueConfig::Storage);+ assert!(resolved.manifest.get("teq.ingress").is_some());+ assert_eq!(resolved.max_attempts(Lane::Interactive), Some(5));+}++#[test]+fn override_files_replace_the_shipped_ones() {+ let mut queues: Value = serde_json::from_str(SHIPPED_QUEUES_JSON).unwrap();+ queues["queues"][1]["max_attempts"] = json!(9);+ let queues = file(&queues.to_string());+ let mut pipeline: Value = serde_json::from_str(SHIPPED_PIPELINE_JSON).unwrap();+ pipeline["ingress"]["batch_size"] = json!(3);+ let pipeline = file(&pipeline.to_string());+ let mut config = Config::default();+ config.inbound.queues_path = Some(queues.path().to_path_buf());+ config.inbound.pipeline_path = Some(pipeline.path().to_path_buf());+ let resolved = resolve(&config).unwrap();+ assert_eq!(resolved.max_attempts(Lane::Interactive), Some(9));+ assert_eq!(resolved.pipeline.ingress.batch_size, 3);+ assert_eq!(resolved.pipeline_json["ingress"]["batch_size"], 3);+}++#[test]+fn unusable_settings_are_named() {+ let mut config = Config::default();+ config.inbound.queues_path = Some("/nonexistent/queues.json".into());+ assert!(resolve(&config).unwrap_err().contains("cannot read"));++ let broken = file("{\"version\": 1, \"queues\": [{\"name\": \"\"}]}");+ config.inbound.queues_path = Some(broken.path().to_path_buf());+ assert!(resolve(&config).unwrap_err().contains("queues.json"));++ config.inbound.queues_path = None;+ let broken = file("{\"version\": 1, \"nonsense\": true}");+ config.inbound.pipeline_path = Some(broken.path().to_path_buf());+ assert!(resolve(&config).unwrap_err().contains("pipeline.json"));++ config.inbound.pipeline_path = None;+ config.inbound.queue_url = Some("redis://localhost".into());+ assert!(resolve(&config).unwrap_err().contains("inbound.queue_url"));+}++#[test]+fn a_queue_url_selects_the_backend() {+ let mut config = Config::default();+ config.inbound.queue_url = Some("storage".into());+ assert_eq!(resolve(&config).unwrap().backend, QueueConfig::Storage);+ // This build carries no broker driver: an AMQP URL is refused by name.+ config.inbound.queue_url = Some("amqp://guest:guest@localhost/".into());+ let refused = resolve(&config).unwrap_err();+ assert!(refused.contains("rabbitmq"), "{refused}");+ assert!(!refused.contains("guest:guest"), "credentials leaked: {refused}");+}++#[tokio::test]+async fn the_module_config_is_what_the_storage_grant_declares() {+ let _lock = CURRENT_LOCK.lock().await;+ let mut queues: Value = serde_json::from_str(SHIPPED_QUEUES_JSON).unwrap();+ queues["queues"][0]["max_attempts"] = json!(4);+ let queues = file(&queues.to_string());+ let mut config = Config::default();+ config.inbound.queues_path = Some(queues.path().to_path_buf());++ let blob = module_config(&config);+ assert_eq!(blob["queues"]["queues"][0]["max_attempts"], 4);+ assert_eq!(blob["pipeline"]["version"], 1);+ let grant = queue_grant().unwrap();+ assert_eq!(grant.manifest.queues[0].max_attempts, 4);+ assert_eq!(grant.backend, QueueConfig::Storage);+ assert_eq!(current().manifest, grant.manifest);++ // An unusable override runs the shipped files rather than failing.+ config.inbound.queues_path = Some("/nonexistent/queues.json".into());+ let blob = module_config(&config);+ assert_eq!(+ blob["queues"],+ serde_json::from_str::<Value>(SHIPPED_QUEUES_JSON).unwrap()+ );+ assert_eq!(queue_grant().unwrap().manifest, shipped().manifest);+}diff --git a/crates/openhuman-core/src/modules/event_queues_tests.rs b/crates/openhuman-core/src/modules/event_queues_tests.rsindex 8b13789179..e9d3853cee 100644--- a/crates/openhuman-core/src/modules/event_queues_tests.rs+++ b/crates/openhuman-core/src/modules/event_queues_tests.rs@@ -1 +1,26 @@+//! Tests for the `tinyeventqueues` module adapter, against the linked module.+use std::time::Duration;++use serde_json::json;++use super::*;+use crate::inbound::events;+use crate::inbound::fixture::{Rig, ScriptedTriage, Step};+use crate::triage::TriggerEnvelope;++#[tokio::test(flavor = "multi_thread", worker_threads = 2)]+async fn every_member_is_reachable() {+ let rig = Rig::new(ScriptedTriage::new(Vec::<Step>::new())).await;+ let envelope = TriggerEnvelope::from_composio("notion", "PAGE", "", "u", json!({}));+ let event = events::composio(&envelope).unwrap();++ let ingested = ingest(&rig.client, vec![event]).await.unwrap();+ assert_eq!(ingested.results.len(), 1);+ let _ = drain(&rig.client).await.unwrap();+ let _ = rig.triage.until_applied(1, Duration::from_secs(5)).await;+ let depths = stats(&rig.client).await.unwrap();+ assert_eq!(depths.queues.len(), 6);+ assert!(list_dead(&rig.client, 5).await.unwrap().is_empty());+ assert!(!redrive(&rig.client, "teq.dead/none").await.unwrap());+}