Repository navigation
Conversation
There was a problem hiding this comment.
The fix looks correct to me. Two of your new tests (plus the updated read-count test) fail on the base branch and pass with this change: the Patch diff now shows the formatter's final output, and both Patch and Write keep the UTF-8 BOM when the formatter exits with an error after rewriting the file. The tool-patch, tool-write and tool-edit suites pass, and typecheck:tsc passes for packages/core. I couldn't confirm it end to end in the terminal app with the simulated model, so this rests on the tests.
Public API: unchanged. These are internal FileWrite/Patch internals only.
One small follow-up: FileWrite.commit now always sets formatted, so the result.formatted ?? readText(...) fallback in packages/core/src/tool/plugin/edit.ts can never run. You could make formatted required on Written and drop that fallback. It's optional, not a blocker.
There was a problem hiding this comment.
The earlier follow-up is done: Written.formatted is now required, and Edit uses it instead of re-reading the file. tool-patch, tool-write and tool-edit pass and typecheck:tsc passes. The Patch test from the issue's reproduction script fails on the base branch and passes with this change. Public API: unchanged (internal FileWrite/tool code only). No new concerns.
|
I reproduced the two formatter-partial-failure cases on 2.2.7-based native code: the write case lost its BOM, and the patch result reported the pre-formatter content. Both native tests passed after overlaying this PR's three production-file changes on my isolated 2.2.7 + #58324 source. This was source-level native tool integration testing, not a built-host test of the combined PRs. Separately, a successful external formatter emitting LF still leaves a previously CRLF file as LF (with BOM restored). I understand that is outside this PR's BOM/result-reporting scope; it is worth keeping separate from a general line-ending-preservation claim. |
Issue for this PR
Closes #61415
Type of change
What does this PR do?
A formatter can write corrections before exiting nonzero. Patch currently returns its pre-format diff in that case, and both Patch and FileWrite skip restoring the original BOM.
Always synchronize the BOM and read the final text after formatting. The final text is required on the internal write result, so Edit uses it directly. Formatter success reporting and formatter fallback behavior stay the same; this costs one final read even when no formatter succeeds.
How did you verify your code works?
typecheck:tscpasses again.typecheckandtypecheck:tsc, changed-file lint, and production Effect rules pass.bun run checkcompletes lint but cannot finish workspace typechecking with the filtered install: unrelated packages lack dependencies such asgray-matterand Cloudflare worker types.Visual
Checklist