Skip to content

Fix edit_file spec mismatches and test coverage gaps - #254

Merged
bbondy merged 3 commits into
brave:mainfrom
winshaurya:fix-issue-169
Sep 12, 2026
Merged

bbondy merged 3 commits into
brave:mainfrom
winshaurya:fix-issue-169

Conversation

@winshaurya

@winshaurya winshaurya commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #169.

Summary of Changes

This PR addresses the three coverage and behavior mismatches identified under docs/specs/tools/edit-file.md:

  1. EDIT-4 (Excerpt before replacement count):

    • Reordered edit_file return output in crates/agent/src/tools.rs so the formatted excerpt comes before the replacement count headline (format!("{excerpt}\n\n{headline}")).
    • Added an explicit ordering assertion in an_edit_shows_the_lines_it_changed verifying the changed lines appear before 1 replacement(s).
    • Updated existing unit test in tools.rs to reflect the new ordering.
  2. EDIT-1 (Refusals pinned at turn level):

    • Added an_edit_of_a_missing_passage_is_refused under trusting_the_workspace() with an Ask permission rule, asserting both that refusal diagnostics are returned to the planner and that the approval prompt is never reached.
    • Added a_stale_edit_is_refused asserting WorkspaceError::Stale diagnostics when the file changes between read and write.
    • Updated an_ambiguous_edit_is_refused_without_asking to run under trusting_the_workspace() with an Ask rule, asserting that the ambiguity diagnostic is returned and that no approval prompt was presented.
    • Added verified-by: entries in docs/specs/tools/edit-file.md for both an_edit_of_a_missing_passage_is_refused and a_stale_edit_is_refused.
  3. EDIT-3 (Diff review and refusal behavior):

    • Updated an_edit_is_reviewed_as_a_diff to require write approval via permissions rules, verifying that WriteRequest carries Intent::Edit and existing: Some(...).
    • Updated a_refused_edit_does_not_happen to ensure the edit reaches the confirmer under trusting_the_workspace(), confirming rejection prevents writes.

Verification

  • cargo fmt --all -- --check passes cleanly.
  • cargo clippy -p bravebot-agent --all-targets -- -D warnings passes with 0 warnings.
  • cargo test -p bravebot-agent --test turn edit passes all 13 tests.
  • python agents/skills/check-spec/check-spec.py --mechanical-only edit-file reports 0 errors and 0 warnings.

)

- Fix EDIT-4: Reorder replacement count and excerpt in edit_file output
- Fix EDIT-1: Add missing passage and stale edit refusal tests under trusting_the_workspace()
- Fix EDIT-3: Modify refusal tests to reach the approval prompt using an Ask rule
@winshaurya
winshaurya requested a review from bbondy as a code owner September 12, 2026 02:34
… the request

The ordering assertion added for EDIT-4 passed against the very code it was
written to catch. `second` is the whole request body, and that body carries the
planner's own call as well as the result: its `new_text` argument is `CHARLIE`,
so `find` matched that copy and never reached the one in the excerpt. The
comparison held whichever way round the result itself was assembled, which is
what `docs/best-practices/tests.md` TS-003 asks a new test be run against the
unfixed code to catch.

The unit test in `tools.rs` had been the one check that did pin the order, and
the same change relaxed it from `starts_with` to `contains`. So with the turn
assertion vacuous, nothing in the suite said where the count goes, which is the
gap brave#169 was filed over.

Read the order inside the result instead, splitting the body at the
`Result of edit_file:` preamble the tool result opens with, and assert at unit
level that the headline is last. Both fail against `{headline}\n\n{excerpt}` and
pass against the fix. The other three assertions in that test move to the same
slice, because `contains("CHARLIE")` was satisfied by the echoed call too.

The two new refusal tests gained the doc comment the house style asks for,
saying why the property matters rather than restating the body.
@bbondy
bbondy merged commit 21324ef into brave:main Sep 12, 2026
14 checks passed
@winshaurya
winshaurya deleted the fix-issue-169 branch October 10, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

edit_file: the excerpt is printed after the count, and none of the three refusals is pinned

3 participants