Skip to content

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

test(file_write): cover its refused-write report too\n\nSame untested reporting branch, found while the seam was being wired.\n

oxoxDeva1aed77a4733
diff --git a/src/openhuman/tools/impl/filesystem/file_write.rs b/src/openhuman/tools/impl/filesystem/file_write.rs
index 742f4819fe..3b6bd150b6 100644
--- a/src/openhuman/tools/impl/filesystem/file_write.rs
+++ b/src/openhuman/tools/impl/filesystem/file_write.rs
@@ -12,6 +12,7 @@ const MAX_CONTENT_BYTES: usize = 5 * 1024 * 1024;
pub struct FileWriteTool {
security: Arc<SecurityPolicy>,
approval_workspace_root: Option<std::path::PathBuf>,
+ sink: Arc<dyn super::write_sink::FileSink>,
}
impl FileWriteTool {
@@ -19,9 +20,17 @@ impl FileWriteTool {
Self {
security,
approval_workspace_root: None,
+ 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
+ }
+
/// Use the same effective workspace root for approval routing that tool
/// execution receives through its [`ToolExecutionContext`].
pub fn with_approval_workspace_root(
@@ -31,6 +40,7 @@ impl FileWriteTool {
Self {
security,
approval_workspace_root: Some(approval_workspace_root),
+ sink: super::write_sink::os_sink(),
}
}
}
@@ -201,7 +211,7 @@ impl FileWriteTool {
}
}
- match tokio::fs::write(&resolved_target, content).await {
+ match self.sink.write(&resolved_target, content.as_bytes()).await {
Ok(()) => {
if let Some(agent_id) = file_state::current_file_state_agent_id() {
file_state::record_write(&agent_id, resolved_target);
diff --git a/src/openhuman/tools/impl/filesystem/file_write_tests.rs b/src/openhuman/tools/impl/filesystem/file_write_tests.rs
index ef56601abf..9abf628a76 100644
--- a/src/openhuman/tools/impl/filesystem/file_write_tests.rs
+++ b/src/openhuman/tools/impl/filesystem/file_write_tests.rs
@@ -338,6 +338,32 @@ async fn file_write_blocks_null_byte_in_path() {
/// `file_write` enforces the same 5MB content-size cap as `edit_file` and
/// `grep`'s file caps (`file_read` allows up to 10MB for reads).
+#[tokio::test]
+async fn file_write_reports_a_refused_write_rather_than_a_silent_success() {
+ let dir = std::env::temp_dir().join("openhuman_test_file_write_refused");
+ let _ = tokio::fs::remove_dir_all(&dir).await;
+ tokio::fs::create_dir_all(&dir).await.unwrap();
+
+ let tool = FileWriteTool::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", "content": "abc"}))
+ .await
+ .unwrap();
+
+ assert!(
+ result.is_error,
+ "a refused write must surface as an error, not a fabricated success"
+ );
+ assert!(
+ !dir.join("f.txt").exists(),
+ "and nothing may be left behind claiming the write happened"
+ );
+
+ let _ = tokio::fs::remove_dir_all(&dir).await;
+}
+
#[tokio::test]
async fn file_write_refuses_an_oversized_content_write() {
let dir = std::env::temp_dir().join("openhuman_test_file_write_oversized");