Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

fix(video-set): refuse a --base direction the prompt table does not know

Soohong Kim19a010515a2b
diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.py
index 0491d0a..97351aa 100644
--- a/sprite_gen/video/batch.py
+++ b/sprite_gen/video/batch.py
@@ -267,7 +267,10 @@ def _parse_bases(values: list[str]) -> dict[str, Path]:
if "=" not in v:
raise SystemExit(f"video-set: --base expects direction=path, got {v!r}")
d, p = v.split("=", 1)
- bases[d.strip()] = Path(p).expanduser().resolve()
+ d = d.strip()
+ if d not in VIEW_TEXT:
+ raise SystemExit(f"video-set: --base direction must be one of {', '.join(sorted(VIEW_TEXT))}, got {d!r}")
+ bases[d] = Path(p).expanduser().resolve()
if not bases:
raise SystemExit("video-set: at least one --base direction=path is required")
return bases
diff --git a/tests/video/test_batch_bases.py b/tests/video/test_batch_bases.py
new file mode 100644
index 0000000..e29fb31
--- /dev/null
+++ b/tests/video/test_batch_bases.py
@@ -0,0 +1,31 @@
+"""`video-set --base` accepts only the directions the prompt table knows.
+
+An undocumented key such as `left=` used to be accepted silently and then
+animated with the default facing, so the caller's intent was inverted without
+a word. The parser now names the allowed directions and refuses the rest.
+"""
+from __future__ import annotations
+
+import pytest
+
+from sprite_gen.video import batch
+
+
+def test_known_directions_parse(tmp_path):
+ still = tmp_path / "s.png"
+ still.write_bytes(b"")
+ bases = batch._parse_bases([f"side={still}", f"front={still}", f"back={still}"])
+ assert set(bases) == {"side", "front", "back"}
+
+
[email protected]("key", ["left", "right", "Side", "profile"])
+def test_unknown_direction_is_refused_by_name(key, tmp_path):
+ with pytest.raises(SystemExit) as exc:
+ batch._parse_bases([f"{key}={tmp_path / 's.png'}"])
+ message = str(exc.value)
+ assert repr(key) in message and "back, front, side" in message
+
+
+def test_missing_equals_still_refused():
+ with pytest.raises(SystemExit):
+ batch._parse_bases(["side"])