Skip to content

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

test(filesystem): cover FAIL-axis for file_read, edit_file and list_files

oxoxDeve25f22e87198
diff --git a/src/openhuman/tools/impl/filesystem/edit_file_tests.rs b/src/openhuman/tools/impl/filesystem/edit_file_tests.rs
index 298f7144b6..80b81d66f4 100644
--- a/src/openhuman/tools/impl/filesystem/edit_file_tests.rs
+++ b/src/openhuman/tools/impl/filesystem/edit_file_tests.rs
@@ -155,3 +155,42 @@ async fn edit_rejects_identical_strings() {
let _ = tokio::fs::remove_dir_all(&dir).await;
}
+
+#[tokio::test]
+#[cfg(unix)]
+async fn edit_reports_an_os_write_failure_rather_than_a_silent_success() {
+ use std::os::unix::fs::PermissionsExt;
+
+ 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 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"
+ );
+ 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"
+ );
+
+ let _ = tokio::fs::remove_dir_all(&dir).await;
+}
diff --git a/src/openhuman/tools/impl/filesystem/file_read_tests.rs b/src/openhuman/tools/impl/filesystem/file_read_tests.rs
index c67c4a33ed..e7d85c9208 100644
--- a/src/openhuman/tools/impl/filesystem/file_read_tests.rs
+++ b/src/openhuman/tools/impl/filesystem/file_read_tests.rs
@@ -271,3 +271,26 @@ async fn file_read_rejects_oversized_file() {
let _ = tokio::fs::remove_dir_all(&dir).await;
}
+
+#[tokio::test]
+async fn file_read_reports_invalid_utf8_as_an_error_not_a_panic() {
+ let dir = std::env::temp_dir().join("openhuman_test_file_read_non_utf8");
+ let _ = tokio::fs::remove_dir_all(&dir).await;
+ tokio::fs::create_dir_all(&dir).await.unwrap();
+
+ // Passes the size cap, fails `read_to_string`: 0x80 is a lone UTF-8
+ // continuation byte with no lead byte, invalid at any position.
+ tokio::fs::write(dir.join("binary.dat"), [0xFFu8, 0xFE, 0x00, 0x80])
+ .await
+ .unwrap();
+
+ let tool = FileReadTool::new(test_security(dir.clone()));
+ let result = tool.execute(json!({"path": "binary.dat"})).await.unwrap();
+ assert!(
+ result.is_error,
+ "invalid UTF-8 must surface as a tool error, not succeed with replaced/garbled text"
+ );
+ assert!(&result.output().contains("Failed to read file"));
+
+ let _ = tokio::fs::remove_dir_all(&dir).await;
+}
diff --git a/src/openhuman/tools/impl/filesystem/list_files_tests.rs b/src/openhuman/tools/impl/filesystem/list_files_tests.rs
index a585bd1c4b..67c10ee507 100644
--- a/src/openhuman/tools/impl/filesystem/list_files_tests.rs
+++ b/src/openhuman/tools/impl/filesystem/list_files_tests.rs
@@ -52,3 +52,26 @@ async fn list_missing_dir() {
assert!(result.output().contains("Failed to resolve"));
let _ = tokio::fs::remove_dir_all(&dir).await;
}
+
+#[tokio::test]
+async fn list_a_plain_file_reports_the_read_dir_failure() {
+ // Distinct from `list_missing_dir`: the path resolves (the file exists),
+ // so `validate_path` succeeds; the failure is `read_dir` itself refusing
+ // a non-directory (ENOTDIR), one step later in the same function.
+ let dir = std::env::temp_dir().join("openhuman_test_list_not_a_dir");
+ let _ = tokio::fs::remove_dir_all(&dir).await;
+ tokio::fs::create_dir_all(&dir).await.unwrap();
+ tokio::fs::write(dir.join("plain.txt"), "not a directory")
+ .await
+ .unwrap();
+
+ let tool = ListFilesTool::new(test_security(dir.clone()));
+ let result = tool.execute(json!({"path": "plain.txt"})).await.unwrap();
+ assert!(
+ result.is_error,
+ "listing a plain file must be a refusal, not an empty-looking success"
+ );
+ assert!(result.output().contains("Failed to read directory"));
+
+ let _ = tokio::fs::remove_dir_all(&dir).await;
+}