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
fix: correct test module paths for artifact-related tests
Steven Enamakelbec30abfc8a1
diff --git a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rsindex 4913d6d578..1b185b02a1 100644--- a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs+++ b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs@@ -6,12 +6,21 @@ use tinyagents_harness::artifacts::tool_results::apply_per_result_persistence;use tinytools::Tool;/// End to end through OpenHuman's wiring: the real `sanitize_text` redacts the-/// stored body and the preview, and the real `file_read` opens the artifact at-/// the path the envelope names.+/// stored body and the preview, the file lands under the workspace rather than+/// the project the agent is editing, and the real `file_read` opens it at the+/// absolute path the envelope names, under the strictest policy shape+/// (enabled, `workspace_only`, action dir outside the workspace).#[tokio::test]-async fn threshold_persists_preview_and_readable_file() {+async fn threshold_persists_outside_the_project_and_reads_back() {let tmp = tempfile::tempdir().unwrap();- let store = new_tool_result_store(tmp.path().to_path_buf(), "session/one");+ let workspace = tmp.path().join("workspace");+ let project = tmp.path().join("project");+ std::fs::create_dir_all(&workspace).unwrap();+ std::fs::create_dir_all(&project).unwrap();+ let store = new_tool_result_store(+ crate::security::policy::tool_result_artifacts_dir(&workspace),+ "session/one",+ );let raw = format!("{} {}","x".repeat(4096),@@ -28,23 +37,28 @@ async fn threshold_persists_preview_and_readable_file() {).await;+ let expected = workspace.join("artifacts/tool-results/session_one/shell/call-1.txt");+ let pointer = expected.to_string_lossy().into_owned();assert!(outcome.persisted);- assert!(out.contains("artifact_path: artifacts/tool-results/session_one/shell/call-1.txt"));+ assert!(out.contains(&format!("artifact_path: {pointer}\n")), "{out}");assert!(out.contains("original_bytes:"));assert!(out.contains("[preview]"));assert!(!out.contains("ghp_abcdefghijklmnopqrstuvwxyz123456"));+ assert!(expected.is_file());+ assert_eq!(+ std::fs::read_dir(&project).unwrap().count(),+ 0,+ "nothing may be written into the project"+ );- let policy = Arc::new(SecurityPolicy {- autonomy: AutonomyLevel::ReadOnly,- action_dir: tmp.path().to_path_buf(),- workspace_dir: tmp.path().to_path_buf(),- ..SecurityPolicy::default()- });+ let cfg = crate::config::AutonomyConfig {+ enabled: true,+ workspace_only: true,+ ..crate::config::AutonomyConfig::default()+ };+ let policy = Arc::new(SecurityPolicy::from_config(&cfg, &workspace, &project));let reader = FileReadTool::new(policy);- let read = reader- .execute(json!({"path": "artifacts/tool-results/session_one/shell/call-1.txt"}))- .await- .unwrap();+ let read = reader.execute(json!({"path": pointer})).await.unwrap();assert!(!read.is_error, "{}", read.output());assert!(read.output().contains("xxxx"));assert!(!read@@ -52,18 +66,50 @@ async fn threshold_persists_preview_and_readable_file() {.contains("ghp_abcdefghijklmnopqrstuvwxyz123456"));}+/// The legacy store still reads the layout older builds wrote, so its sweep+/// finds what they left in a project.+#[test]+fn legacy_store_is_rooted_in_the_action_dir() {+ let tmp = tempfile::tempdir().unwrap();+ let legacy = legacy_action_dir_store(tmp.path().to_path_buf(), "s");+ assert!(!legacy.is_detached());+ assert_eq!(+ legacy.path_for_read_tool("shell", Some("c")),+ "artifacts/tool-results/s/shell/c.txt"+ );+}+/// The vocabulary passed to the crate is OpenHuman's: `file_read` reads,/// `use_skill` is the only wrapper followed.#[test]fn read_targets_use_openhumans_tool_names() {let path = "artifacts/tool-results/s/shell/c.txt";- assert!(artifact_read_target("file_read", &json!({"path": path})).is_some());+ assert!(artifact_read_target(None, "file_read", &json!({"path": path})).is_some());assert!(artifact_read_target(+ None,"use_skill",&json!({"skill": "files", "tool": "file_read", "args": {"path": path, "offset": 3}})).is_some_and(|read| read.offset == 3));- assert!(artifact_read_target("glob", &json!({"path": path})).is_none());+ assert!(artifact_read_target(None, "glob", &json!({"path": path})).is_none());+}++/// With the session's store, its absolute pointers page like the relative ones+/// did, wrapped in `use_skill` or not.+#[test]+fn read_targets_recognise_the_detached_stores_absolute_pointers() {+ let tmp = tempfile::tempdir().unwrap();+ let store = new_tool_result_store(tmp.path().join("tool-results"), "s");+ let pointer = store.path_for_read_tool("shell", Some("c"));+ assert!(artifact_read_target(Some(&store), "file_read", &json!({"path": pointer})).is_some());+ assert!(artifact_read_target(+ Some(&store),+ "use_skill",+ &json!({"skill": "files", "tool": "file_read", "args": {"path": pointer, "offset": 3}})+ )+ .is_some_and(|read| read.offset == 3));+ // Without the store there is nothing to recognise an absolute path against.+ assert!(artifact_read_target(None, "file_read", &json!({"path": pointer})).is_none());}/// A continuation names `file_read` and the offset, in the wire format thediff --git a/crates/openhuman-core/src/agent/session_host/artifact_wiring_tests.rs b/crates/openhuman-core/src/agent/session_host/artifact_wiring_tests.rsnew file mode 100644index 0000000000..a180ba1120--- /dev/null+++ b/crates/openhuman-core/src/agent/session_host/artifact_wiring_tests.rs@@ -0,0 +1,88 @@+use super::*;++const DAY: std::time::Duration = std::time::Duration::from_secs(24 * 60 * 60);++fn age(path: &Path, by: std::time::Duration) {+ let old = std::time::SystemTime::now() - by;+ let file = std::fs::File::options().write(true).open(path).unwrap();+ file.set_modified(old).unwrap();+}++fn stale_session(root: &Path, session: &str) -> PathBuf {+ let dir = root.join(session).join("shell");+ std::fs::create_dir_all(&dir).unwrap();+ let file = dir.join("call.txt");+ std::fs::write(&file, "old output").unwrap();+ age(&file, 2 * DAY);+ // A directory's own mtime counts toward freshness too.+ for d in [dir.as_path(), dir.parent().unwrap()] {+ let handle = std::fs::File::open(d).unwrap();+ handle.set_modified(std::time::SystemTime::now() - 2 * DAY).unwrap();+ }+ root.join(session)+}++/// The store writes under the workspace, never the action directory, whether+/// or not the turn carries a workspace descriptor.+#[test]+fn the_store_is_rooted_in_the_workspace_not_the_action_dir() {+ let tmp = tempfile::tempdir().unwrap();+ let workspace = tmp.path().join("workspace");+ let action = tmp.path().join("project");+ let descriptor = tinytools::WorkspaceDescriptor {+ root: tmp.path().join("checkout"),+ trusted_roots: Vec::new(),+ policy_id: String::new(),+ sandbox: Default::default(),+ };++ for descriptor in [None, Some(&descriptor)] {+ let store = build_artifact_store(&workspace, descriptor, &action, "s");+ assert!(store.is_detached());+ assert_eq!(store.root(), tool_result_artifacts_dir(&workspace));+ let pointer = store.path_for_read_tool("shell", Some("c"));+ assert!(Path::new(&pointer).starts_with(workspace.join("artifacts/tool-results")));+ }+}++/// Artifacts older builds left in the project keep being swept with the age+/// rule they always had, while a fresh one (a concurrent older session) and the+/// current session are left alone.+#[test]+fn stale_artifacts_left_in_the_project_by_older_builds_are_swept() {+ let tmp = tempfile::tempdir().unwrap();+ let workspace = tmp.path().join("workspace");+ let action = tmp.path().join("project");+ let legacy_root = action.join("artifacts/tool-results");+ let stale = stale_session(&legacy_root, "old");+ let fresh = legacy_root.join("recent/shell");+ std::fs::create_dir_all(&fresh).unwrap();+ std::fs::write(fresh.join("call.txt"), "recent").unwrap();+ let detached_stale = stale_session(&tool_result_artifacts_dir(&workspace), "older");++ build_artifact_store(&workspace, None, &action, "current");++ assert!(!stale.exists(), "a stale legacy session is swept");+ assert!(fresh.join("call.txt").exists(), "a fresh one is kept");+ assert!(!detached_stale.exists(), "the workspace store is swept too");+}++#[test]+fn legacy_roots_include_a_distinct_descriptor_root_once() {+ let action = PathBuf::from("/p/action");+ let descriptor = |root: &str| tinytools::WorkspaceDescriptor {+ root: PathBuf::from(root),+ trusted_roots: Vec::new(),+ policy_id: String::new(),+ sandbox: Default::default(),+ };+ assert_eq!(legacy_roots(None, &action), vec![action.clone()]);+ assert_eq!(+ legacy_roots(Some(&descriptor("/p/action")), &action),+ vec![action.clone()]+ );+ assert_eq!(+ legacy_roots(Some(&descriptor("/p/checkout")), &action),+ vec![action.clone(), PathBuf::from("/p/checkout")]+ );+}diff --git a/crates/openhuman-core/src/security/policy/policy_action_dir_tests.rs b/crates/openhuman-core/src/security/policy/policy_action_dir_tests.rsindex 3a10f40422..fd24869cf2 100644--- a/crates/openhuman-core/src/security/policy/policy_action_dir_tests.rs+++ b/crates/openhuman-core/src/security/policy/policy_action_dir_tests.rs@@ -81,3 +81,47 @@ fn from_config_does_not_grant_an_action_dir_covering_the_workspace() {policy.trusted_roots);}++/// Oversized tool outputs are saved under `<workspace>/artifacts/tool-results`+/// and pointed at by absolute path. Under `workspace_only` an absolute path is+/// refused unless a trusted root covers it, so `from_config` grants that one+/// directory — read-only — and nothing else under the workspace.+#[tokio::test]+async fn tool_result_artifacts_are_readable_by_absolute_path_under_workspace_only() {+ let tmp = tempfile::tempdir().expect("tempdir");+ let workspace = tmp.path().join("workspace");+ let action = tmp.path().join("project");+ let artifacts = super::tool_result_artifacts_dir(&workspace).join("s1/shell");+ fs::create_dir_all(&artifacts).unwrap();+ fs::create_dir_all(&action).unwrap();+ fs::write(artifacts.join("call.txt"), "output").unwrap();+ let record = workspace.join("artifacts/abc");+ fs::create_dir_all(&record).unwrap();+ fs::write(record.join("meta.json"), "{}").unwrap();++ let cfg = crate::config::AutonomyConfig {+ enabled: true,+ workspace_only: true,+ ..crate::config::AutonomyConfig::default()+ };+ let policy = SecurityPolicy::from_config(&cfg, &workspace, &action);++ let grant = super::tool_result_artifacts_dir(&workspace)+ .to_string_lossy()+ .to_string();+ assert!(policy+ .trusted_roots+ .iter()+ .any(|r| r.path == grant && r.access == TrustedAccess::ReadOnly));++ let result = artifacts.join("call.txt");+ policy+ .validate_path(&result.to_string_lossy())+ .await+ .expect("a tool-result artifact must be readable by absolute path");+ // The grant is that directory only: internal artifact records stay closed.+ assert!(policy+ .validate_path(&record.join("meta.json").to_string_lossy())+ .await+ .is_err());+}