Skip to content

Commit 52b2aa9

Browse files
Yogthosyogthos
authored andcommitted
Run cargo fmt
1 parent 1826095 commit 52b2aa9

1 file changed

Lines changed: 12 additions & 22 deletions

File tree

src/agent/tools/apply_patch.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ pub struct ApplyPatchTool {
3232

3333
impl ApplyPatchTool {
3434
pub fn new(permission: Option<PermCheck>, ask_tx: Option<AskSender>) -> Self {
35-
Self {
36-
permission,
37-
ask_tx,
38-
}
35+
Self { permission, ask_tx }
3936
}
4037
}
4138

@@ -58,14 +55,10 @@ fn apply_create(path: &str, content: &str) -> Result<String, String> {
5855
}
5956

6057
fn apply_update(path: &str, old_text: &str, new_text: &str) -> Result<String, String> {
61-
let original = std::fs::read_to_string(path)
62-
.map_err(|e| format!("read failed: {}", e))?;
58+
let original = std::fs::read_to_string(path).map_err(|e| format!("read failed: {}", e))?;
6359

6460
if !original.contains(old_text) {
65-
return Err(format!(
66-
"text not found in {}",
67-
path
68-
));
61+
return Err(format!("text not found in {}", path));
6962
}
7063

7164
let matches: Vec<_> = original.match_indices(old_text).collect();
@@ -88,8 +81,7 @@ fn apply_delete(path: &str) -> Result<String, String> {
8881
}
8982

9083
fn apply_rename(path: &str, new_path: &str) -> Result<String, String> {
91-
std::fs::rename(path, new_path)
92-
.map_err(|e| format!("rename failed: {}", e))?;
84+
std::fs::rename(path, new_path).map_err(|e| format!("rename failed: {}", e))?;
9385
Ok(format!("renamed {} -> {}", path, new_path))
9486
}
9587

@@ -163,19 +155,21 @@ impl Tool for ApplyPatchTool {
163155
| PatchOp::Update { path, .. }
164156
| PatchOp::Delete { path }
165157
| PatchOp::Rename { path, .. } => {
166-
check_perm_path(&self.permission, &self.ask_tx, "apply_patch", path)
167-
.await?;
158+
check_perm_path(&self.permission, &self.ask_tx, "apply_patch", path).await?;
168159
}
169160
}
170161
// Rename also requires permission on the new path
171162
if let PatchOp::Rename { new_path, .. } = op {
172-
check_perm_path(&self.permission, &self.ask_tx, "apply_patch", new_path)
173-
.await?;
163+
check_perm_path(&self.permission, &self.ask_tx, "apply_patch", new_path).await?;
174164
}
175165
// Validate create content size
176166
if let PatchOp::Create { content, .. } = op {
177167
if content.len() > MAX_CREATE_SIZE {
178-
results.push(format!("FAILED: create content exceeds {} bytes ({} bytes provided)", MAX_CREATE_SIZE, content.len()));
168+
results.push(format!(
169+
"FAILED: create content exceeds {} bytes ({} bytes provided)",
170+
MAX_CREATE_SIZE,
171+
content.len()
172+
));
179173
break;
180174
}
181175
}
@@ -289,11 +283,7 @@ mod tests {
289283
#[tokio::test]
290284
async fn test_rejects_empty_operations() {
291285
let tool = ApplyPatchTool::new(None, None);
292-
let result = tool
293-
.call(ApplyPatchArgs {
294-
operations: vec![],
295-
})
296-
.await;
286+
let result = tool.call(ApplyPatchArgs { operations: vec![] }).await;
297287
assert!(result.is_err());
298288
assert!(result.unwrap_err().to_string().contains("no operations"));
299289
}

0 commit comments

Comments
 (0)