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(harness): add explicit definition test module
Steven Enamakele9ba866f4e58
diff --git a/crates/openhuman-core/src/agent/harness/session/builder/builder_tests.rs b/crates/openhuman-core/src/agent/harness/session/builder/builder_tests.rsindex 31ad48b64c..d3df944742 100644--- a/crates/openhuman-core/src/agent/harness/session/builder/builder_tests.rs+++ b/crates/openhuman-core/src/agent/harness/session/builder/builder_tests.rs@@ -61,6 +61,8 @@ fn custom_profile(id: &str, dedicated_memory: bool) -> crate::agent::profiles::Aprofile}+#[path = "builder_tests_explicit_definition_tests.rs"]+mod explicit_definition_tests;#[path = "builder_tests_memory_write_instruction_tests.rs"]mod memory_write_instruction_tests;#[path = "builder_tests_profile_soul_prompt_tests.rs"]diff --git a/crates/openhuman-core/src/agent/harness/session/builder/builder_tests_explicit_definition_tests.rs b/crates/openhuman-core/src/agent/harness/session/builder/builder_tests_explicit_definition_tests.rsnew file mode 100644index 0000000000..87d879656d--- /dev/null+++ b/crates/openhuman-core/src/agent/harness/session/builder/builder_tests_explicit_definition_tests.rs@@ -0,0 +1,81 @@+//! `from_config_with_definition` and `resolved_definition`: an explicit+//! definition is authoritative for the session it builds, and the in-turn+//! readers (`sandbox_mode`, `subagents`) consult it before the process+//! registry.++use super::*;+use crate::agent::harness::definition::{+ AgentDefinitionRegistry, PromptSource, SandboxMode, ToolScope,+};+use crate::agent::harness::session::types::Agent;++fn explicit_definition(id: &str) -> crate::agent::harness::definition::AgentDefinition {+ let mut def = AgentDefinitionRegistry::builtins_only()+ .get("orchestrator")+ .cloned()+ .expect("built-in orchestrator");+ def.id = id.to_string();+ def.display_name = Some("Explicit".to_string());+ def.system_prompt = PromptSource::Inline("You are explicit.".to_string());+ def.tools = ToolScope::Wildcard;+ def.sandbox_mode = SandboxMode::Sandboxed;+ def+}++#[tokio::test]+async fn from_config_with_definition_stamps_the_definition_on_the_session() {+ let tmp = tempfile::TempDir::new().unwrap();+ let config = test_config(&tmp);+ let def = explicit_definition("embedded-alpha");++ let agent = Agent::from_config_with_definition(&config, &def, None, None)+ .expect("build from an explicit definition");++ assert_eq!(agent.agent_definition_id, "embedded-alpha");+ let resolved = agent+ .resolved_definition()+ .expect("the explicit definition is stamped");+ assert_eq!(resolved.id, "embedded-alpha");+ assert_eq!(resolved.sandbox_mode, SandboxMode::Sandboxed);+ assert!(matches!(resolved.system_prompt, PromptSource::Inline(ref p) if p == "You are explicit."));+}++#[tokio::test]+async fn resolved_definition_prefers_the_sessions_own_over_a_same_id_registry_entry() {+ // A library host may reuse an id the process registry also knows. The+ // session's own definition must win at the security-relevant reads+ // (`sandbox_mode`), never the registry's copy.+ let _ = AgentDefinitionRegistry::init_global_builtins();+ let tmp = tempfile::TempDir::new().unwrap();+ let config = test_config(&tmp);+ let def = explicit_definition("orchestrator");+ assert_ne!(+ AgentDefinitionRegistry::global()+ .and_then(|r| r.get("orchestrator"))+ .map(|d| d.sandbox_mode),+ Some(SandboxMode::Sandboxed),+ "the registry's orchestrator is not sandboxed, so a leak is observable"+ );++ let agent = Agent::from_config_with_definition(&config, &def, None, None)+ .expect("build from an explicit definition");++ assert_eq!(+ agent.resolved_definition().map(|d| d.sandbox_mode),+ Some(SandboxMode::Sandboxed)+ );+}++#[tokio::test]+async fn registry_built_sessions_resolve_the_registry_definition() {+ // Byte-identical behaviour for every existing caller: a session built by+ // id carries the registry's definition and reads it back.+ let _ = AgentDefinitionRegistry::init_global_builtins();+ let tmp = tempfile::TempDir::new().unwrap();+ let config = test_config(&tmp);++ let agent = Agent::from_config(&config).expect("orchestrator session");+ let resolved = agent.resolved_definition().expect("registry definition");+ assert_eq!(resolved.id, "orchestrator");+ assert_eq!(resolved.sandbox_mode, SandboxMode::None);+}