Bug
script_apply_edits introduces whitespace corruption when replacing a method signature line: the method declaration loses its leading indentation (flushed to column 0) and an extra blank line is inserted before it. The tool returns success: true despite the file having broken formatting.
This was observed on two separate files in the same session, with identical corruption patterns, suggesting a systematic issue in how the tool handles line replacement near method declarations.
Reproduction
Context: Two PlayMode test files needed method signature renames and assertion text changes.
File 1: ThemeBootstrapAcceptanceTests.cs
File before edit (exact region, lines 85-89):
}
[UnityTest]
public IEnumerator Start_WithNoPersistedTheme_AppliesDefaultDarkTheme()
{
Edit intent: Rename method from AppliesDefaultDarkTheme to AppliesDefaultOutrunTheme, update assertion text from "theme-dark" to "theme-outrun".
File after script_apply_edits (lines 85-91):
}
[UnityTest]
public IEnumerator Start_WithNoPersistedTheme_AppliesDefaultOutrunTheme()
{
Two issues:
- Extra blank line inserted before
[UnityTest] (line 87 is now empty)
- Method declaration lost indentation --
public IEnumerator is at column 0 instead of column 8 (8 spaces), and a blank line was inserted between [UnityTest] and the method declaration
File 2: RiftTokenGateTests.cs
File before edit (exact region, lines 98-103):
}
[UnityTest]
public IEnumerator Gate_TryGetValue_ReadsInheritedVarValues()
{
// Arrange
File after script_apply_edits (lines 98-105):
}
[UnityTest]
public IEnumerator Gate_TryGetValue_ReadsInheritedVarValues()
{
// Arrange
Identical corruption pattern: extra blank line before attribute, method declaration flushed to column 0 with blank line between attribute and method.
Expected Behavior
The replacement should preserve the indentation of the original line. If the original method signature was at 8 spaces of indentation, the replacement should also be at 8 spaces. No extra blank lines should be inserted around the edit region.
Impact
- Code compiles and runs correctly (C# ignores leading whitespace), so
validate does not catch it
- However, the formatting corruption is visible in diffs and requires manual cleanup
- Since it silently corrupts formatting on
success: true, users may not notice until code review
Workaround
- Read the file after any
script_apply_edits call and fix whitespace with an external editor tool
- Use
apply_text_edits with explicit old/new text matching instead (preserves formatting more reliably)
Environment
- MCP For Unity v9.5.3-beta.1
- Unity 6000.3.9f1
- Transport: SSE
- Client: Claude Code (claude-opus-4-6)
Bug
script_apply_editsintroduces whitespace corruption when replacing a method signature line: the method declaration loses its leading indentation (flushed to column 0) and an extra blank line is inserted before it. The tool returnssuccess: truedespite the file having broken formatting.This was observed on two separate files in the same session, with identical corruption patterns, suggesting a systematic issue in how the tool handles line replacement near method declarations.
Reproduction
Context: Two PlayMode test files needed method signature renames and assertion text changes.
File 1: ThemeBootstrapAcceptanceTests.cs
File before edit (exact region, lines 85-89):
Edit intent: Rename method from
AppliesDefaultDarkThemetoAppliesDefaultOutrunTheme, update assertion text from"theme-dark"to"theme-outrun".File after
script_apply_edits(lines 85-91):Two issues:
[UnityTest](line 87 is now empty)public IEnumeratoris at column 0 instead of column 8 (8 spaces), and a blank line was inserted between[UnityTest]and the method declarationFile 2: RiftTokenGateTests.cs
File before edit (exact region, lines 98-103):
File after
script_apply_edits(lines 98-105):Identical corruption pattern: extra blank line before attribute, method declaration flushed to column 0 with blank line between attribute and method.
Expected Behavior
The replacement should preserve the indentation of the original line. If the original method signature was at 8 spaces of indentation, the replacement should also be at 8 spaces. No extra blank lines should be inserted around the edit region.
Impact
validatedoes not catch itsuccess: true, users may not notice until code reviewWorkaround
script_apply_editscall and fix whitespace with an external editor toolapply_text_editswith explicit old/new text matching instead (preserves formatting more reliably)Environment