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
feat(tools): route file writes through a sink the tools can swap\n\nEvery tool that reports a failed write has a branch that only runs when the\nfilesystem refuses, and that branch decides whether a failed edit is reported\nhonestly or fabricated as a success. It is worth asserting and was not\nassertable.\n\nA mode-bit denial is the obvious fixture and does not work: it is a\ndiscretionary check, and a root test runner writes straight through it. Under\nCI such a case either fails on a premise that never held or is skipped, and\nboth read as coverage.\n\nThe write is a seam instead. Production installs the OS; a test installs one\nthat refuses. new() keeps its signature, so a tool adopts this in three lines\nand no construction site elsewhere changes.\n
oxoxDevb2a6cb013ed6
diff --git a/src/openhuman/tools/impl/filesystem/mod.rs b/src/openhuman/tools/impl/filesystem/mod.rsindex 973c7831f9..5015d91960 100644--- a/src/openhuman/tools/impl/filesystem/mod.rs+++ b/src/openhuman/tools/impl/filesystem/mod.rs@@ -13,6 +13,7 @@ mod read_diff;mod run_linter;mod run_tests;mod update_memory_md;+mod write_sink;use crate::openhuman::security::policy::{TrustedAccess, TrustedRoot};use crate::openhuman::security::SecurityPolicy;diff --git a/src/openhuman/tools/impl/filesystem/write_sink.rs b/src/openhuman/tools/impl/filesystem/write_sink.rsnew file mode 100644index 0000000000..4d879605d2--- /dev/null+++ b/src/openhuman/tools/impl/filesystem/write_sink.rs@@ -0,0 +1,57 @@+//! The filesystem write the tools go through.+//!+//! Every tool that reports "the write failed" has a branch that only runs when+//! the OS refuses, and that branch is the one worth asserting: it decides+//! whether a failed edit is reported honestly or fabricated as a success.+//!+//! Provoking a real refusal from a test is where this gets awkward. A+//! mode-bit denial is a discretionary check, and a root test runner carries+//! `CAP_DAC_OVERRIDE` and writes through it — so a fixture built on+//! permissions succeeds under CI, and the case either fails on a premise that+//! never held or is skipped and asserts nothing at all. Both read as coverage.+//!+//! So the write is a seam instead. Production installs the OS; a test installs+//! one that refuses, and the reporting branch becomes ordinary to assert on+//! any platform and as any user.++use std::path::Path;+use std::sync::Arc;++use async_trait::async_trait;++/// Where a tool's file writes land.+#[async_trait]+pub trait FileSink: Send + Sync {+ async fn write(&self, path: &Path, contents: &[u8]) -> std::io::Result<()>;+}++/// The real filesystem.+pub struct OsFileSink;++#[async_trait]+impl FileSink for OsFileSink {+ async fn write(&self, path: &Path, contents: &[u8]) -> std::io::Result<()> {+ tokio::fs::write(path, contents).await+ }+}++/// The sink a tool uses unless a caller installs another one.+pub fn os_sink() -> Arc<dyn FileSink> {+ Arc::new(OsFileSink)+}++/// A sink that refuses every write with `kind`, for asserting the branch a+/// tool takes when the filesystem says no.+#[cfg(test)]+pub struct RefusingSink(pub std::io::ErrorKind);++#[cfg(test)]+#[async_trait]+impl FileSink for RefusingSink {+ async fn write(&self, path: &Path, _contents: &[u8]) -> std::io::Result<()> {+ Err(std::io::Error::new(+ self.0,+ format!("refused by the test sink: {}", path.display()),+ ))+ }+}