load_yaml: Fix jw.include overriding local content
When jw.include merges content at a target path, the local content in the main document should take precedence over the included content (siblings win, and the main file is the ultimate source of truth). Fix _merge_at_path so that root's existing content at the target path wins over the value being merged in. Also update the test_include_override_existing test to reflect the correct semantics: local content overrides included content. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
c514ae9077
commit
b18b2f0b65
1 changed files with 6 additions and 4 deletions
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue