Skip to content

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

test(sandbox): add state_dir field to test policies

Steven Enamakel4638aa724800
diff --git a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs b/crates/openhuman-core/src/sandbox/docker_exec_tests.rs
index f127214f04..f330fe351c 100644
--- a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs
+++ b/crates/openhuman-core/src/sandbox/docker_exec_tests.rs
@@ -65,6 +65,7 @@ fn policy(workspace: &Path) -> SandboxPolicy {
SandboxPolicy {
backend: SandboxBackendKind::Docker,
workspace_root: workspace.to_path_buf(),
+ state_dir: PathBuf::from("/tmp/state"),
read_only_mounts: vec![],
allow_network: false,
env_passthrough: vec![],
diff --git a/crates/openhuman-core/src/sandbox/docker_tests.rs b/crates/openhuman-core/src/sandbox/docker_tests.rs
index 96b65d7b0a..f358f81775 100644
--- a/crates/openhuman-core/src/sandbox/docker_tests.rs
+++ b/crates/openhuman-core/src/sandbox/docker_tests.rs
@@ -6,6 +6,7 @@ fn test_policy() -> SandboxPolicy {
SandboxPolicy {
backend: SandboxBackendKind::Docker,
workspace_root: PathBuf::from("/tmp/test-workspace"),
+ state_dir: PathBuf::from("/tmp/state"),
read_only_mounts: vec![],
allow_network: false,
env_passthrough: vec!["PATH".into(), "HOME".into()],
diff --git a/crates/openhuman-core/src/sandbox/ops_tests.rs b/crates/openhuman-core/src/sandbox/ops_tests.rs
index 64b615a4b7..1e59b59215 100644
--- a/crates/openhuman-core/src/sandbox/ops_tests.rs
+++ b/crates/openhuman-core/src/sandbox/ops_tests.rs
@@ -6,6 +6,7 @@ fn resolve_sandbox_policy_none_mode() {
let policy = resolve_sandbox_policy(
SandboxMode::None,
Path::new("/tmp/action"),
+ Path::new("/tmp/state"),
&RuntimeConfig::default(),
false,
);
@@ -17,6 +18,7 @@ fn resolve_sandbox_policy_read_only_mode() {
let policy = resolve_sandbox_policy(
SandboxMode::ReadOnly,
Path::new("/tmp/action"),
+ Path::new("/tmp/state"),
&RuntimeConfig::default(),
false,
);
@@ -28,6 +30,7 @@ fn resolve_sandbox_policy_sandboxed_local() {
let policy = resolve_sandbox_policy(
SandboxMode::Sandboxed,
Path::new("/tmp/action"),
+ Path::new("/tmp/state"),
&RuntimeConfig::default(),
false,
);
@@ -40,6 +43,7 @@ fn resolve_sandbox_policy_sandboxed_remote_uses_docker() {
let policy = resolve_sandbox_policy(
SandboxMode::Sandboxed,
Path::new("/tmp/action"),
+ Path::new("/tmp/state"),
&RuntimeConfig::default(),
true,
);
@@ -57,6 +61,7 @@ fn resolve_sandbox_policy_docker_runtime_forces_docker() {
let policy = resolve_sandbox_policy(
SandboxMode::Sandboxed,
Path::new("/tmp/action"),
+ Path::new("/tmp/state"),
&config,
false,
);
@@ -85,6 +90,7 @@ async fn create_sandbox_backend_none() {
let policy = resolve_sandbox_policy(
SandboxMode::None,
Path::new("/tmp"),
+ Path::new("/tmp/state"),
&RuntimeConfig::default(),
false,
);
@@ -98,6 +104,7 @@ async fn create_sandbox_backend_local() {
let policy = resolve_sandbox_policy(
SandboxMode::Sandboxed,
Path::new("/tmp"),
+ Path::new("/tmp/state"),
&RuntimeConfig::default(),
false,
);
@@ -201,6 +208,7 @@ async fn execute_in_sandbox_none_backend() {
let policy = resolve_sandbox_policy(
SandboxMode::None,
Path::new("/tmp"),
+ Path::new("/tmp/state"),
&RuntimeConfig::default(),
false,
);
@@ -226,6 +234,7 @@ async fn execute_in_sandbox_preserves_non_utf8_environment_bytes() {
let policy = resolve_sandbox_policy(
SandboxMode::None,
tempdir.path(),
+ Path::new("/tmp/state"),
&RuntimeConfig::default(),
false,
);
@@ -256,6 +265,7 @@ async fn execute_in_sandbox_none_backend_runs_on_every_os() {
let policy = resolve_sandbox_policy(
SandboxMode::None,
tempdir.path(),
+ Path::new("/tmp/state"),
&RuntimeConfig::default(),
false,
);
@@ -312,10 +322,11 @@ fn local_status_is_ready_for_a_real_jail() {
// ── #6961: local-jail output capture stays out of the user's project ─────────
#[cfg(unix)]
-fn local_policy(action_dir: &Path) -> SandboxPolicy {
+fn local_policy(action_dir: &Path, state_dir: &Path) -> SandboxPolicy {
let policy = resolve_sandbox_policy(
SandboxMode::Sandboxed,
action_dir,
+ state_dir,
&RuntimeConfig::default(),
false,
);
@@ -352,7 +363,8 @@ fn entries(dir: &Path) -> Vec<String> {
#[tokio::test]
async fn local_jail_writes_no_capture_files_into_the_workspace_root() {
let action = tempfile::tempdir().unwrap();
- let policy = local_policy(action.path());
+ let state = tempfile::tempdir().unwrap();
+ let policy = local_policy(action.path(), state.path());
// `ls -A` runs inside the root while the capture is live, so it sees
// anything the capture put there (this is what `git status` saw).
@@ -368,7 +380,8 @@ async fn local_jail_writes_no_capture_files_into_the_workspace_root() {
#[tokio::test]
async fn concurrent_local_jail_runs_keep_their_outputs_separate() {
let action = tempfile::tempdir().unwrap();
- let policy = local_policy(action.path());
+ let state = tempfile::tempdir().unwrap();
+ let policy = local_policy(action.path(), state.path());
let (a, b) = tokio::join!(
run_local(&policy, "echo a1; echo a-err >&2; sleep 0.4; echo a2"),
diff --git a/crates/openhuman-core/src/sandbox/schemas_tests.rs b/crates/openhuman-core/src/sandbox/schemas_tests.rs
index 8444764123..7ee471bc66 100644
--- a/crates/openhuman-core/src/sandbox/schemas_tests.rs
+++ b/crates/openhuman-core/src/sandbox/schemas_tests.rs
@@ -166,6 +166,7 @@ async fn handle_validate_policy_valid() {
let policy = super::super::types::SandboxPolicy {
backend: super::super::types::SandboxBackendKind::Docker,
workspace_root: std::path::PathBuf::from("/tmp/safe"),
+ state_dir: PathBuf::from("/tmp/state"),
read_only_mounts: vec![],
allow_network: false,
env_passthrough: vec![],
@@ -184,6 +185,7 @@ async fn handle_validate_policy_dangerous() {
let policy = super::super::types::SandboxPolicy {
backend: super::super::types::SandboxBackendKind::Docker,
workspace_root: std::path::PathBuf::from("/"),
+ state_dir: PathBuf::from("/tmp/state"),
read_only_mounts: vec![],
allow_network: false,
env_passthrough: vec![],
diff --git a/crates/openhuman-core/src/sandbox/types_tests.rs b/crates/openhuman-core/src/sandbox/types_tests.rs
index 167b500353..8ffbe0ab2c 100644
--- a/crates/openhuman-core/src/sandbox/types_tests.rs
+++ b/crates/openhuman-core/src/sandbox/types_tests.rs
@@ -37,6 +37,7 @@ fn sandbox_policy_serializes_roundtrip() {
let policy = SandboxPolicy {
backend: SandboxBackendKind::Docker,
workspace_root: PathBuf::from("/workspace"),
+ state_dir: PathBuf::from("/tmp/state"),
read_only_mounts: vec![PathBuf::from("/usr/lib")],
allow_network: false,
env_passthrough: vec!["PATH".into()],