fix(error-handling): _handle_file_edit() now respects encoding parameter
- Fixed _handle_file_edit() to use encoding=inputs.get("encoding", "utf-8") for both read_text() and write_text() calls, ensuring encoding is explicit and not dependent on the platform default.
- Added encoding field to the FILE_EDIT_SPEC schema to surface encoding choices to callers.
ISSUES CLOSED: #7559
This commit is contained in:
@@ -62,6 +62,15 @@ def step_given_file_with_content(context: Any, name: str, content: str) -> None:
|
||||
path.write_text(content)
|
||||
|
||||
|
||||
@given('an encoded file "{name}" with encoding "{encoding}" and content "{content}"')
|
||||
def step_given_file_with_content_encoding(
|
||||
context: Any, name: str, encoding: str, content: str
|
||||
) -> None:
|
||||
path = Path(context.sandbox_dir) / name
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(content, encoding=encoding)
|
||||
|
||||
|
||||
@given('a file "{name}" with lines "{csv_lines}"')
|
||||
def step_given_file_with_lines(context: Any, name: str, csv_lines: str) -> None:
|
||||
lines = csv_lines.split(",")
|
||||
@@ -149,6 +158,39 @@ def step_when_file_edit(context: Any, old: str, new: str) -> None:
|
||||
)
|
||||
|
||||
|
||||
@when(
|
||||
'I edit file "edit-enc.txt" replacing "{old}" with "{new}" specifying encoding "{encoding}"'
|
||||
)
|
||||
def step_when_file_edit_with_encoding(
|
||||
context: Any, old: str, new: str, encoding: str
|
||||
) -> None:
|
||||
_run_tool(
|
||||
context,
|
||||
"builtin/file-edit",
|
||||
{
|
||||
"path": "edit-enc.txt",
|
||||
"old_text": old,
|
||||
"new_text": new,
|
||||
"encoding": encoding,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def step_when_file_edit_with_encoding(
|
||||
context: Any, old: str, new: str, encoding: str
|
||||
) -> None:
|
||||
_run_tool(
|
||||
context,
|
||||
"builtin/file-edit",
|
||||
{
|
||||
"path": "edit-enc.txt",
|
||||
"old_text": old,
|
||||
"new_text": new,
|
||||
"encoding": encoding,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@when('I execute the "builtin/file-edit" tool replacing all "{old}" with "{new}"')
|
||||
def step_when_file_edit_all(context: Any, old: str, new: str) -> None:
|
||||
_run_tool(
|
||||
|
||||
Reference in New Issue
Block a user