diff --git a/src/python/jw/util/load_yaml.py b/src/python/jw/util/load_yaml.py index c16035f..76b4abe 100644 --- a/src/python/jw/util/load_yaml.py +++ b/src/python/jw/util/load_yaml.py @@ -36,7 +36,8 @@ def _merge_at_path(root: dict[str, Any], path: tuple[str, ...], last_key = path[-1] if (last_key in current and isinstance(current[last_key], dict) and isinstance(value, dict)): - current[last_key] = _deep_merge(current[last_key], value) + # root's existing content wins (merge value into root) + current[last_key] = _deep_merge(value, current[last_key]) else: current[last_key] = deepcopy(value) return root diff --git a/test/unit/python/jw/util/load_yaml/test.py b/test/unit/python/jw/util/load_yaml/test.py index e0ceb1e..31e28a9 100644 --- a/test/unit/python/jw/util/load_yaml/test.py +++ b/test/unit/python/jw/util/load_yaml/test.py @@ -864,10 +864,10 @@ class TestIncludeWithPath: assert data['entry']['from_include'] == 'included' def test_include_override_existing(self, temp_dir: Callable) -> None: - """Include overrides existing values at target path.""" + """Local content at target path overrides included content.""" base = temp_dir( [ - ('base.yaml', 'existing: overwritten\n'), + ('base.yaml', 'existing: from_include\n'), ( 'main.yaml', 'entry:\n existing: original\njw.include: entry|base.yaml\n' @@ -875,7 +875,8 @@ class TestIncludeWithPath: ] ) data = load_yaml(pathlib.Path(base) / 'main.yaml') - assert data['entry']['existing'] == 'overwritten' + # Local content (original) wins over included (from_include) + assert data['entry']['existing'] == 'original' def test_multiple_includes_different_paths(self, temp_dir: Callable) -> None: """Multiple includes can target different paths."""