Skip to content

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

chore: files changed crates/openhuman-core/src/cron/schemas_tests.rs

Steven Enamakel43f6d76b8171
diff --git a/crates/openhuman-core/src/cron/schemas_tests.rs b/crates/openhuman-core/src/cron/schemas_tests.rs
index f8a685f9d2..614d48a06b 100644
--- a/crates/openhuman-core/src/cron/schemas_tests.rs
+++ b/crates/openhuman-core/src/cron/schemas_tests.rs
@@ -1,5 +1,30 @@
use super::*;
use serde_json::json;
+use tempfile::TempDir;
+
+async fn cron_test_runtime(config: crate::config::Config) -> crate::core::runtime::CoreRuntime {
+ use crate::core::runtime::{CoreBuilder, DomainSet, ServiceSet};
+ use crate::core::types::HostKind;
+
+ CoreBuilder::new(HostKind::Cli)
+ .domains(DomainSet::all())
+ .services(ServiceSet::none())
+ .config(config)
+ .build()
+ .await
+ .unwrap()
+}
+
+fn cron_test_config(tmp: &TempDir) -> crate::config::Config {
+ let config = crate::config::Config {
+ workspace_dir: tmp.path().join("workspace"),
+ action_dir: tmp.path().join("workspace"),
+ config_path: tmp.path().join("config.toml"),
+ ..Default::default()
+ };
+ std::fs::create_dir_all(&config.workspace_dir).unwrap();
+ config
+}
// ── schemas() branch coverage ───────────────────────────────────
@@ -85,6 +110,60 @@ fn schemas_add_requires_schedule_and_returns_job() {
assert_eq!(s.outputs[0].name, "job");
}
+#[tokio::test]
+async fn rpc_add_rejects_disallowed_target_even_with_request_origin_spoof() {
+ let tmp = TempDir::new().unwrap();
+ let mut config = cron_test_config(&tmp);
+ config.channels_config.telegram = Some(crate::config::TelegramConfig {
+ bot_token: "test-token".into(),
+ chat_id: None,
+ allowed_users: vec!["alice".into()],
+ stream_mode: Default::default(),
+ draft_update_interval_ms: 1000,
+ silent_streaming: true,
+ mention_only: false,
+ });
+ let runtime = cron_test_runtime(config.clone()).await;
+ let result = runtime
+ .invoke(
+ "openhuman.cron_add",
+ json!({
+ "job_type": "agent",
+ "schedule": {"kind":"every", "every_ms":300000},
+ "prompt": "check inbox",
+ "session_target": "isolated",
+ "delivery": {"mode":"announce", "channel":"telegram", "to":"42", "best_effort":true},
+ "origin": {"kind":"channel", "channel":"telegram", "reply_target":"42", "history_key":"telegram_alice_42", "sender":"alice"}
+ }),
+ )
+ .await;
+ assert!(
+ result.unwrap_err().contains("allowed"),
+ "RPC-supplied origin must not bypass the configured recipient allowlist"
+ );
+ assert!(crate::cron::list_jobs(&config).unwrap().is_empty());
+}
+
+#[tokio::test]
+async fn rpc_add_refuses_when_cron_is_disabled_without_creating_job() {
+ let tmp = TempDir::new().unwrap();
+ let mut config = cron_test_config(&tmp);
+ config.cron.enabled = false;
+ let runtime = cron_test_runtime(config.clone()).await;
+ let result = runtime
+ .invoke(
+ "openhuman.cron_add",
+ json!({
+ "job_type": "shell",
+ "schedule": {"kind":"every", "every_ms":300000},
+ "command": "echo harmless"
+ }),
+ )
+ .await;
+ assert!(result.unwrap_err().contains("cron is disabled"));
+ assert!(crate::cron::list_jobs(&config).unwrap().is_empty());
+}
+
#[test]
fn all_controller_schemas_covers_every_supported_function() {
let names: Vec<_> = all_controller_schemas()