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(edit_file): assert the refused-write report without needing a real refusal
oxoxDevc7fe55dd7011
diff --git a/src/openhuman/tools/impl/filesystem/edit_file.rs b/src/openhuman/tools/impl/filesystem/edit_file.rsindex a8de6a9f67..420b095eba 100644--- a/src/openhuman/tools/impl/filesystem/edit_file.rs+++ b/src/openhuman/tools/impl/filesystem/edit_file.rs@@ -18,11 +18,22 @@ const MAX_FILE_BYTES: u64 = 5 * 1024 * 1024;pub struct EditFileTool {security: Arc<SecurityPolicy>,+ sink: Arc<dyn super::write_sink::FileSink>,}impl EditFileTool {pub fn new(security: Arc<SecurityPolicy>) -> Self {- Self { security }+ Self {+ security,+ sink: super::write_sink::os_sink(),+ }+ }++ /// Sends this tool's writes somewhere other than the OS.+ #[cfg(test)]+ pub fn with_sink(mut self, sink: Arc<dyn super::write_sink::FileSink>) -> Self {+ self.sink = sink;+ self}}@@ -204,7 +215,7 @@ impl EditFileTool {contents.replacen(old_string, new_string, 1)};- match tokio::fs::write(&resolved, &updated).await {+ match self.sink.write(&resolved, updated.as_bytes()).await {Ok(()) => {if let Some(agent_id) = file_state::current_file_state_agent_id() {file_state::record_write(&agent_id, resolved);diff --git a/src/openhuman/tools/impl/filesystem/edit_file_tests.rs b/src/openhuman/tools/impl/filesystem/edit_file_tests.rsindex 8f0121dee7..04ff552e42 100644--- a/src/openhuman/tools/impl/filesystem/edit_file_tests.rs+++ b/src/openhuman/tools/impl/filesystem/edit_file_tests.rs@@ -157,54 +157,30 @@ async fn edit_rejects_identical_strings() {}#[tokio::test]-#[cfg(unix)]async fn edit_reports_an_os_write_failure_rather_than_a_silent_success() {- use std::os::unix::fs::PermissionsExt;-- // SAFETY: `geteuid` takes no arguments, mutates no process state, and is- // documented as always succeeding.- let euid = unsafe { libc::geteuid() };- if euid == 0 {- // A mode-bit write denial is a DAC check; root carries- // CAP_DAC_OVERRIDE and bypasses it, so the write below would- // succeed and this test would assert nothing. Skip loudly rather- // than pass on a precondition that never held.- eprintln!(- "edit_reports_an_os_write_failure_rather_than_a_silent_success: \- skipped — running as root, which bypasses file-mode write checks"- );- return;- }-let dir = std::env::temp_dir().join("openhuman_test_edit_os_write_fail");let _ = tokio::fs::remove_dir_all(&dir).await;tokio::fs::create_dir_all(&dir).await.unwrap();let file = dir.join("f.txt");tokio::fs::write(&file, "abc").await.unwrap();- // SecurityPolicy is `Supervised` (can_act), so the tool's own gate lets- // this through; the failure comes from the OS `write` call itself.- tokio::fs::set_permissions(&file, std::fs::Permissions::from_mode(0o444))- .await- .unwrap();- let tool = EditFileTool::new(test_security(dir.clone()));+ let tool = EditFileTool::new(test_security(dir.clone())).with_sink(Arc::new(+ super::super::write_sink::RefusingSink(std::io::ErrorKind::PermissionDenied),+ ));let result = tool.execute(json!({"path": "f.txt", "old_string": "abc", "new_string": "xyz"})).await.unwrap();- tokio::fs::set_permissions(&file, std::fs::Permissions::from_mode(0o644))- .await- .unwrap();assert!(result.is_error,- "an OS-level write failure must surface as an error, not a fabricated success"+ "a refused write must surface as an error, not a fabricated success");assert!(result.output().contains("Failed to write file"));assert_eq!(tokio::fs::read_to_string(&file).await.unwrap(),"abc",- "the file must be left untouched when the write itself failed"+ "the file must be left as it was when the write did not happen");let _ = tokio::fs::remove_dir_all(&dir).await;