-
Notifications
You must be signed in to change notification settings - Fork 3
fix(edit): kill the auto-format edit-rejection round-trip #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
634498d
fix(edit): kill the auto-format edit-rejection round-trip
agjs 067859d
fix(edit): guard currentFileView against I/O errors (Gemini review)
agjs 6c9ab5e
test(e2e): edit anchor survives the real write-guard auto-format
agjs ec8e391
docs(edit): clarify currentFileView shape vs read (Copilot review)
agjs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { test, expect } from "bun:test"; | ||
| import { mkdtemp, rm } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { formatFile } from "../src/detect-gate"; | ||
| import { applyEdits } from "../src/files/edit"; | ||
|
|
||
| // e2e: the write-guard auto-formats a file (real eslint --fix + prettier) right | ||
| // after a write, so the model's next edit anchor no longer matches disk. This | ||
| // drives the REAL formatter (not a hand-built "formatted" string) and proves a | ||
| // pre-format anchor still lands via the widened fuzzy matcher — the local model's | ||
| // #1 reported friction. (A structural rewrite the fuzzy can't bridge falls back to | ||
| // the inlined-content rejection, covered in files-edit.test.ts.) | ||
| test("a pre-format edit anchor survives the real write-guard auto-format", async () => { | ||
| const dir = await mkdtemp(join(tmpdir(), "tsforge-fmt-e2e-")); | ||
| const file = "demo.ts"; | ||
| // No trailing comma, no semicolons — the formatter will add both. | ||
| const before = "const o = {\n a: 1,\n b: 2\n}\n"; | ||
|
|
||
| await Bun.write(join(dir, file), before); | ||
|
|
||
| try { | ||
| await formatFile(dir, file); | ||
| const after = await Bun.file(join(dir, file)).text(); | ||
|
|
||
| // Sanity: the formatter actually reformatted (else the test proves nothing). | ||
| expect(after).not.toBe(before); | ||
| expect(after).toContain("b: 2,"); // prettier added the trailing comma | ||
|
|
||
| // The model's pre-format anchor (`b: 2\n}`, no trailing comma) exact-misses the | ||
| // formatted file (`b: 2,\n};`) — it must still apply via the fuzzy fallback, | ||
| // NOT reject and force a re-read. | ||
| const r = await applyEdits(dir, file, [ | ||
| { oldString: " a: 1,\n b: 2\n}", newString: " a: 1,\n b: 999\n}" }, | ||
| ]); | ||
|
|
||
| expect(r.ok).toBe(true); | ||
| expect(await Bun.file(join(dir, file)).text()).toContain("b: 999"); | ||
| } finally { | ||
| await rm(dir, { recursive: true, force: true }); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.