Add read_file_text to executor filesystem

This commit is contained in:
pakrym-oai
2026-04-07 11:04:03 -07:00
parent 658fc7761b
commit e56d29ed91
4 changed files with 14 additions and 22 deletions

View File

@@ -171,7 +171,7 @@ pub async fn maybe_parse_apply_patch_verified(
path.as_path(),
&effective_cwd,
);
let original_bytes = match fs.read_file(&path_abs).await {
let content = match fs.read_file_text(&path_abs).await {
Ok(content) => content,
Err(e) => {
return MaybeApplyPatchVerified::CorrectnessError(
@@ -182,20 +182,6 @@ pub async fn maybe_parse_apply_patch_verified(
);
}
};
let content = match String::from_utf8(original_bytes) {
Ok(content) => content,
Err(e) => {
return MaybeApplyPatchVerified::CorrectnessError(
ApplyPatchError::IoError(IoError {
context: format!("Failed to read {}", path.display()),
source: std::io::Error::new(
std::io::ErrorKind::InvalidData,
e,
),
}),
);
}
};
changes.insert(path, ApplyPatchFileChange::Delete { content });
}
Hunk::UpdateFile {

View File

@@ -391,18 +391,12 @@ async fn derive_new_contents_from_chunks(
fs: &dyn ExecutorFileSystem,
) -> std::result::Result<AppliedPatch, ApplyPatchError> {
let path_abs = AbsolutePathBuf::resolve_path_against_base(path, cwd);
let original_bytes = fs.read_file(&path_abs).await.map_err(|err| {
let original_contents = fs.read_file_text(&path_abs).await.map_err(|err| {
ApplyPatchError::IoError(IoError {
context: format!("Failed to read file to update {}", path.display()),
source: err,
})
})?;
let original_contents = String::from_utf8(original_bytes).map_err(|err| {
ApplyPatchError::IoError(IoError {
context: format!("Failed to read file to update {}", path.display()),
source: io::Error::new(io::ErrorKind::InvalidData, err),
})
})?;
let mut original_lines: Vec<String> = original_contents.split('\n').map(String::from).collect();

View File

@@ -39,6 +39,12 @@ pub type FileSystemResult<T> = io::Result<T>;
pub trait ExecutorFileSystem: Send + Sync {
async fn read_file(&self, path: &AbsolutePathBuf) -> FileSystemResult<Vec<u8>>;
/// Reads a file and decodes it as UTF-8 text.
async fn read_file_text(&self, path: &AbsolutePathBuf) -> FileSystemResult<String> {
let bytes = self.read_file(path).await?;
String::from_utf8(bytes).map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))
}
async fn write_file(&self, path: &AbsolutePathBuf, contents: Vec<u8>) -> FileSystemResult<()>;
async fn create_directory(

View File

@@ -122,6 +122,12 @@ async fn file_system_methods_cover_surface_area(use_remote: bool) -> Result<()>
.with_context(|| format!("mode={use_remote}"))?;
assert_eq!(nested_file_contents, b"hello from trait");
let nested_file_text = file_system
.read_file_text(&absolute_path(nested_file.clone()))
.await
.with_context(|| format!("mode={use_remote}"))?;
assert_eq!(nested_file_text, "hello from trait");
file_system
.copy(
&absolute_path(nested_file),