trusty_code/tools/fs/edit.rs
1//! `edit` tool — per-model edit-format selection (#2068).
2//!
3//! Why: Agents that iteratively refine code need a surgical replace-in-place
4//! primitive that is safer than re-writing the whole file from memory. Before
5//! #2068 the only supported wire format was exact-unique SEARCH/REPLACE,
6//! mirroring the Claude Code `Edit` tool contract. Aider's A/B data shows edit
7//! success rate varies by model family and format (see
8//! `tools::fs::edit_format`'s module docs for the matrix): some models
9//! reliably reproduce an exact substring, others do much better with a
10//! unified diff or a full-file rewrite. `EditTool` now accepts any of the
11//! three formats in one call and applies them in the calling model's
12//! preferred order via `edit_format::select_and_apply`.
13//! What: `EditTool` reads the file, builds an `EditPayload` for each format
14//! present in the tool-call arguments (`old_string`+`new_string`, `diff`, or
15//! `content`), and delegates to `edit_format::select_and_apply` to pick and
16//! apply the best-fit format, then writes the result back. All paths are
17//! scoped to the working directory.
18//! Test: See `#[cfg(test)]` below — covers each format, zero/ambiguous
19//! SEARCH/REPLACE errors, malformed-diff errors, and path traversal.
20
21use std::path::PathBuf;
22
23use async_trait::async_trait;
24use serde_json::{Value, json};
25
26use crate::mode::HarnessMode;
27use crate::tools::fs::edit_format::{
28 EditFormat, EditPayload, select_and_apply, select_and_apply_for_mode,
29};
30use crate::tools::fs::{FsError, scoped_path};
31use crate::tools::traits::{ToolExecutor, ToolResult};
32
33/// `ToolExecutor` that applies an edit using whichever wire format(s) the
34/// caller supplied, in the calling model's preferred order.
35///
36/// Why: Surgical in-place edits are the primary mutation primitive for coding
37/// agents. Supporting all three #2068 formats behind one tool keeps the
38/// registry/schema surface simple while letting the caller (or a future
39/// repair loop) hand the model whichever format it is more likely to succeed
40/// with.
41/// What: Implements `ToolExecutor` with `name = "edit"`. Reads the file,
42/// builds the present `EditPayload`s, calls `edit_format::select_and_apply`
43/// with `self.model_slug`, and writes the result back.
44/// Test: `cargo test -p trusty-code -- tools::fs::edit`.
45pub struct EditTool {
46 working_dir: PathBuf,
47 model_slug: Option<String>,
48 /// The resolved `HarnessMode` for this tool's owning run (#2073). `None`
49 /// (the default, and every pre-#2073 call site) preserves the exact
50 /// pre-#2073 behaviour: always the plain per-model order via
51 /// `edit_format::select_and_apply`. `Some(mode)` routes through
52 /// `edit_format::select_and_apply_for_mode`, whose `HarnessMode::Parity`
53 /// arm requires a `diff` payload and does NOT fall back to SEARCH/REPLACE
54 /// or whole-file (owner-tightened 2026-07-07, §5.9's edit-format
55 /// reconciliation read literally for benchmark fairness).
56 mode: Option<HarnessMode>,
57}
58
59impl EditTool {
60 /// Construct a new `EditTool` scoped to `working_dir`.
61 ///
62 /// Why: The working directory is the security boundary set at construction.
63 /// What: Stores `working_dir`. `model_slug` defaults to `None`, which
64 /// selects the catch-all format order (see `edit_format::format_order_for`);
65 /// this has no effect on a call that supplies only one format.
66 /// Test: `edit_replaces_unique_match`, et al.
67 pub fn new(working_dir: impl Into<PathBuf>) -> Self {
68 Self {
69 working_dir: working_dir.into(),
70 model_slug: None,
71 mode: None,
72 }
73 }
74
75 /// Set the model slug used to look up the per-model format fallback order.
76 ///
77 /// Why: The registry factory resolves the calling agent's model slug
78 /// (`provider::resolve_model`) once per delegation; threading it through
79 /// here lets `edit_format::select_and_apply` pick the best-fit format when
80 /// a tool call supplies more than one representation of the same edit.
81 /// What: Stores `slug` for use in `execute`.
82 /// Test: `edit_falls_back_to_whole_file_when_search_replace_fails`.
83 pub fn with_model_slug(mut self, slug: impl Into<String>) -> Self {
84 self.model_slug = Some(slug.into());
85 self
86 }
87
88 /// Set the resolved `HarnessMode` this tool's owning run uses (#2073).
89 ///
90 /// Why: `HarnessMode::Parity` must score a model's raw diff-editing
91 /// ability, unforgivingly — without this the tool always used the
92 /// per-model fallback matrix even in Parity, letting a model "pass" an
93 /// edit via SEARCH/REPLACE or whole-file without ever demonstrating a
94 /// valid diff (owner decision, 2026-07-07: this would defeat M3's model
95 /// bake-off). Every call site that does not opt in (`mode` stays `None`)
96 /// keeps the exact pre-#2073 behaviour.
97 /// What: Stores `mode` for use in `execute`/`edit_inner`.
98 /// Test: `edit_under_parity_mode_applies_a_valid_diff`,
99 /// `edit_under_parity_mode_errors_without_a_diff_payload`,
100 /// `edit_under_daily_driver_mode_matches_legacy_model_based_order`.
101 pub fn with_mode(mut self, mode: HarnessMode) -> Self {
102 self.mode = Some(mode);
103 self
104 }
105
106 /// Perform the edit: read the file, apply the best-fit payload, write back.
107 ///
108 /// Why: Centralises the IO so `execute` stays focused on argument parsing.
109 /// What: Returns the `EditFormat` that was actually applied. Errors
110 /// propagate from `scoped_path`, file IO, or the underlying
111 /// `edit_format::select_and_apply`/`select_and_apply_for_mode` call.
112 /// `self.mode` (#2073) picks which of the two: `None` (unset) preserves
113 /// the exact pre-#2073 plain per-model selection; `Some(mode)` routes
114 /// through the mode-aware variant, whose `Parity` arm accepts ONLY a
115 /// `diff` payload and returns a recoverable
116 /// `FsError::ParityDiffRequired` (never a panic) when none was supplied
117 /// or the diff fails to apply — no fallback to SEARCH/REPLACE or
118 /// whole-file, even then.
119 /// Test: All `EditTool` unit tests exercise this path.
120 fn edit_inner(
121 &self,
122 path: &std::path::Path,
123 payloads: &[EditPayload],
124 ) -> Result<EditFormat, FsError> {
125 let scoped = scoped_path(&self.working_dir, path)?;
126
127 let content = std::fs::read_to_string(&scoped).map_err(|e| {
128 if e.kind() == std::io::ErrorKind::NotFound {
129 FsError::NotFound(scoped.clone())
130 } else {
131 FsError::io(&scoped, e)
132 }
133 })?;
134
135 let model_slug = self.model_slug.as_deref().unwrap_or("");
136 let (updated, format) = match self.mode {
137 Some(mode) => select_and_apply_for_mode(mode, model_slug, &content, &scoped, payloads)?,
138 None => select_and_apply(model_slug, &content, &scoped, payloads)?,
139 };
140 std::fs::write(&scoped, updated).map_err(|e| FsError::io(&scoped, e))?;
141 Ok(format)
142 }
143}
144
145#[async_trait]
146impl ToolExecutor for EditTool {
147 fn name(&self) -> &str {
148 "edit"
149 }
150
151 /// OpenAI function-call schema for `edit`.
152 ///
153 /// Why: The LLM uses this schema to construct its tool call. `path` is the
154 /// only unconditionally required field (#2068); exactly one edit format's
155 /// fields must also be present, validated at execution time since JSON
156 /// Schema cannot express "one of these three field groups" cleanly here.
157 /// What: JSON object with `path` plus the three optional per-format field
158 /// groups: `old_string`+`new_string` (SEARCH/REPLACE), `diff`
159 /// (unified-diff), `content` (whole-file).
160 /// Test: `schema_requires_only_path`.
161 fn schema(&self) -> Value {
162 json!({
163 "type": "function",
164 "function": {
165 "name": "edit",
166 "description": "Edit a file using one of three formats: (1) SEARCH/REPLACE — provide old_string+new_string; old_string must appear exactly once in the file (cheapest, preferred when you can reproduce it exactly); (2) unified-diff — provide diff as one or more '@@ -l,s +l,s @@' hunks (use when context is easier to express as a diff than an exact substring); (3) whole-file — provide content as the file's complete new contents (most robust, most expensive; use as a last resort). Provide exactly one format's fields. The path must be inside the working directory.",
167 "parameters": {
168 "type": "object",
169 "properties": {
170 "path": {
171 "type": "string",
172 "description": "Relative or absolute path to the file (must be inside the working directory)."
173 },
174 "old_string": {
175 "type": "string",
176 "description": "SEARCH/REPLACE format: the exact string to replace. Must appear exactly once in the file. Requires new_string."
177 },
178 "new_string": {
179 "type": "string",
180 "description": "SEARCH/REPLACE format: the replacement string. Requires old_string."
181 },
182 "diff": {
183 "type": "string",
184 "description": "Unified-diff format: one or more '@@ -l,s +l,s @@' hunks to apply against the file's current content."
185 },
186 "content": {
187 "type": "string",
188 "description": "Whole-file format: the complete new content of the file."
189 }
190 },
191 "required": ["path"],
192 "additionalProperties": false
193 }
194 }
195 })
196 }
197
198 /// Execute an `edit` tool call.
199 ///
200 /// Why: Applies whichever edit format(s) the caller supplied, in the
201 /// model's preferred order.
202 /// What: Builds an `EditPayload` for each format present in `args`
203 /// (`old_string`+`new_string`, `diff`, `content`), errors if none are
204 /// present or `old_string`/`new_string` are only partially supplied, then
205 /// calls `edit_inner` and converts the result into a `ToolResult`.
206 /// Test: `edit_replaces_unique_match`, `edit_errors_on_zero_matches`,
207 /// `edit_applies_unified_diff`, `edit_applies_whole_file`, etc.
208 async fn execute(&self, args: Value) -> ToolResult {
209 let Some(path_str) = args.get("path").and_then(Value::as_str) else {
210 return ToolResult::err("edit: missing required argument 'path'");
211 };
212
213 let mut payloads = Vec::new();
214 match (
215 args.get("old_string").and_then(Value::as_str),
216 args.get("new_string").and_then(Value::as_str),
217 ) {
218 (Some(old_string), Some(new_string)) => payloads.push(EditPayload::SearchReplace {
219 old_string: old_string.to_string(),
220 new_string: new_string.to_string(),
221 }),
222 (None, None) => {}
223 _ => {
224 return ToolResult::err(
225 "edit: 'old_string' and 'new_string' must be provided together",
226 );
227 }
228 }
229 if let Some(diff) = args.get("diff").and_then(Value::as_str) {
230 payloads.push(EditPayload::UnifiedDiff {
231 diff: diff.to_string(),
232 });
233 }
234 if let Some(content) = args.get("content").and_then(Value::as_str) {
235 payloads.push(EditPayload::WholeFile {
236 content: content.to_string(),
237 });
238 }
239 if payloads.is_empty() {
240 return ToolResult::err(
241 "edit: must provide either 'old_string'+'new_string', 'diff', or 'content'",
242 );
243 }
244
245 match self.edit_inner(std::path::Path::new(path_str), &payloads) {
246 Ok(format) => ToolResult::ok(format!("edited {path_str} ({format})")),
247 Err(e) => ToolResult::err(e.to_string()),
248 }
249 }
250}
251
252// ── Tests ─────────────────────────────────────────────────────────────────────
253
254#[cfg(test)]
255mod tests {
256 use std::fs;
257
258 use serde_json::json;
259
260 use super::*;
261 use crate::tools::traits::ToolExecutor;
262
263 fn make_tool(tmp: &tempfile::TempDir) -> EditTool {
264 EditTool::new(tmp.path())
265 }
266
267 /// `edit` replaces a unique match and the file is updated on disk.
268 ///
269 /// Why: Basic contract — edit a file, re-read it, assert the replacement.
270 /// What: Write `old`, execute `edit(old → new)`, read back and assert `new`.
271 /// Test: This test.
272 #[tokio::test]
273 async fn edit_replaces_unique_match() {
274 let tmp = tempfile::tempdir().expect("tempdir");
275 fs::write(tmp.path().join("code.py"), "def foo():\n pass\n").expect("write");
276 let tool = make_tool(&tmp);
277 let result = tool
278 .execute(json!({
279 "path": "code.py",
280 "old_string": " pass",
281 "new_string": " return 42"
282 }))
283 .await;
284 assert!(!result.is_error(), "unexpected error: {}", result.content());
285 let updated = fs::read_to_string(tmp.path().join("code.py")).expect("read");
286 assert!(updated.contains("return 42"), "replacement must be applied");
287 assert!(!updated.contains(" pass"), "old string must be gone");
288 }
289
290 /// `edit` errors when `old_string` is not found in the file.
291 ///
292 /// Why: A zero-match edit would be a silent no-op; the agent must provide
293 /// a valid substring to avoid confusion about whether the edit succeeded.
294 /// What: `execute` with a non-existent `old_string` must return an error.
295 /// Test: This test.
296 #[tokio::test]
297 async fn edit_errors_on_zero_matches() {
298 let tmp = tempfile::tempdir().expect("tempdir");
299 fs::write(tmp.path().join("f.py"), "x = 1\n").expect("write");
300 let tool = make_tool(&tmp);
301 let result = tool
302 .execute(json!({
303 "path": "f.py",
304 "old_string": "not_in_file",
305 "new_string": "replacement"
306 }))
307 .await;
308 assert!(result.is_error());
309 assert!(
310 result.content().contains("not found"),
311 "unexpected message: {}",
312 result.content()
313 );
314 }
315
316 /// `edit` errors when `old_string` appears more than once.
317 ///
318 /// Why: An ambiguous replacement would modify the wrong occurrence; the
319 /// agent must provide more context.
320 /// What: Write a file with two identical lines, attempt `edit`; expect error.
321 /// Test: This test.
322 #[tokio::test]
323 async fn edit_errors_on_multiple_matches() {
324 let tmp = tempfile::tempdir().expect("tempdir");
325 fs::write(tmp.path().join("dup.py"), "x = 1\nx = 1\n").expect("write");
326 let tool = make_tool(&tmp);
327 let result = tool
328 .execute(json!({
329 "path": "dup.py",
330 "old_string": "x = 1",
331 "new_string": "x = 2"
332 }))
333 .await;
334 assert!(result.is_error());
335 assert!(
336 result.content().contains("ambiguous"),
337 "unexpected message: {}",
338 result.content()
339 );
340 }
341
342 /// `edit` rejects a path that escapes the working directory.
343 ///
344 /// Why: Path traversal must be blocked at the tool boundary.
345 /// What: `execute` with `path = "../../etc/passwd"` must return error.
346 /// Test: This test.
347 #[tokio::test]
348 async fn path_traversal_is_rejected() {
349 let tmp = tempfile::tempdir().expect("tempdir");
350 let tool = make_tool(&tmp);
351 let result = tool
352 .execute(json!({
353 "path": "../../etc/passwd",
354 "old_string": "root",
355 "new_string": "evil"
356 }))
357 .await;
358 assert!(result.is_error());
359 assert!(
360 result.content().contains("escapes"),
361 "unexpected message: {}",
362 result.content()
363 );
364 }
365
366 /// The schema requires only `path`; all three edit-format field groups are
367 /// optional at the schema level (validated at execution time instead).
368 ///
369 /// Why: #2068 lets a call supply SEARCH/REPLACE, unified-diff, or
370 /// whole-file fields — JSON Schema cannot cleanly express "exactly one of
371 /// these three field groups", so only the universally-required `path` is
372 /// listed, and every format's properties are documented but optional.
373 /// What: Parses `schema()` and checks `required == ["path"]`, and that all
374 /// five properties (`path`, `old_string`, `new_string`, `diff`, `content`)
375 /// are present.
376 /// Test: This test.
377 #[test]
378 fn schema_requires_only_path() {
379 let tmp = tempfile::tempdir().expect("tempdir");
380 let tool = make_tool(&tmp);
381 let schema = tool.schema();
382 let required = schema["function"]["parameters"]["required"]
383 .as_array()
384 .expect("required array");
385 let names: Vec<&str> = required.iter().filter_map(Value::as_str).collect();
386 assert_eq!(names, vec!["path"], "only 'path' must be required");
387
388 let properties = schema["function"]["parameters"]["properties"]
389 .as_object()
390 .expect("properties object");
391 for key in ["path", "old_string", "new_string", "diff", "content"] {
392 assert!(properties.contains_key(key), "missing property '{key}'");
393 }
394 }
395
396 /// `edit` applies a unified-diff payload when `diff` is supplied.
397 ///
398 /// Why: Guard the second #2068 format end-to-end through `execute`.
399 /// What: Write a two-line file, execute `edit` with a `diff` argument
400 /// replacing one line, and assert the file was patched.
401 /// Test: This test.
402 #[tokio::test]
403 async fn edit_applies_unified_diff() {
404 let tmp = tempfile::tempdir().expect("tempdir");
405 fs::write(tmp.path().join("f.py"), "line1\nline2\n").expect("write");
406 let tool = make_tool(&tmp);
407 let result = tool
408 .execute(json!({
409 "path": "f.py",
410 "diff": "@@ -2,1 +2,1 @@\n-line2\n+line2-changed\n"
411 }))
412 .await;
413 assert!(!result.is_error(), "unexpected error: {}", result.content());
414 assert!(result.content().contains("unified_diff"));
415 let updated = fs::read_to_string(tmp.path().join("f.py")).expect("read");
416 assert_eq!(updated, "line1\nline2-changed\n");
417 }
418
419 /// `edit` applies a whole-file payload when `content` is supplied.
420 ///
421 /// Why: Guard the third #2068 format (last-resort, most-robust) end-to-end.
422 /// What: Write a file, execute `edit` with a `content` argument, and
423 /// assert the file's entire content was replaced.
424 /// Test: This test.
425 #[tokio::test]
426 async fn edit_applies_whole_file() {
427 let tmp = tempfile::tempdir().expect("tempdir");
428 fs::write(tmp.path().join("f.py"), "old content\n").expect("write");
429 let tool = make_tool(&tmp);
430 let result = tool
431 .execute(json!({
432 "path": "f.py",
433 "content": "brand new file\n"
434 }))
435 .await;
436 assert!(!result.is_error(), "unexpected error: {}", result.content());
437 assert!(result.content().contains("whole_file"));
438 let updated = fs::read_to_string(tmp.path().join("f.py")).expect("read");
439 assert_eq!(updated, "brand new file\n");
440 }
441
442 /// `edit` errors when `old_string` is supplied without `new_string`.
443 ///
444 /// Why: A half-supplied SEARCH/REPLACE pair is an unambiguous caller
445 /// mistake and must be rejected before touching the filesystem.
446 /// What: `execute` with only `old_string` set must return a recoverable error.
447 /// Test: This test.
448 #[tokio::test]
449 async fn edit_errors_on_partial_search_replace_pair() {
450 let tmp = tempfile::tempdir().expect("tempdir");
451 fs::write(tmp.path().join("f.py"), "x = 1\n").expect("write");
452 let tool = make_tool(&tmp);
453 let result = tool
454 .execute(json!({"path": "f.py", "old_string": "x = 1"}))
455 .await;
456 assert!(result.is_error());
457 assert!(result.content().contains("together"));
458 }
459
460 /// `edit` errors when none of the three format field groups are supplied.
461 ///
462 /// Why: Nothing to apply is a caller mistake, not a silent no-op.
463 /// What: `execute` with only `path` must return a recoverable error.
464 /// Test: This test.
465 #[tokio::test]
466 async fn edit_errors_when_no_format_supplied() {
467 let tmp = tempfile::tempdir().expect("tempdir");
468 fs::write(tmp.path().join("f.py"), "x = 1\n").expect("write");
469 let tool = make_tool(&tmp);
470 let result = tool.execute(json!({"path": "f.py"})).await;
471 assert!(result.is_error());
472 assert!(result.content().contains("must provide"));
473 }
474
475 /// With a model slug set, a failing SEARCH/REPLACE payload falls back to a
476 /// concurrently-supplied whole-file payload within the same call.
477 ///
478 /// Why: This is the #2068 fallback-ordering acceptance criterion exercised
479 /// through the actual `ToolExecutor::execute` entry point, not just the
480 /// underlying `edit_format::select_and_apply` unit tests.
481 /// What: Give a flagship model slug (SEARCH/REPLACE-first order), a
482 /// non-matching `old_string`/`new_string` pair, and a `content` fallback;
483 /// assert the whole-file fallback was applied.
484 /// Test: This test.
485 #[tokio::test]
486 async fn edit_falls_back_to_whole_file_when_search_replace_fails() {
487 let tmp = tempfile::tempdir().expect("tempdir");
488 fs::write(tmp.path().join("f.py"), "original\n").expect("write");
489 let tool = EditTool::new(tmp.path()).with_model_slug("anthropic/claude-opus-4-5");
490 let result = tool
491 .execute(json!({
492 "path": "f.py",
493 "old_string": "not-present-in-file",
494 "new_string": "x",
495 "content": "fallback content\n"
496 }))
497 .await;
498 assert!(!result.is_error(), "unexpected error: {}", result.content());
499 assert!(result.content().contains("whole_file"));
500 let updated = fs::read_to_string(tmp.path().join("f.py")).expect("read");
501 assert_eq!(updated, "fallback content\n");
502 }
503
504 /// Under `HarnessMode::Parity`, a flagship model slug (which would prefer
505 /// SEARCH/REPLACE first under the plain per-model matrix) still applies
506 /// ONLY the unified-diff payload when both are supplied — the
507 /// SEARCH/REPLACE payload is never even attempted (#2073, tightened
508 /// 2026-07-07: Parity's edit-format is strict unified-diff only, not
509 /// merely model-independent).
510 #[tokio::test]
511 async fn edit_under_parity_mode_applies_a_valid_diff() {
512 let tmp = tempfile::tempdir().expect("tempdir");
513 fs::write(tmp.path().join("f.py"), "line1\nline2\n").expect("write");
514 let tool = EditTool::new(tmp.path())
515 .with_model_slug("anthropic/claude-opus-4-5")
516 .with_mode(crate::mode::HarnessMode::Parity);
517
518 let result = tool
519 .execute(json!({
520 "path": "f.py",
521 // Deliberately non-matching, so a SEARCH/REPLACE-first order
522 // would fail; only the diff below can actually apply. Under
523 // strict Parity this payload is never even attempted.
524 "old_string": "not-present",
525 "new_string": "x",
526 "diff": "@@ -2,1 +2,1 @@\n-line2\n+line2-diffed\n"
527 }))
528 .await;
529
530 assert!(!result.is_error(), "unexpected error: {}", result.content());
531 assert!(result.content().contains("unified_diff"));
532 let updated = fs::read_to_string(tmp.path().join("f.py")).expect("read");
533 assert_eq!(updated, "line1\nline2-diffed\n");
534 }
535
536 /// Under `HarnessMode::Parity`, an `edit` call that supplies only
537 /// SEARCH/REPLACE (no `diff`) must return a RECOVERABLE tool error — the
538 /// same `ToolResult::err` mechanism every other edit failure uses, never
539 /// a panic — whose message makes clear Parity requires a unified-diff
540 /// edit, and must NOT silently succeed via the fallback matrix (#2073,
541 /// tightened 2026-07-07: the model is scored as failing the edit, per
542 /// the owner's benchmark-fairness decision).
543 #[tokio::test]
544 async fn edit_under_parity_mode_errors_without_a_diff_payload() {
545 let tmp = tempfile::tempdir().expect("tempdir");
546 fs::write(tmp.path().join("f.py"), "line1\nline2\n").expect("write");
547 let tool = EditTool::new(tmp.path())
548 .with_model_slug("anthropic/claude-opus-4-5")
549 .with_mode(crate::mode::HarnessMode::Parity);
550
551 // A payload that WOULD succeed under DailyDriver's fallback matrix
552 // (unique old_string match) — under Parity it must never be tried.
553 let result = tool
554 .execute(json!({
555 "path": "f.py",
556 "old_string": "line2",
557 "new_string": "line2-replaced"
558 }))
559 .await;
560
561 assert!(
562 result.is_error(),
563 "Parity must reject an edit with no diff payload, got: {}",
564 result.content()
565 );
566 assert!(
567 result.content().contains("unified-diff"),
568 "error must make the Parity requirement clear: {}",
569 result.content()
570 );
571 let unchanged = fs::read_to_string(tmp.path().join("f.py")).expect("read");
572 assert_eq!(
573 unchanged, "line1\nline2\n",
574 "the file must be untouched when Parity rejects the edit"
575 );
576 }
577
578 /// Under `HarnessMode::DailyDriver`, `with_mode` must produce the exact
579 /// same outcome as the pre-#2073 default (no `with_mode` call at all) —
580 /// the mode-aware path is a no-op wrapper around the legacy per-model
581 /// matrix for this mode.
582 #[tokio::test]
583 async fn edit_under_daily_driver_mode_matches_legacy_model_based_order() {
584 let tmp = tempfile::tempdir().expect("tempdir");
585 fs::write(tmp.path().join("f.py"), "original\n").expect("write");
586 let tool = EditTool::new(tmp.path())
587 .with_model_slug("anthropic/claude-opus-4-5")
588 .with_mode(crate::mode::HarnessMode::DailyDriver);
589
590 let result = tool
591 .execute(json!({
592 "path": "f.py",
593 "old_string": "not-present-in-file",
594 "new_string": "x",
595 "content": "fallback content\n"
596 }))
597 .await;
598
599 assert!(!result.is_error(), "unexpected error: {}", result.content());
600 assert!(result.content().contains("whole_file"));
601 let updated = fs::read_to_string(tmp.path().join("f.py")).expect("read");
602 assert_eq!(updated, "fallback content\n");
603 }
604}