Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
feat(video): timed attack clips pinned to their canvas, caller motion text, set-wide body height
Soohong Kimd23fe58cb0d2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1818416..f0694a3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,12 @@All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.+## Unreleased (v2.7.0)++- Attack clips are timed strikes pinned to their start. `MOTION_TEXT["attack"]` asks for the same attack twice, each a windup, one strike in front, a held impact pose and a recovery to the exact starting stance with approximate times, keeps what the subject holds in the hand nearest the viewer, and forbids turning. The attack template drops the "evenly paced" line, keeps what the subject holds inside the frame and asks for crisp frames. `video-set` asks attack clips for 4 s by default (other states keep 3 s; `--duration` still sets one length for all) and passes the canvas as `--last-frame`, so the clip ends where it began. The item report records the clip's `duration` and `last_frame`.+- `build_prompt(..., motion=...)` accepts a caller's own motion paragraph in place of the built-in state sentence, keeping the engine's frame, camera, background and design rules.+- `video-set --body-height N` passes one standing-height target to every state's loop (`video-loop --body-height`), so a character comes out the same size in every state even though states use differently shaped canvases.+## v2.6.0 - Automatic local gait selection and XY motion correction- In `motion-auto`, an uncertain fine XY search-boundary match can emit the selected frames unchanged only after the existing rendered-cell seam gate and animation checks pass. Reports and the CLI expose the rejected measurement and unapplied correction. Other failures and explicit `motion` registration remain strict.diff --git a/docs/video-pipeline.md b/docs/video-pipeline.mdindex bdf3498..6cb2c5f 100644--- a/docs/video-pipeline.md+++ b/docs/video-pipeline.md@@ -70,6 +70,21 @@ stance … same height every time"). `video-set` carries those templatesname limbs — the first drafts said "bipedal … knees … arms pumping", which prompted aquadruped and a legless blob into a contradiction (2026-09-09).+An attack is a timed strike, not a repeat. `MOTION_TEXT["attack"]` asks for the same attack+twice, each a windup (about 0.5 s), one strike in front (about 0.25 s), a held impact pose+(about 0.3 s) and a recovery to the exact starting stance (about 0.5 s), with what the subject+holds kept in the hand nearest the viewer and the body never turning. Its template+(`ACTION_COMMON_TEXT`) drops the "evenly paced" line, keeps what the subject holds inside the+frame, and asks for crisp frames without motion blur. `video-set` asks attack clips for 4 s+(`STATE_DURATION_SECONDS`; every other state keeps 3 s, and `--duration` overrides every state)+and pins the clip to end on the frame it starts from: `--last-frame` is the canvas itself+(first-last mode, see [video.md](video.md)), so the strike has to come back to the still.++`build_prompt(direction, state, character, facing, motion=...)` takes a caller's own motion+paragraph — whole sentences about the subject, such as a request interpreter writes per+request — in place of the built-in state sentence. The frame, camera, background and design+rules stay the engine's, and an attack keeps its "twice in a row" sentence.+## 3. Frames — extract, key, check the edges`ffmpeg` extracts every frame; the clip's real fps is recorded (never assumed). Each@@ -312,7 +327,11 @@ Outputs:`sprite-gen video-set --base side=side.png --base front=front.png --states idle,walk,run,jump,attack --out-dir set/`runs canvas → video → frames → loop for every (direction, state). The xAI team quotais **2 requests per second** (five parallel starts produced two HTTP 429s): starts are-staggered (`--start-gap 2`) and a 429 gets a bounded, logged retry (15 s, 30 s). Items+staggered (`--start-gap 2`) and a 429 gets a bounded, logged retry (15 s, 30 s). Clip length+is each state's own default (3 s, attack 4 s) unless `--duration` sets one for all, and an+attack clip is pinned to end on its canvas. States use differently shaped canvases (square, tall, wide),+so the same character films at different pixel heights; `--body-height N` gives every state's loop the+same standing-height target and keeps the character one size across the set. Itemsare idempotent (an existing clip is reused unless `--force`); one failure stops onlyits item and is listed in `table.md` with its stage and error. Exit code is non-zerowhen any item failed.diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.pyindex 5368e96..7ad03b5 100644--- a/sprite_gen/video/batch.py+++ b/sprite_gen/video/batch.py@@ -35,7 +35,20 @@ START_GAP_SECONDS = 2.0# for jump/attack, which the one-shot cut handles; 6 s bought nothing but a longer wait# and, for jump, more idle standing between hops.DEFAULT_DURATION_SECONDS = 3+# An attack is timed rather than repeated: a windup, one strike, a held impact pose and the+# recovery, twice. Four seconds holds both attacks at the stated timing; a shorter clip squeezes+# them, a longer one stretches them.+STATE_DURATION_SECONDS = {"attack": 4}+# States whose clip is pinned to end on the frame it starts from (first-last mode): the model+# has to come back to the still, which is what closes a one-shot action into a loop instead of+# leaving it wherever the strike ended.+PIN_LAST_FRAME_STATES = frozenset({"attack"})RETRY_BACKOFF_SECONDS = (15, 30)+++def duration_for(state: str, requested: int | None) -> int:+ """Seconds to ask for: an explicit request wins, otherwise the state's own default."""+ return requested if requested is not None else STATE_DURATION_SECONDS.get(state, DEFAULT_DURATION_SECONDS)VIEW_TEXT = {"side": "seen from the exact side, facing {facing}","front": "seen from the front, facing the viewer directly",@@ -46,7 +59,13 @@ MOTION_TEXT = {"walk": "moves in place on a treadmill: a steady locomotion cycle for this body type with clear repeating ground contacts and an even left-right or front-back rhythm the body already has.","run": "moves in place on a treadmill: a fast locomotion cycle for this body type with a bounding rhythm and clear repeating ground contacts.","jump": "performs a modest vertical hop in place over and over: compress, spring up about half the body height, land softly, return to the exact starting stance, repeat at an even rhythm. Same height every time.",- "attack": "performs the same melee attack over and over with the weapon it is already holding (bare hands only if it holds nothing), keeping every piece of its gear and outfit exactly as drawn: one clean strike in front, then returns to the exact ready stance, repeating at an even rhythm.",+ "attack": (+ "performs the same melee attack twice in a row with what it is already holding in the hand nearest the viewer "+ "(bare hands only if it holds nothing), keeping every piece of its gear and outfit exactly as drawn. Each attack is "+ "a windup (about 0.5 s), one clean strike in front (about 0.25 s), a held impact pose (about 0.3 s), then a recovery "+ "to the exact starting stance (about 0.5 s). What it holds never changes hands, and the body keeps facing the same "+ "direction without turning."+ ),"cheer": "celebrates in place: rises into a raised, spread-out cheer pose, holds it for a beat, then settles back to the exact starting stance, repeating at an even rhythm.","wave": "waves in place: lifts one side into a friendly wave, sways it a few times, then settles back to the exact starting stance, repeating at an even rhythm.",}@@ -58,6 +77,20 @@ COMMON_TEXT = ("proportions exactly as in the image. Consistent, evenly paced motion so the animation loops.")+# One-shot actions pinned to their first frame (`PIN_LAST_FRAME_STATES`). No "evenly paced" line:+# a strike is fast and a windup is not, so the timing lives in the motion sentence instead. What the+# character holds is kept inside the frame too, and the fast frames are asked to stay crisp.+ACTION_COMMON_TEXT = (+ "2D game sprite animation. The character {motion} The character is {view}. Stays centered in the frame and does "+ "not move across the screen; the body, hair and anything it holds always stay fully inside the frame with margin. "+ "Camera completely locked, no zoom, no pan, no reframing. The background stays a perfectly flat, pure chroma-key fill "+ "for the whole clip — no shadows, no ground line, no particles, no lighting changes, no effects. Keep the design, "+ "colors and proportions exactly as in the image. Crisp, clean frames with no motion blur, no smears and no afterimages."+)+# A caller's own motion paragraph (`build_prompt(motion=...)`) says what one attack is; this says+# how many to make, the same count the built-in attack text asks for.+REPEAT_TEXT = {"attack": "Perform this attack twice in a row with the same timing each time."}+_start_lock = threading.Lock()_last_start = [0.0]@@ -70,16 +103,32 @@ def _staggered_start(gap: float) -> None:_last_start[0] = time.monotonic()-def build_prompt(direction: str, state: str, character: str | None, facing: str = "right") -> str:+def build_prompt(direction: str, state: str, character: str | None, facing: str = "right", motion: str | None = None) -> str:+ """The clip prompt for one (direction, state).++ `motion` replaces the built-in state sentence with the caller's own description of the+ motion, written as whole sentences about the subject (a request interpreter's output, for+ instance). The frame, camera, background and design rules stay the engine's.+ """validate_facing(facing)- motion = MOTION_TEXT.get(state, f"performs the '{state}' action in place, repeating at an even rhythm.")view = VIEW_TEXT.get(direction, f"seen from the {direction}").format(facing=facing)- text = COMMON_TEXT.format(motion=motion, view=view)+ template = ACTION_COMMON_TEXT if state in PIN_LAST_FRAME_STATES else COMMON_TEXT+ if motion is not None:+ motion = " ".join(motion.split())+ if not motion:+ raise SystemExit("video: motion description is empty")+ head = "2D game sprite animation. The character {motion} The character is {view}."+ repeat = f" {REPEAT_TEXT[state]}" if state in REPEAT_TEXT else ""+ subject = character.strip().rstrip(".") if character else "The character"+ return f"2D game sprite animation. {motion}{repeat} {subject} is {view}." + template[len(head):]+ text = template.format(motion=MOTION_TEXT.get(state, f"performs the '{state}' action in place, repeating at an even rhythm."), view=view)return text.replace("The character", character, 1) if character else text-def run_video_cli(image: Path, prompt: str, out: Path, report: Path, *, duration: int, resolution: str, log: Path) -> int:+def run_video_cli(image: Path, prompt: str, out: Path, report: Path, *, duration: int, resolution: str, log: Path, last_frame: Path | None = None) -> int:cmd = [sys.executable, "-m", "sprite_gen.gen.video", "--image", str(image), "--prompt", prompt, "--out", str(out), "--duration", str(duration), "--resolution", resolution, "--no-audio", "--report", str(report)]+ if last_frame is not None:+ cmd += ["--last-frame", str(last_frame)]with log.open("w", encoding="utf-8") as fh:return subprocess.run(cmd, stdout=fh, stderr=subprocess.STDOUT, text=True).returncode@@ -92,7 +141,7 @@ def run_item(base: Path,root: Path,character: str | None,- duration: int,+ duration: int | None,resolution: str,key: str,force: bool,@@ -104,6 +153,7 @@ def run_item(facing: str = "right",facing_fix: str = "none",prepare_side: Callable[[Path], tuple[Path, dict]] | None = None,+ body_height: int | None = None,) -> dict[str, Any]:if anchor == "motion-auto" and not loop_mod.profile_for(state).gait:raise SystemExit("video-set: --anchor motion-auto requires walk/run states")@@ -112,6 +162,7 @@ def run_item(validate_facing(facing, facing_fix)if facing_fix not in facing_mod.FIXES:raise SystemExit("video-set: --facing-fix must be mirror or none")+ duration = duration_for(state, duration)item_dir = root / itemitem_dir.mkdir(parents=True, exist_ok=True)result: dict[str, Any] = {"item": item, "direction": direction, "state": state, "dir": str(item_dir)}@@ -168,7 +219,8 @@ def run_item(attempts: list[int] = []for attempt in range(1 + len(RETRY_BACKOFF_SECONDS)):_staggered_start(gap)- rc = video_runner(canvas_png, prompt, clip, clip_report, duration=duration, resolution=resolution, log=item_dir / "clip.log")+ pin = {"last_frame": canvas_png} if state in PIN_LAST_FRAME_STATES else {}+ rc = video_runner(canvas_png, prompt, clip, clip_report, duration=duration, resolution=resolution, log=item_dir / "clip.log", **pin)attempts.append(rc)if rc == 0 and clip.exists():break@@ -177,14 +229,14 @@ def run_item(time.sleep(RETRY_BACKOFF_SECONDS[attempt])continuebreak- result["clip"] = {"attempts": attempts}+ result["clip"] = {"attempts": attempts, "duration": duration, "last_frame": state in PIN_LAST_FRAME_STATES}if attempts[-1] != 0 or not clip.exists():raise SystemExit(f"clip generation failed after {len(attempts)} attempt(s); see {item_dir / 'clip.log'}")fr = frames_mod.run_frames(clip, item_dir / "frames", key=key, allow_edge_contact=False, report_path=item_dir / "frames.report.json", spill=spill, reference=canvas_png)result["frames"] = {k: fr[k] for k in ("fps", "frames", "alpha_zero_pct_min", "alpha_zero_pct_max")}result["frames"]["spill"] = fr.get("spill", {}).get("mode")- lp = loop_mod.run_loop(Path(fr["keyed_dir"]), item_dir / "loop", fps=float(fr["fps"]), state=state, min_len=None, max_len=None, n_out=None, seam_max=loop_mod.SEAM_RATIO_MAX, name=item, report_path=item_dir / "loop.report.json", anchor=anchor)+ lp = loop_mod.run_loop(Path(fr["keyed_dir"]), item_dir / "loop", fps=float(fr["fps"]), state=state, min_len=None, max_len=None, n_out=None, seam_max=loop_mod.SEAM_RATIO_MAX, name=item, report_path=item_dir / "loop.report.json", anchor=anchor, body_height=body_height)result["loop"] = {"kind": lp["cycle"].get("kind", "periodic"), "cycle": lp["cycle"]["length"], "period": lp["cycle"]["period_global"], "cycle_ratio": round(lp["cycle"]["ratio"], 3), "seam_ratio": lp["resampled_seam_ratio"], "n_out": lp["n_out"], "drift_px": lp["strip"].get("drift_px", 0), "gif": lp["gif"]["file"], "webp": lp["webp"]["file"], "strip": lp["strip"]["path"]}result["loop"]["review_recommended"] = lp["cycle"].get("review_recommended", False)result["loop"]["half_period_guard"] = lp["cycle"].get("half_period_guard")@@ -219,7 +271,7 @@ def run_set(states: list[str],root: Path,character: str | None,- duration: int,+ duration: int | None,resolution: str,key: str,concurrency: int,@@ -231,6 +283,7 @@ def run_set(spill: str = "auto",facing: str = "right",facing_fix: str = "none",+ body_height: int | None = None,) -> dict[str, Any]:if anchor == "motion-auto" and any(not loop_mod.profile_for(state).gait for state in states):raise SystemExit("video-set: --anchor motion-auto requires walk/run states")@@ -260,14 +313,14 @@ def run_set(return prepared[base]with ThreadPoolExecutor(max_workers=max(1, concurrency)) as ex:- futures = {ex.submit(run_item, item=i, direction=d, state=s, base=bases[d], root=root, character=character, duration=duration, resolution=resolution, key=key, force=force, gap=gap, video_runner=video_runner, shape=shape, anchor=anchor, spill=spill, facing=facing, facing_fix=facing_fix, prepare_side=prepare_side): i for i, d, s in items}+ futures = {ex.submit(run_item, item=i, direction=d, state=s, base=bases[d], root=root, character=character, duration=duration, resolution=resolution, key=key, force=force, gap=gap, video_runner=video_runner, shape=shape, anchor=anchor, spill=spill, facing=facing, facing_fix=facing_fix, prepare_side=prepare_side, body_height=body_height): i for i, d, s in items}for fut in as_completed(futures):r = fut.result()results.append(r)print(json.dumps({k: r[k] for k in ("item", "ok") if k in r} | ({"error": r["error"]} if not r.get("ok") else {"seam": r["loop"]["seam_ratio"]}), ensure_ascii=False), flush=True)results.sort(key=lambda r: [i for i, _, _ in items].index(r["item"]))table = write_table(results, root / "table.md")- payload = {"kind": "sprite-gen-video-set-report", "root": str(root), "states": states, "facing": facing, "facing_fix": facing_fix, "directions": list(bases), "ok": sum(1 for r in results if r.get("ok")), "failed": [r["item"] for r in results if not r.get("ok")], "items": results}+ payload = {"kind": "sprite-gen-video-set-report", "root": str(root), "states": states, "facing": facing, "facing_fix": facing_fix, "directions": list(bases), "body_height": body_height, "ok": sum(1 for r in results if r.get("ok")), "failed": [r["item"] for r in results if not r.get("ok")], "items": results}atomic_write_text(root / "set.report.json", json.dumps(payload, ensure_ascii=False, indent=2) + "\n")print(table)return payload@@ -295,7 +348,7 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:parser.add_argument("--states", default="idle,walk,run,jump,attack", help="comma list of motion states")parser.add_argument("--out-dir", required=True, type=Path, help="batch root; one folder per direction-state")parser.add_argument("--character", help="short subject phrase used in the prompts (e.g. 'The armored knight')")- parser.add_argument("--duration", type=int, default=DEFAULT_DURATION_SECONDS, help=f"seconds per clip (default {DEFAULT_DURATION_SECONDS}); a repeating motion holds enough cycles at 3 s and a longer clip only costs more (2026-09-18)")+ parser.add_argument("--duration", type=int, default=None, help=f"seconds per clip for every state (default: {DEFAULT_DURATION_SECONDS}, attack {STATE_DURATION_SECONDS['attack']}); a repeating motion holds enough cycles at 3 s and a longer clip only costs more (2026-09-18)")parser.add_argument("--resolution", default="720p")parser.add_argument("--key", choices=("auto", "green", "magenta", "white"), default="auto")parser.add_argument("--concurrency", type=int, default=3, help="parallel clip generations (starts are staggered regardless)")@@ -303,6 +356,7 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:parser.add_argument("--shape", choices=canvas_mod.SHAPES, help="force one canvas shape for every state (e.g. wide for a costume or arms that leave a 1:1 frame)")parser.add_argument("--anchor", choices=tuple(a for a in loop_mod.ANCHOR_MODES if a != "motion"), default="none", help="motion-auto: automatic regions, local period and XY correction (walk/run only); feet: remove in-canvas drift")parser.add_argument("--spill", choices=frames_mod.SPILL_MODES, default="auto", help="auto: judge key reflections from each item's canvas still (default); small / full: force")+ parser.add_argument("--body-height", type=int, default=None, help="scale every state's loop so the standing height is this many px (video-loop --body-height): one value for the whole set keeps the character the same size across states")parser.add_argument("--force", action="store_true", help="regenerate clips that already exist")@@ -311,10 +365,11 @@ def run(**kwargs: object) -> int:bases=_parse_bases(list(kwargs.get("base") or [])), # type: ignore[arg-type]states=[s.strip() for s in str(kwargs.get("states") or "").split(",") if s.strip()],root=Path(str(kwargs["out_dir"])), character=kwargs.get("character"), # type: ignore[arg-type]- duration=int(kwargs.get("duration") or DEFAULT_DURATION_SECONDS), resolution=str(kwargs.get("resolution") or "720p"), key=str(kwargs.get("key") or "auto"),+ duration=(int(kwargs["duration"]) if kwargs.get("duration") else None), resolution=str(kwargs.get("resolution") or "720p"), key=str(kwargs.get("key") or "auto"),concurrency=int(kwargs.get("concurrency") or 3), force=bool(kwargs.get("force")), gap=float(kwargs.get("start_gap") or START_GAP_SECONDS),facing=str(kwargs.get("facing") or "right"), facing_fix=str(kwargs.get("facing_fix") or "none"),shape=(str(kwargs["shape"]) if kwargs.get("shape") else None), anchor=str(kwargs.get("anchor") or "none"), spill=str(kwargs.get("spill") or "auto"),+ body_height=(int(kwargs["body_height"]) if kwargs.get("body_height") else None),)return 0 if not payload["failed"] else 1diff --git a/tests/video/test_attack_motion.py b/tests/video/test_attack_motion.pynew file mode 100644index 0000000..d3ac667--- /dev/null+++ b/tests/video/test_attack_motion.py@@ -0,0 +1,123 @@+"""Attack clips: a timed strike twice, one hand, no turning, pinned to end where they start.++A 4 s clip, the frame, camera and background rules without the "evenly paced" line, and a+caller's own motion paragraph (`build_prompt(motion=...)`) in place of the built-in one.+"""+from __future__ import annotations++import json+import subprocess+from pathlib import Path++import pytest++from sprite_gen.video import batch as batch_mod++FIXTURE = Path(__file__).parents[1] / "fixtures" / "facing" / "left.png"+++def test_attack_text_is_timed_one_handed_and_twice() -> None:+ text = batch_mod.build_prompt("side", "attack", None)+ for phrase in ("twice in a row", "hand nearest the viewer", "windup (about 0.5 s)", "strike in front (about 0.25 s)",+ "held impact pose (about 0.3 s)", "exact starting stance", "never changes hands", "without turning",+ "anything it holds always stay fully inside the frame", "no motion blur"):+ assert phrase in text, phrase+ assert "evenly paced" not in text+ # the repeating states keep their template, evenly paced line included+ assert "evenly paced" in batch_mod.build_prompt("side", "walk", None)+ assert "no motion blur" not in batch_mod.build_prompt("side", "walk", None)+++def test_a_callers_motion_replaces_the_built_in_sentence() -> None:+ motion = "The knight draws the sword back, then strikes forward and holds the impact pose. It never turns."+ text = batch_mod.build_prompt("side", "attack", "A small knight.", facing="right", motion=motion)+ assert text.startswith(f"2D game sprite animation. {motion} Perform this attack twice in a row with the same timing each time. "+ "A small knight is seen from the exact side, facing right. Stays centered")+ assert text.endswith("no motion blur, no smears and no afterimages.")+ assert "melee attack" not in text # the built-in attack sentence is not added on top+ # whitespace in the paragraph is folded, a missing subject reads "The character"+ assert "The character is seen from the front" in batch_mod.build_prompt("front", "attack", None, motion=" Strikes.\n Holds. ")+ # a state with no repeat sentence and its own template+ walk = batch_mod.build_prompt("side", "walk", None, motion="The fox trots in place.")+ assert "Perform this attack" not in walk and walk.endswith("so the animation loops.")+ with pytest.raises(SystemExit):+ batch_mod.build_prompt("side", "attack", None, motion=" \n ")+++def test_video_cli_pins_the_last_frame_only_when_asked(tmp_path: Path, monkeypatch) -> None:+ seen: list[list[str]] = []++ def fake_run(cmd, **kw):+ seen.append(cmd)+ return subprocess.CompletedProcess(cmd, 0)++ monkeypatch.setattr(batch_mod.subprocess, "run", fake_run)+ common = dict(duration=4, resolution="480p", log=tmp_path / "log")+ batch_mod.run_video_cli(tmp_path / "canvas.png", "p", tmp_path / "c.mp4", tmp_path / "r.json", **common)+ batch_mod.run_video_cli(tmp_path / "canvas.png", "p", tmp_path / "c.mp4", tmp_path / "r.json", last_frame=tmp_path / "canvas.png", **common)+ assert "--last-frame" not in seen[0]+ assert seen[1][seen[1].index("--last-frame") + 1] == str(tmp_path / "canvas.png")+ assert seen[1][seen[1].index("--duration") + 1] == "4"++[email protected]("state,duration,pinned", [("attack", 4, True), ("jump", 3, False)])+def test_video_set_pins_attack_to_its_canvas_for_four_seconds(tmp_path: Path, state: str, duration: int, pinned: bool, monkeypatch) -> None:+ monkeypatch.setattr(batch_mod.facing_mod.vision, "grok_inspect", lambda *a, **kw: ("right", {}))+ calls: list[dict] = []++ def video(image, prompt, out, report, **kw):+ calls.append({"image": image, **kw})+ out.write_bytes(b"test-video")+ report.write_text(json.dumps({"prompt": prompt}))+ return 0++ result = batch_mod.run_item(item=f"side-{state}", direction="side", state=state, base=FIXTURE, root=tmp_path,+ character=None, duration=None, resolution="480p", key="green", force=False, gap=0,+ video_runner=video)+ assert calls[0]["duration"] == duration+ assert ("last_frame" in calls[0]) is pinned+ if pinned:+ assert calls[0]["last_frame"] == calls[0]["image"] == tmp_path / f"side-{state}" / "canvas.png"+ # frames/loop may refuse a synthetic clip; the clip call itself is what this pins+ assert result.get("clip", {}).get("last_frame", pinned) is pinned or not result.get("ok")+++def test_video_set_gives_every_state_the_same_body_height(tmp_path: Path, monkeypatch) -> None:+ from PIL import Image+ seen: list = []++ def fake_canvas(base, out, *, state, shape, facing, headroom, lead, report_path):+ Image.new("RGB", (32, 32), (0, 255, 0)).save(out)+ return {"shape": "square", "canvas": [32, 32], "offset": [0, 0]}++ def fake_frames(clip, out_dir, **kw):+ keyed = Path(out_dir) / "keyed"+ keyed.mkdir(parents=True, exist_ok=True)+ return {"fps": 24.0, "frames": 30, "alpha_zero_pct_min": 0.0, "alpha_zero_pct_max": 0.0, "keyed_dir": str(keyed), "spill": {"mode": "full"}}++ def fake_loop(frames_dir, out_dir, **kw):+ seen.append((kw["state"], kw.get("body_height")))+ return {"cycle": {"kind": "periodic", "length": 24, "period_global": 24, "ratio": 0.2}, "resampled_seam_ratio": 0.3,+ "n_out": 8, "gif": {"file": "g"}, "webp": {"file": "w"}, "strip": {"path": "s", "drift_px": 0}}++ def video(image, prompt, out, report, **kw):+ Path(out).write_bytes(b"x")+ Path(report).write_text(json.dumps({"prompt": prompt}))+ return 0++ monkeypatch.setattr(batch_mod.facing_mod.vision, "grok_inspect", lambda *a, **kw: ("right", {}))+ monkeypatch.setattr(batch_mod.canvas_mod, "run_canvas", fake_canvas)+ monkeypatch.setattr(batch_mod.frames_mod, "run_frames", fake_frames)+ monkeypatch.setattr(batch_mod.loop_mod, "run_loop", fake_loop)+ base = tmp_path / "base.png"+ Image.new("RGB", (32, 32), (0, 255, 0)).save(base)+ payload = batch_mod.run_set(bases={"side": base}, states=["walk", "attack"], root=tmp_path / "set", character=None,+ duration=None, resolution="720p", key="green", concurrency=1, force=False, gap=0.0,+ video_runner=video, body_height=300)+ assert payload["ok"] == 2 and payload["body_height"] == 300+ assert sorted(seen) == [("attack", 300), ("walk", 300)]+ import argparse+ parser = argparse.ArgumentParser()+ batch_mod.add_arguments(parser)+ assert parser.parse_args(["--out-dir", "x", "--body-height", "320"]).body_height == 320+ assert parser.parse_args(["--out-dir", "x"]).body_height is Nonediff --git a/tests/video/test_duration_window_oneshot.py b/tests/video/test_duration_window_oneshot.pyindex bf2f95d..2d0b800 100644--- a/tests/video/test_duration_window_oneshot.py+++ b/tests/video/test_duration_window_oneshot.py@@ -1,6 +1,6 @@"""Synthetic regressions for the 3 s default and its consequences (2026-09-18/20 field tests):-* `video-set` asks for 3 s clips by default;+* `video-set` asks for 3 s clips by default (4 s for attack);* a gait's period window is taken in seconds (floor) and half the clip (ceiling), so a1.0-1.3 s stride is still inside the window of a 3 s clip; idle and the actionstates keep their clip-length fractions;@@ -24,10 +24,12 @@ from sprite_gen.video import loop as loop_modfrom tests.video.test_video_pipeline import HAS_IMG2WEBP, _gait_frames, _one_shot_frames-def test_video_set_defaults_to_three_seconds(monkeypatch) -> None:+def test_video_set_duration_defaults_per_state(monkeypatch) -> None:parser = argparse.ArgumentParser()batch_mod.add_arguments(parser)- assert parser.parse_args(["--out-dir", "x"]).duration == batch_mod.DEFAULT_DURATION_SECONDS == 3+ # unset on the command line means "each state's own default", not one number for all+ assert parser.parse_args(["--out-dir", "x"]).duration is None+ assert parser.parse_args(["--out-dir", "x", "--duration", "6"]).duration == 6seen: dict = {}def fake_run_set(**kw):@@ -36,8 +38,12 @@ def test_video_set_defaults_to_three_seconds(monkeypatch) -> None:monkeypatch.setattr(batch_mod, "run_set", fake_run_set)monkeypatch.setattr(batch_mod, "_parse_bases", lambda items: {})- batch_mod.run(out_dir="x", duration=None) # a caller that leaves it unset gets the default, not 6- assert seen["duration"] == 3+ batch_mod.run(out_dir="x", duration=None)+ assert seen["duration"] is None+ assert batch_mod.DEFAULT_DURATION_SECONDS == 3+ assert batch_mod.duration_for("walk", None) == batch_mod.duration_for("jump", None) == 3+ assert batch_mod.duration_for("attack", None) == 4+ assert batch_mod.duration_for("attack", 6) == batch_mod.duration_for("walk", 6) == 6def test_gait_windows_are_in_seconds_capped_at_half_the_clip() -> None: