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
test(core): strengthen weak core tests; config parse warnings log the safe summary
M3gA-Mind90b1a2865e00
diff --git a/crates/openhuman-core/src/config/schema/load/config_file_read.rs b/crates/openhuman-core/src/config/schema/load/config_file_read.rsindex b016f95115..7999691299 100644--- a/crates/openhuman-core/src/config/schema/load/config_file_read.rs+++ b/crates/openhuman-core/src/config/schema/load/config_file_read.rs@@ -36,7 +36,7 @@ pub(super) async fn parse_config_boxed(config_path: &Path, contents: &str) -> (Btracing::warn!(path = %config_path.display(),backup = %backup_path.display(),- error = %parse_err,+ error = %parse_error.safe_summary(),"[config] Config file is corrupted — attempting recovery from backup");match fs::read_to_string(&backup_path).await {@@ -58,7 +58,8 @@ pub(super) async fn parse_config_boxed(config_path: &Path, contents: &str) -> (Btracing::warn!(path = %config_path.display(),backup = %backup_path.display(),- error = %bak_err,+ error = %ConfigParseError::from_error(backup_path.clone(), &bak_err)+ .safe_summary(),"[config] Backup is also corrupted; resetting to defaults");}@@ -75,7 +76,7 @@ pub(super) async fn parse_config_boxed(config_path: &Path, contents: &str) -> (B} else {tracing::warn!(path = %config_path.display(),- error = %parse_err,+ error = %parse_error.safe_summary(),"[config] Config file is corrupted (no backup found); resetting to defaults");}diff --git a/crates/openhuman-core/src/config/schema/load_parse_log_tests.rs b/crates/openhuman-core/src/config/schema/load_parse_log_tests.rsnew file mode 100644index 0000000000..769a4c0ba9--- /dev/null+++ b/crates/openhuman-core/src/config/schema/load_parse_log_tests.rs@@ -0,0 +1,53 @@+//! A corrupt config is logged by its safe summary, never by the parser's text,+//! which quotes the offending source line (and so any secret on it).++use super::*;++#[derive(Clone, Default)]+struct Logs(std::sync::Arc<std::sync::Mutex<Vec<u8>>>);++impl std::io::Write for Logs {+ fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {+ self.0.lock().unwrap().extend_from_slice(bytes);+ Ok(bytes.len())+ }+ fn flush(&mut self) -> std::io::Result<()> {+ Ok(())+ }+}++const LEAKY: &str = "api_key = \"sk-live-SECRETVALUE\n";++async fn logs_of_recovery(backup: Option<&str>) -> String {+ let logs = Logs::default();+ let writer = logs.clone();+ let subscriber = tracing_subscriber::fmt()+ .with_writer(move || writer.clone())+ .with_ansi(false)+ .finish();+ let _guard = tracing::subscriber::set_default(subscriber);+ tracing::callsite::rebuild_interest_cache();++ let tmp = tempfile::tempdir().unwrap();+ let config_path = tmp.path().join("config.toml");+ std::fs::write(&config_path, LEAKY).unwrap();+ if let Some(backup) = backup {+ std::fs::write(config_path.with_extension("toml.bak"), backup).unwrap();+ }+ let (_, corrupted) = parse_config_with_recovery(&config_path, LEAKY).await;+ assert!(corrupted);+ let text = String::from_utf8(logs.0.lock().unwrap().clone()).unwrap();+ text+}++#[tokio::test]+async fn corrupt_config_warn_log_omits_values() {+ for backup in [None, Some(LEAKY)] {+ let text = logs_of_recovery(backup).await;+ assert!(+ text.contains("corrupted"),+ "{backup:?}: no corruption warning in {text:?}"+ );+ assert!(!text.contains("SECRETVALUE"), "{backup:?}: {text}");+ }+}diff --git a/crates/openhuman-core/src/config/schema/load_tests.rs b/crates/openhuman-core/src/config/schema/load_tests.rsindex 9fd7bdf009..fb16f8cdd3 100644--- a/crates/openhuman-core/src/config/schema/load_tests.rs+++ b/crates/openhuman-core/src/config/schema/load_tests.rs@@ -114,6 +114,8 @@ mod env_overlay_context_tests;mod env_overlay_tests;#[path = "load_migration_tests.rs"]mod migration_tests;+#[path = "load_parse_log_tests.rs"]+mod parse_log_tests;#[path = "load_profile_layout_parity_tests.rs"]mod profile_layout_parity_tests;diff --git a/crates/openhuman-core/src/core/invoke_tests.rs b/crates/openhuman-core/src/core/invoke_tests.rsindex 3608218427..81ec3525c6 100644--- a/crates/openhuman-core/src/core/invoke_tests.rs+++ b/crates/openhuman-core/src/core/invoke_tests.rs@@ -129,26 +129,6 @@ async fn invoke_service_status_rejects_unknown_param() {assert!(err.contains("unknown param 'x'"));}-#[tokio::test]-async fn invoke_memory_init_accepts_empty_params() {- // jwt_token is optional (accepted for backward compat but ignored).- // The call may still fail for workspace reasons in test, but must NOT- // fail with a missing-param error for jwt_token.- let result = invoke_method(- DispatchCtx::ambient(),- default_state(),- "openhuman.memory_init",- json!({}),- )- .await;- if let Err(ref e) = result {- assert!(- !e.contains("missing required param") || !e.contains("jwt_token"),- "jwt_token should be optional, got: {e}"- );- }-}-#[tokio::test]async fn invoke_memory_learn_rejects_unknown_param() {let err = invoke_method(@@ -276,22 +256,17 @@ async fn invoke_method_rejects_string_params_for_registered_method() {#[tokio::test]async fn invoke_method_accepts_null_params_for_registered_method() {- // JSON-RPC 2.0 allows omitting params; null must be treated like {}.+ // JSON-RPC 2.0 allows omitting params; null must behave exactly like {}+ // (see invoke_health_snapshot_via_registry), not merely avoid one error.let result = invoke_method(DispatchCtx::ambient(),default_state(),"openhuman.health_snapshot",json!(null),)- .await;- // Call should succeed or fail for domain reasons — but must NOT- // fail with the "invalid params" shape error.- if let Err(e) = result {- assert!(- !e.contains("invalid params"),- "null should be accepted as empty object, got: {e}"- );- }+ .await+ .expect("null params must behave like {}");+ assert!(result.get("result").is_some());}#[tokio::test]diff --git a/crates/openhuman-core/src/core/runtime/builder_tests.rs b/crates/openhuman-core/src/core/runtime/builder_tests.rsindex 7db953eb15..61d18a1bc2 100644--- a/crates/openhuman-core/src/core/runtime/builder_tests.rs+++ b/crates/openhuman-core/src/core/runtime/builder_tests.rs@@ -175,3 +175,25 @@ fn boot_jobs_are_independent_from_runtime_service_flags() {assert!(!headless.integrations);assert!(!headless.memory_sync);}++/// Inspection boot refuses to start without a caller-supplied config and a+/// fixed bearer, before it touches any process state.+#[tokio::test]+async fn inspection_boot_rejects_missing_config_and_env_token() {+ let refusal = |result: anyhow::Result<super::CoreRuntime>| match result {+ Ok(_) => panic!("inspection boot must refuse"),+ Err(error) => error.to_string(),+ };+ let inspection = || CoreBuilder::new(HostKind::Cli).boot_mode(CoreBootMode::Inspection);++ let error = refusal(inspection().build().await);+ assert!(error.contains("caller-supplied config"), "{error}");++ let error = refusal(+ inspection()+ .config(crate::config::Config::default())+ .build()+ .await,+ );+ assert!(error.contains("fixed RPC bearer"), "{error}");+}diff --git a/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rs b/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rsindex e08a7ecbaf..3c76e6376c 100644--- a/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rs+++ b/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rs@@ -85,7 +85,7 @@ impl EventHandler<DomainEvent> for ComposioTriggerSubscriber {// own tenant; in SaaS it has none and is dropped.let ctx = DispatchCtx::host_default();if let Ok(config) = ctx.load_config().await {- if config.composio.mode == crate::config::schema::COMPOSIO_MODE_DIRECT {+ if is_direct_mode(&config) {tracing::info!(toolkit = %toolkit,trigger = %trigger,@@ -118,52 +118,25 @@ impl EventHandler<DomainEvent> for ComposioTriggerSubscriber {}}- if triage_disabled() {+ // The env var is a global kill-switch that works even when the config+ // file is corrupt; an unreadable config otherwise fails open to triage.+ let config = ctx.load_config().await;+ if let Some(reason) = triage_skip_reason(config.as_ref().ok(), &toolkit, triage_disabled())+ {tracing::debug!(toolkit = %toolkit,trigger = %trigger,- "[composio][triage] skipped: {TRIAGE_DISABLED_ENV} is set"+ "[composio][triage] skipped: {reason}");return;}-- // Config-level triage gates — checked after env var so the env var- // remains a global emergency kill-switch that works even when the- // config file is corrupt. Fail-open on load error: if we can't read- // the config we let triage run rather than silently drop events.- match ctx.load_config().await {- Ok(config) => {- if config.composio.triage_disabled {- tracing::debug!(- toolkit = %toolkit,- trigger = %trigger,- "[composio][triage] skipped: composio.triage_disabled=true in config"- );- return;- }- let toolkit_lower = toolkit.to_ascii_lowercase();- if config- .composio- .triage_disabled_toolkits- .iter()- .any(|t| t.to_ascii_lowercase() == toolkit_lower)- {- tracing::debug!(- toolkit = %toolkit,- trigger = %trigger,- "[composio][triage] skipped: toolkit in composio.triage_disabled_toolkits"- );- return;- }- }- Err(e) => {- tracing::warn!(- toolkit = %toolkit,- trigger = %trigger,- error = %e,- "[composio][triage] config load failed — falling through to triage (fail-open)"- );- }+ if let Err(e) = &config {+ tracing::warn!(+ toolkit = %toolkit,+ trigger = %trigger,+ error = %e,+ "[composio][triage] config load failed — falling through to triage (fail-open)"+ );}// Build the envelope outside the spawned task so any panic in@@ -323,6 +296,33 @@ pub(super) fn triage_directly(})}+/// Backend-tenant triggers are ghosts once the user has switched to direct mode.+pub(super) fn is_direct_mode(config: &crate::config::Config) -> bool {+ config.composio.mode == crate::config::schema::COMPOSIO_MODE_DIRECT+}++/// Why a received trigger skips triage, if it does. The env kill-switch wins,+/// then the config's global switch and per-toolkit list (case-insensitive).+/// `None` config means it could not be read, which fails open to triage.+pub(super) fn triage_skip_reason(+ config: Option<&crate::config::Config>,+ toolkit: &str,+ env_disabled: bool,+) -> Option<&'static str> {+ if env_disabled {+ return Some("OPENHUMAN_TRIGGER_TRIAGE_DISABLED is set");+ }+ let composio = &config?.composio;+ if composio.triage_disabled {+ return Some("composio.triage_disabled=true in config");+ }+ composio+ .triage_disabled_toolkits+ .iter()+ .any(|t| t.eq_ignore_ascii_case(toolkit))+ .then_some("toolkit in composio.triage_disabled_toolkits")+}+/// Returns `true` when `OPENHUMAN_TRIGGER_TRIAGE_DISABLED` is set to a/// truthy value. The pipeline is **on by default**; this env var is the/// opt-out escape hatch.diff --git a/crates/openhuman-core/src/integrations/composio/bus_tests.rs b/crates/openhuman-core/src/integrations/composio/bus_tests.rsindex be380d1a83..459308b8a5 100644--- a/crates/openhuman-core/src/integrations/composio/bus_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/bus_tests.rs@@ -1,7 +1,9 @@//! Unit tests for the Composio bus subscribers.use super::connection_created_subscriber::WaitError;-use super::trigger_subscriber::{triage_disabled, TRIAGE_DISABLED_ENV};+use super::trigger_subscriber::{+ is_direct_mode, triage_disabled, triage_skip_reason, TRIAGE_DISABLED_ENV,+};use super::*;use crate::core::events::DomainEvent;use serde_json::json;@@ -24,7 +26,8 @@ async fn ignores_non_composio_events() {}#[tokio::test]-async fn handles_trigger_event_without_panic() {+async fn handling_a_trigger_with_triage_disabled_is_a_smoke_test() {+ // Smoke only: the gate decisions are pinned on `triage_skip_reason`.// `ComposioTriggerSubscriber::handle` calls// `config_rpc::load_config_with_timeout()` at the very top (the// direct-mode trigger gate, `bus.rs`), *before* the@@ -86,19 +89,14 @@ fn triage_disabled_flag_parser() {}#[test]-fn direct_mode_constant_matches_trigger_drop_check() {- // The ComposioTriggerSubscriber drops events when- // `config.composio.mode == COMPOSIO_MODE_DIRECT`. If the schema- // constant ever drifts from the string "direct" the drop becomes- // a silent no-op and backend-tenant ghosts would leak through- // into a direct-mode user's triage pipeline. Pin both sides.- use crate::config::ComposioConfig;- assert_eq!(crate::config::schema::COMPOSIO_MODE_DIRECT, "direct");- let cfg = ComposioConfig {- mode: "direct".into(),- ..Default::default()- };- assert_eq!(cfg.mode, crate::config::schema::COMPOSIO_MODE_DIRECT);+fn direct_mode_drops_backend_tenant_triggers() {+ // Pinned against the literal: if the schema constant drifted from what the+ // config file holds, the drop would silently become a no-op.+ let mut config = crate::config::Config::default();+ config.composio.mode = "direct".into();+ assert!(is_direct_mode(&config));+ config.composio.mode = "backend".into();+ assert!(!is_direct_mode(&config));}#[test]@@ -116,64 +114,20 @@ fn composio_config_triage_disabled_default() {}#[test]-fn composio_config_triage_disabled_toolkit_match() {- use crate::config::ComposioConfig;- let cfg = ComposioConfig {- triage_disabled_toolkits: vec!["GMAIL".to_string(), "slack".to_string()],- ..Default::default()- };- let toolkit = "gmail";- let toolkit_lower = toolkit.to_ascii_lowercase();- assert!(- cfg.triage_disabled_toolkits- .iter()- .any(|t| t.to_ascii_lowercase() == toolkit_lower),- "case-insensitive match against gmail should fire"- );- assert!(- !cfg.triage_disabled_toolkits- .iter()- .any(|t| t.eq_ignore_ascii_case("github")),- "github should not match"- );-}--#[tokio::test]-async fn trigger_subscriber_skips_triage_when_env_disabled() {- // Same rationale as `handles_trigger_event_without_panic`: the- // direct-mode trigger gate in `ComposioTriggerSubscriber::handle`- // calls `load_config_with_timeout()` before the env kill-switch, so- // this test must isolate `OPENHUMAN_WORKSPACE` under `TEST_ENV_LOCK`- // (acquired before `TRIAGE_ENV_GUARD`).- use crate::config::{Config, TEST_ENV_LOCK};- let _env_lock = TEST_ENV_LOCK.lock().await;- let _guard = TRIAGE_ENV_GUARD.lock().await;-- let tmp = tempfile::tempdir().expect("tempdir");- unsafe {- std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());- }- let mut config = Config::default();- config.config_path = tmp.path().join("config.toml");- config.workspace_dir = tmp.path().join("workspace");- config.save().await.expect("save fake config to disk");-- std::env::set_var(TRIAGE_DISABLED_ENV, "1");- let sub = ComposioTriggerSubscriber::new();- // Should complete without panicking (env gate fires, triage skipped).- sub.handle(&DomainEvent::ComposioTriggerReceived {- toolkit: "gmail".into(),- trigger: "GMAIL_NEW_GMAIL_MESSAGE".into(),- metadata_id: "trig-env".into(),- metadata_uuid: "uuid-env".into(),- payload: json!({ "subject": "env gate test" }),- })- .await;- std::env::remove_var(TRIAGE_DISABLED_ENV);-- unsafe {- std::env::remove_var("OPENHUMAN_WORKSPACE");- }+fn triage_skip_reason_applies_the_kill_switch_and_config_gates() {+ let mut config = crate::config::Config::default();+ assert_eq!(triage_skip_reason(Some(&config), "gmail", false), None);+ // The env kill-switch wins even when the config would allow triage.+ assert!(triage_skip_reason(Some(&config), "gmail", true).is_some());++ config.composio.triage_disabled_toolkits = vec!["GMAIL".into()];+ assert!(triage_skip_reason(Some(&config), "gmail", false).is_some());+ assert_eq!(triage_skip_reason(Some(&config), "github", false), None);++ config.composio.triage_disabled = true;+ assert!(triage_skip_reason(Some(&config), "github", false).is_some());+ // An unreadable config fails open.+ assert_eq!(triage_skip_reason(None, "github", false), None);}#[tokio::test]diff --git a/crates/openhuman-core/src/modules/ops_tests.rs b/crates/openhuman-core/src/modules/ops_tests.rsindex 345d834c13..b7b343203d 100644--- a/crates/openhuman-core/src/modules/ops_tests.rs+++ b/crates/openhuman-core/src/modules/ops_tests.rs@@ -46,35 +46,43 @@ fn test_bundled_record() -> &'static crate::modules::types::ModuleRecord {}))}+/// The record pins the empty-input digest, so `b""` is a bundle whose digest+/// matches but whose archive cannot be read, and `b"tampered"` is one whose+/// digest does not match. Both must be reported, never replaced by the cache.#[tokio::test]-async fn invalid_installer_bundle_is_reported_without_falling_back_to_the_cache() {- let record = test_bundled_record();- let bundled = tempfile::tempdir().unwrap();- let user_cache = tempfile::tempdir().unwrap();- let bundle_dir = tinybus::module::artifact_dir(- bundled.path(),- record.id,- record.version,- record.assets[0].host_key,- )- .unwrap();- std::fs::create_dir_all(&bundle_dir).unwrap();- std::fs::write(bundle_dir.join(record.assets[0].archive), b"").unwrap();-- let runtime = crate::modules::runtime::runtime().await.unwrap();- let error = Resolver::load_cached(- runtime,- &record.release(),- user_cache.path(),- &serde_json::json!({}),- false,- Some(bundled.path()),- )- .unwrap_err();-- assert!(error.contains("installer bundle"), "{error}");- assert!(error.contains("repairing the installation"), "{error}");- assert!(!user_cache.path().join(record.id).exists());+async fn a_bad_installer_bundle_is_reported_without_falling_back_to_the_cache() {+ for staged in [&b""[..], &b"tampered"[..]] {+ let record = test_bundled_record();+ let bundled = tempfile::tempdir().unwrap();+ let user_cache = tempfile::tempdir().unwrap();+ let bundle_dir = tinybus::module::artifact_dir(+ bundled.path(),+ record.id,+ record.version,+ record.assets[0].host_key,+ )+ .unwrap();+ std::fs::create_dir_all(&bundle_dir).unwrap();+ std::fs::write(bundle_dir.join(record.assets[0].archive), staged).unwrap();++ let runtime = crate::modules::runtime::runtime().await.unwrap();+ let error = Resolver::load_cached(+ runtime,+ &record.release(),+ user_cache.path(),+ &serde_json::json!({}),+ false,+ Some(bundled.path()),+ )+ .unwrap_err();++ assert!(error.contains("installer bundle"), "{staged:?}: {error}");+ assert!(+ error.contains("repairing the installation"),+ "{staged:?}: {error}"+ );+ assert!(!user_cache.path().join(record.id).exists());+ }}#[tokio::test]