The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(config): preserve long quoted scalars
Hukla7f59505685f6
diff --git a/tests/test_utils_atomic_roundtrip_yaml_save.py b/tests/test_utils_atomic_roundtrip_yaml_save.pyindex 729182ca7d0..a5eb16260dd 100644--- a/tests/test_utils_atomic_roundtrip_yaml_save.py+++ b/tests/test_utils_atomic_roundtrip_yaml_save.py@@ -120,6 +120,20 @@ class TestAtomicRoundtripYamlSave:assert "\\u4f60" not in textassert "\\u30CE" not in text+ def test_preserves_long_double_quoted_scalar_with_backslash(self, config_path):+ """A no-op save must not turn fold indentation after a backslash into data."""+ value = "A" * 74 + r"D:\CentBrowserPortable " + "B" * 40+ config_path.write_text(+ 'policy: "' + value.replace("\\", "\\\\") + '"\n',+ encoding="utf-8",+ )++ from utils import atomic_roundtrip_yaml_save++ atomic_roundtrip_yaml_save(config_path, {"policy": value})++ assert yaml.safe_load(config_path.read_text(encoding="utf-8"))["policy"] == value+def test_appends_new_keys(self, config_path):config_path.write_text("model:\n"diff --git a/utils.py b/utils.pyindex cb4db2f4add..bbfa4e7c5b4 100644--- a/utils.py+++ b/utils.py@@ -431,6 +431,14 @@ def atomic_yaml_write(path: Union[str, Path], data: Any, *, default_flow_style:_atomic_write(path, _write, prefix=f".{path.stem}_", mode=_mode_for_write(path, create_mode))+# ruamel's emitter can change a double-quoted value when it folds a long line right after an+# escaped backslash (``D:\\Cent…`` → ``D:\\`` + bare newline): the fold reloads as a literal space+# and a no-op save mutates the stored value (#119844). Config writes must be value-preserving, so+# every round-trip emitter in the tree keeps scalars on one line instead of folding (``None``+# does NOT disable folding on 0.18.x; only a large width does).+ROUNDTRIP_YAML_WIDTH = 2**31 - 1++def _roundtrip_load(path: Path):"""``(yaml_rt, CommentedMap)``: a ruamel round-trip loader keeping quotes/Unicode with 2-spaceindents, plus *path* loaded through it (empty map when missing/blank)."""@@ -438,6 +446,7 @@ def _roundtrip_load(path: Path):from ruamel.yaml.comments import CommentedMapyaml_rt = YAML(typ="rt")+ yaml_rt.width = ROUNDTRIP_YAML_WIDTHyaml_rt.preserve_quotes = Trueyaml_rt.allow_unicode = Trueyaml_rt.default_flow_style = False