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(agent): add host runtime tests
Steven Enamakel5178a797049d
diff --git a/crates/openhuman-core/src/agent/host_runtime_tests.rs b/crates/openhuman-core/src/agent/host_runtime_tests.rsindex 66e3b58563..9f47eda721 100644--- a/crates/openhuman-core/src/agent/host_runtime_tests.rs+++ b/crates/openhuman-core/src/agent/host_runtime_tests.rs@@ -2,7 +2,7 @@ use super::*;use crate::config::{DockerRuntimeConfig, RuntimeConfig};#[test]-fn native_runtime_reports_capabilities_and_shell_command() {+fn native_runtime_reports_capabilities_and_shell_flavor() {let runtime = NativeRuntime::new();assert_eq!(runtime.name(), "native");assert!(runtime.has_shell_access());@@ -10,34 +10,8 @@ fn native_runtime_reports_capabilities_and_shell_command() {assert!(runtime.supports_long_running());assert_eq!(runtime.memory_budget(), 0);assert!(runtime.storage_path().ends_with("openhuman/runtime"));-- // Use a tempdir so `ensure_usable_cwd` accepts the path on every- // OS (`/tmp` does not exist on Windows).- let tempdir = tempfile::tempdir().unwrap();- let command = runtime- .build_shell_command("echo hi", tempdir.path())- .unwrap();- let prog = command- .as_std()- .get_program()- .to_string_lossy()- .into_owned();- let args: Vec<String> = command- .as_std()- .get_args()- .map(|arg| arg.to_string_lossy().into_owned())- .collect();- // Shell selection is delegated to `platform_shell::build_tokio_command`- // — this test just asserts NativeRuntime is wired into it. The full- // per-platform matrix is covered by `platform_shell::tests`.- if cfg!(windows) {- assert_eq!(prog, "cmd");- assert_eq!(args, vec!["/C".to_string(), "echo hi".to_string()]);- } else {- assert!(prog.ends_with("bash") || prog == "sh");- assert_eq!(args.first().map(String::as_str), Some("-lc"));- }- assert_eq!(command.as_std().get_current_dir(), Some(tempdir.path()));+ assert!(!runtime.hide_window());+ assert_eq!(runtime.shell_flavor(), host_shell_flavor());}#[test]@@ -78,7 +52,8 @@ fn docker_runtime_builds_expected_flags() {assert_eq!(request.command, "pwd");assert!(request.login_shell, "legacy DockerRuntime used sh -lc");assert_eq!(request.label.as_deref(), Some("openhuman.runtime=true"));- assert!(runtime.build_shell_command("pwd", tempdir.path()).is_err());+ assert_eq!(runtime.shell_flavor(), ShellFlavor::Posix);+ assert!(!runtime.hide_window());}#[cfg(feature = "modules")]@@ -127,107 +102,36 @@ fn create_runtime_supports_native_and_docker_and_rejects_unknown() {}/// `[shell] hide_window` plumbs through `create_runtime` into the native-/// adapter, and a hide-window native runtime still builds a usable shell-/// command on every platform (the `CREATE_NO_WINDOW` flag is Windows-only-/// and applied without disturbing the command on macOS/Linux).-#[test]-fn native_runtime_with_hide_window_still_builds_shell_command() {- let native = create_runtime(&RuntimeConfig::default(), true).unwrap();- assert_eq!(native.name(), "native");-- // Tempdir so `ensure_usable_cwd` accepts it on Windows CI too.- let tempdir = tempfile::tempdir().unwrap();- let runtime = NativeRuntime::with_hide_window(true);- let command = runtime- .build_shell_command("echo hi", tempdir.path())- .expect("hide_window should not break command construction");- assert_eq!(command.as_std().get_current_dir(), Some(tempdir.path()));-- // The program/args are identical with and without the flag — hiding the- // window must not alter what is executed.- let plain = NativeRuntime::with_hide_window(false)- .build_shell_command("echo hi", tempdir.path())- .unwrap();- assert_eq!(command.as_std().get_program(), plain.as_std().get_program());-}--/// `maybe_hide_window` is a no-op when disabled (and on non-Windows hosts-/// even when enabled), and must never panic.-#[test]-fn maybe_hide_window_is_safe_no_op() {- let mut disabled = tokio::process::Command::new("echo");- maybe_hide_window(&mut disabled, false);- let mut enabled = tokio::process::Command::new("echo");- maybe_hide_window(&mut enabled, true);- assert_eq!(disabled.as_std().get_program(), "echo");- assert_eq!(enabled.as_std().get_program(), "echo");-}--/// Regression: a failed stage in a pipeline must surface as a non-zero exit-/// (pipefail), so the harness records the call as failed and the-/// repeated-failure circuit breaker can trip — rather than `… | tail`-/// masking the failure as success and letting the agent loop. Only-/// meaningful where bash is present (the pipefail wrapper); on bash-less-/// hosts we fall back to plain `sh` and skip.-#[cfg(unix)]-#[tokio::test]-async fn native_shell_pipefail_surfaces_failed_pipe_stage() {- if platform_shell::bash_path().is_none() {- return; // no bash → plain sh, pipefail unavailable- }- let rt = NativeRuntime::new();- let dir = std::env::temp_dir();-- let mut failing = rt.build_shell_command("false | true", &dir).unwrap();- let status = failing.status().await.unwrap();- assert!(- !status.success(),- "pipefail must surface the failed `false` stage, not mask it behind `true`"- );-- // A clean pipeline still succeeds.- let mut ok = rt.build_shell_command("true | true", &dir).unwrap();- assert!(ok.status().await.unwrap().success());-}--/// #3353: a CWD that can't be made usable (here: a path *under an existing-/// file*, which `create_dir_all` cannot create) must yield a descriptive,-/// path-naming error from `build_shell_command` instead of an opaque OS-/// error 267 (ERROR_DIRECTORY) at spawn time.+/// adapter, which hands it to TinyBox on the native shell request.#[test]-fn native_shell_command_rejects_uncreatable_cwd_with_clear_error() {- let rt = NativeRuntime::new();- let tmp = tempfile::tempdir().unwrap();- let parent_file = tmp.path().join("a-file");- std::fs::write(&parent_file, b"x").unwrap();- let bad_cwd = parent_file.join("child"); // parent is a file → uncreatable-- let err = rt- .build_shell_command("echo hi", &bad_cwd)- .expect_err("an uncreatable CWD must be rejected up front");- let msg = err.to_string();- assert!(- msg.contains("could not be created"),- "expected an actionable message, got: {msg}"- );- assert!(- msg.contains(&bad_cwd.to_string_lossy().to_string()),- "error should name the offending path: {msg}"- );+fn hide_window_reaches_the_native_runtime_only() {+ assert!(create_runtime(&RuntimeConfig::default(), true)+ .unwrap()+ .hide_window());+ assert!(!create_runtime(&RuntimeConfig::default(), false)+ .unwrap()+ .hide_window());+ assert!(NativeRuntime::with_hide_window(true).hide_window());+ assert!(!NativeRuntime::new().hide_window());+ let docker = create_runtime(+ &RuntimeConfig {+ kind: "docker".into(),+ ..RuntimeConfig::default()+ },+ true,+ )+ .unwrap();+ assert!(!docker.hide_window(), "docker runs in a container, not a console");}-/// A valid-but-missing CWD is defensively created (covers a dir deleted-/// after launch), so the command builds successfully and runs there.+/// The shell flavor told to the model is the one TinyBox's `SelectShell`+/// returns for this machine, and is the contract's own type.#[test]-fn native_shell_command_creates_missing_cwd() {- let rt = NativeRuntime::new();- let tmp = tempfile::tempdir().unwrap();- let missing = tmp.path().join("nested").join("workdir");- assert!(!missing.exists());-- let command = rt- .build_shell_command("echo hi", &missing)- .expect("missing CWD should be auto-created");- assert!(missing.is_dir(), "CWD should have been created");- assert_eq!(command.as_std().get_current_dir(), Some(missing.as_path()));+fn host_shell_flavor_matches_the_platform_the_module_selects() {+ let expected = if cfg!(windows) {+ tinybox_bus::ShellFlavor::Cmd+ } else {+ tinybox_bus::ShellFlavor::Posix+ };+ assert_eq!(host_shell_flavor(), expected);}