Skip to content

The agent that grows with you

test(tools): cover UTF-8 BOM input in json_parse sandbox helper

nankingjing3fee5c291b55
diff --git a/tests/tools/test_code_execution.py b/tests/tools/test_code_execution.py
index 7ded9823a7e..e6369b80039 100644
--- a/tests/tools/test_code_execution.py
+++ b/tests/tools/test_code_execution.py
@@ -338,6 +338,21 @@ assert escaped.startswith("'")
self.assertEqual(result["status"], "success")
+ def test_json_parse_helper_bom(self):
+ """json_parse strips a leading UTF-8 BOM and tolerates control chars (#57870)."""
+ code = """
+from hermes_tools import json_parse
+# A leading UTF-8 BOM (e.g. from Windows CLI output) must also parse (#57870)
+bom_text = "\\ufeff" + '{"body": "bom-ok"}'
+bom_result = json_parse(bom_text)
+assert bom_result == {"body": "bom-ok"}, bom_result
+print("bom:" + bom_result["body"])
+"""
+ result = self._run(code)
+ self.assertEqual(result["status"], "success")
+ self.assertIn("bom:bom-ok", result["output"])
+
+
def test_retry_helper_all_fail(self):
"""retry raises the last error when all attempts fail."""
code = """