fix(map): reject duplicate YAML keys via a SafeLoader duplicate-check

This commit is contained in:
2026-09-20 18:00:27 +02:00
parent 53c6dc0b43
commit ee22f7548a
2 changed files with 55 additions and 1 deletions
+21
View File
@@ -67,6 +67,27 @@ def test_minimal_map_without_optional_layers(tmp_path: Path) -> None:
assert zone_cells(spec, "A") == []
def test_rejects_duplicate_yaml_keys(tmp_path: Path) -> None:
"""PyYAML is silently last-wins on duplicate mapping keys; a map that
declares `name` (or a legend entry) twice must fail, not keep one."""
body = _minimal_map() + 'name: "Test bis"\n'
with pytest.raises(MapValidationError, match="duplicate mapping key"):
load_map(_write(tmp_path, body))
def test_rejects_duplicate_legend_keys(tmp_path: Path) -> None:
body = _minimal_map().replace(
' ".": { type: floor, move_cost: 1 }\n',
' ".": { type: floor, move_cost: 1 }\n ".": { type: wall, move_cost: null }\n',
)
with pytest.raises(MapValidationError, match="duplicate mapping key"):
load_map(_write(tmp_path, body))
def test_accepts_map_without_duplicates(tmp_path: Path) -> None:
assert load_map(_write(tmp_path, _minimal_map())).name == "Test"
def test_rejects_ragged_rows(tmp_path: Path) -> None:
body = _minimal_map().replace(" #.#\n", " #.##\n")
with pytest.raises(MapValidationError):