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(shell): add shell execution tests for sandbox fixtures
Steven Enamakelc75fded4e9b8
diff --git a/crates/openhuman-core/src/sandbox/shell_exec_fixture.rs b/crates/openhuman-core/src/sandbox/shell_exec_fixture.rsindex 4f80ca0c65..c5c9775654 100644--- a/crates/openhuman-core/src/sandbox/shell_exec_fixture.rs+++ b/crates/openhuman-core/src/sandbox/shell_exec_fixture.rs@@ -43,6 +43,15 @@ pub(crate) async fn run(run: NativeShellRun) -> anyhow::Result<SandboxExecResult}}}+ if run.python_utf8 {+ // The module defaults these unless the parent environment sets them.+ for (name, default) in [("PYTHONUTF8", "1"), ("PYTHONIOENCODING", "utf-8")] {+ command.env(+ name,+ std::env::var_os(name).unwrap_or_else(|| default.into()),+ );+ }+ }command.envs(&run.env);command.current_dir(&run.cwd)diff --git a/crates/openhuman-core/src/tools/impl/system/shell_tests.rs b/crates/openhuman-core/src/tools/impl/system/shell_tests.rsindex 60ae1cd8c6..f13ee919ad 100644--- a/crates/openhuman-core/src/tools/impl/system/shell_tests.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell_tests.rs@@ -1,4 +1,3 @@-use super::super::shell_platform::{PYTHON_UTF8_DEFAULTS, SAFE_ENV_VARS};use super::*;use crate::agent::host_runtime::{NativeRuntime, RuntimeAdapter};use crate::security::{AutonomyLevel, SecurityPolicy};diff --git a/crates/openhuman-core/src/tools/impl/system/shell_tests_platform_tests.rs b/crates/openhuman-core/src/tools/impl/system/shell_tests_platform_tests.rsindex a5a55e7d58..d93b046df0 100644--- a/crates/openhuman-core/src/tools/impl/system/shell_tests_platform_tests.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell_tests_platform_tests.rs@@ -1,11 +1,11 @@-//! Platform-aware shell description and the child environment builder-//! (`shell_platform.rs`), exercised through the `shell` tool.+//! Platform-aware shell description (`shell_description.rs`) and the Python+//! encoding defaults, exercised through the `shell` tool.//!-//! Both take the platform / parent environment as a parameter so the Windows-//! behaviour is pinned on every CI host, not only on a Windows runner.+//! The description takes the platform as a parameter so the Windows wording is+//! pinned on every CI host, not only on a Windows runner.use super::*;-use crate::agent::platform_shell::ShellFlavor;+use crate::agent::host_runtime::{host_shell_flavor, ShellFlavor};use std::collections::HashMap;use std::ffi::OsString;@@ -53,7 +53,7 @@ fn the_tool_describes_the_shell_this_host_actually_spawns() {);assert_eq!(tool.description(),- shell_description(ShellFlavor::current())+ shell_description(host_shell_flavor()));let command_desc = tool.parameters_schema()["properties"]["command"]["description"].as_str()@@ -61,7 +61,7 @@ fn the_tool_describes_the_shell_this_host_actually_spawns() {.to_string();assert_eq!(command_desc,- command_param_description(ShellFlavor::current())+ command_param_description(host_shell_flavor()));assert!(command_param_description(ShellFlavor::Cmd).contains("cmd.exe"));}@@ -80,22 +80,9 @@ fn as_map(env: Vec<(&'static str, OsString)>) -> HashMap<&'static str, String> {.collect()}-#[test]-fn python_children_default_to_utf8_io() {- // Production: `UnicodeEncodeError: 'charmap'` from Python under cmd.exe,- // whose console code page is not UTF-8.- let env = as_map(shell_child_env(parent(&[("PATH", "/bin")])));- assert_eq!(env.get("PYTHONUTF8").map(String::as_str), Some("1"));- assert_eq!(- env.get("PYTHONIOENCODING").map(String::as_str),- Some("utf-8")- );- assert_eq!(env.get("PATH").map(String::as_str), Some("/bin"));-}-#[test]fn a_users_own_python_encoding_settings_win() {- let env = as_map(shell_child_env(parent(&[+ let env = as_map(python_utf8_env(parent(&[("PYTHONUTF8", "0"),("PYTHONIOENCODING", "latin-1"),])));@@ -106,23 +93,25 @@ fn a_users_own_python_encoding_settings_win() {);}-#[test]-fn the_child_env_forwards_only_the_allow_list_plus_python_defaults() {- let env = as_map(shell_child_env(parent(&[- ("PATH", "/bin"),- ("USERPROFILE", "C:\\Users\\me"),- ("OPENAI_API_KEY", "sk-secret"),- ("AWS_SECRET_ACCESS_KEY", "secret"),- ])));- assert_eq!(- env.get("USERPROFILE").map(String::as_str),- Some("C:\\Users\\me")- );+/// A Docker container gets the sandbox allowlist from the turn's environment+/// plus the Python defaults, and never the rest of it.+#[cfg(feature = "modules")]+#[tokio::test]+async fn the_container_environment_forwards_only_the_allowlist_plus_python_defaults() {+ let scoped = crate::tools::timeout::CommandEnvironment::new([+ ("PATH".to_owned(), "/bin".to_owned()),+ ("OPENAI_API_KEY".to_owned(), "sk-secret".to_owned()),+ ("AWS_SECRET_ACCESS_KEY".to_owned(), "secret".to_owned()),+ ]);+ let env = scoped.scope(async { container_environment() }).await.unwrap();+ assert_eq!(env.get("PATH").map(String::as_str), Some("/bin"));+ assert_eq!(env.get("PYTHONUTF8").map(String::as_str), Some("1"));assert!(!env.contains_key("OPENAI_API_KEY"));assert!(!env.contains_key("AWS_SECRET_ACCESS_KEY"));for key in env.keys() {assert!(- SAFE_ENV_VARS.contains(key) || PYTHON_UTF8_DEFAULTS.iter().any(|(k, _)| k == key),+ crate::sandbox::ops::SANDBOX_ENV_PASSTHROUGH.contains(&key.as_str())+ || PYTHON_UTF8_DEFAULTS.iter().any(|(k, _)| k == key),"unexpected {key}");}@@ -179,13 +168,6 @@ impl RuntimeAdapter for CmdRuntime {fn shell_flavor(&self) -> ShellFlavor {ShellFlavor::Cmd}- fn build_shell_command(- &self,- _command: &str,- _workspace_dir: &std::path::Path,- ) -> anyhow::Result<tokio::process::Command> {- anyhow::bail!("not spawned in this test")- }}#[test]