Files
hermes-agent/tests/tools/test_patch_unicode_replace_all.py
Rudy Celekli 13f25e5fd9 fix(tools): preserve each normalized replacement’s Unicode
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
(cherry picked from commit 8e18884e6b4638c8a91ba4fd678821e6812f6130)
2026-10-02 01:15:39 +05:30

30 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Replacing every normalized match preserves each region's untouched Unicode."""
import json
from tools import file_tools, terminal_tool
from tools.registry import registry
def test_replace_all_preserves_each_matches_unicode(tmp_path, monkeypatch):
home = tmp_path / "home"
home.mkdir()
monkeypatch.setenv("HERMES_HOME", str(home))
path = tmp_path / "notes.txt"
original = "Price ‘old’—ready\nPrice 'old'—ready\n"
path.write_text(original, encoding="utf-8")
task = "unicode-replace-all"
terminal_tool.register_task_env_overrides(task, {"env_type": "local", "cwd": str(tmp_path)})
try:
read = json.loads(registry.dispatch("read_file", {"path": str(path)}, task_id=task))
assert "error" not in read
result = json.loads(registry.dispatch("patch", {
"mode": "replace", "path": str(path), "old_string": "Price 'old'--ready",
"new_string": "Price 'new'--ready", "replace_all": True,
}, task_id=task))
assert "error" not in result, result
assert path.read_text(encoding="utf-8") == original.replace("old", "new")
finally:
file_tools.clear_file_ops_cache(task)
terminal_tool.clear_task_env_overrides(task)