Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(video): an explicit --max-len caps the two-cycle window, and only a declared loop gets cycles_kept
Soohong Kim3d6cbcf72823
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 457356a..880fe7e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,10 +4,10 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the## Unreleased - A staff that closes at the top and swings below the hand is cut two steps long-- **Output change: once the top of the silhouette jumps at its first choice, `video-loop --anchor motion-auto` reads the held part below its top too, and may cut two steps long.** A staff that turns about the hand once in two steps comes back to the same place at the top band half its turn later, moving the other way: v2.35.0 chose again on the top band alone, took such a cut — the top closed — and the shaft under the hand swung back at the wrap, with no warning. Now, behind the seam pop only, the side of the body the top band sits on is read row by row on the silhouette's outer edge (`repair.held_side`, `repair.side_edges`, `repair.held_edge` on the frames the search chooses from, `loop.HeldEdge`): per row, the cut's first and last frames against the clip's frames after its last and before its first, in place and in speed, over the row's median step in the loop; the 80th percentile over the rows is the held seam, closing under **1.2** (`repair.HELD_EDGE_REFERENCE`). Among the candidates whose top does not jump, one whose held side closes is taken (the usual 15 % of the best score, then the smallest held seam). Where no cut one step long closes it, windows twice a candidate's length are read — two cycles of a confirmed repeat, not themselves seen repeating — and one whose held side closes and whose top does not jump is cut: the report's `cycle.cycles` is `2`, and `strip.json` carries `cycles: 2`. A cut with fewer than two clip frames either side of it cannot be read: `skipped`, counted under `unread`, never chosen. `cycle.seam_pop.held_edge` records `side`, `reference`, `measured`, `unread`, `cycles`, `chosen` and `two_cycle` (lengths tried, `measured`, `unread`, `top_pops`, `closing`); a candidate row carries `held_edge` (`null` with `held_edge_skipped`). A first choice whose top does not jump reads nothing new: a walk without a part held above its head is cut, written and warned about byte for byte as before. [docs/loop-repair.md](docs/loop-repair.md#the-held-side--a-staff-that-closes-at-the-top-and-swings-below-the-hand).-- **New warning: a held part that no window one or two steps long closes.** The top band's cut stands and `jolt.warnings` and stderr gain `the held part does not close at the wrap on the <side> side of the silhouette, below its top: …x its rows' median step (over 1.2); no window one or two cycles long closes it — it swings on a beat of its own`; a held side that could not be read is said as well. Nothing fails on it.-- **Output change: `video-cycle-align` keeps a loop cut two steps long on purpose two steps long.** A loop whose `strip.json` says `cycles: 2` is not stopped as a suspect (its suspects carry `status: "declared"`), counts half its length toward the set's length, and is resampled to twice that length; its row and its `strip.json` `cycle_align` carry `cycles_kept`. Before, the screen stopped the set on it, and `--cycles <loop>=2` cut the held part's wrap back in while `=1` played it twice as fast. A `--cycles` count given for it is still the last word. Every loop without `cycles` in its `strip.json` is aligned as before.-- **`tests/video/test_loop_prop_seam_held.py`** draws a walker stepping every 24 frames with a staff turning about the hand every 48: v2.35.0 cuts it one step long where the top closes and the staff's foot swings back at the wrap at twice its largest step inside the loop; now every cut one step long whose top closes reads a held seam of 2.0 to 5.2, and the window two steps long taken reads 0. A staff swinging with the step below a pennant that sways on its own beat stays one step long (0 to 0.5); a staff whose foot swings every 37 frames is kept on the top band's cut and warned about; a walk without a staff reads nothing below its top; the set alignment keeps the two-step loop at twice the set's length.+- **Output change: once the top of the silhouette jumps at its first choice, `video-loop --anchor motion-auto` reads the held part below its top too, and may cut two steps long.** A staff that turns about the hand once in two steps comes back to the same place at the top band half its turn later, moving the other way: v2.35.0 chose again on the top band alone, took such a cut — the top closed — and the shaft under the hand swung back at the wrap, with no warning. Now, behind the seam pop only, the side of the body the top band sits on is read row by row on the silhouette's outer edge (`repair.held_side`, `repair.side_edges`, `repair.held_edge` on the frames the search chooses from, `loop.HeldEdge`): per row, the cut's first and last frames against the clip's frames after its last and before its first, in place and in speed, over the row's median step in the loop; the 80th percentile over the rows is the held seam, closing under **1.2** (`repair.HELD_EDGE_REFERENCE`). Among the candidates whose top does not jump, one whose held side closes is taken (the usual 15 % of the best score, then the smallest held seam). Where no cut one step long closes it, windows twice a candidate's length are read — two cycles of a confirmed repeat, not themselves seen repeating — and one whose held side closes and whose top does not jump is cut: the report's `cycle.cycles` is `2`, and `strip.json` carries `cycles: 2`. A cut with fewer than two clip frames either side of it cannot be read: `skipped`, counted under `unread`, never chosen. An explicit `--max-len` stays the cut's ceiling: windows two steps long over it are not read (`two_cycle_capped`: `max_len`, `lengths_over`); the state's default window is no ceiling. `cycle.seam_pop.held_edge` records `side`, `reference`, `measured`, `unread`, `cycles`, `chosen` and `two_cycle` (lengths tried, `measured`, `unread`, `top_pops`, `closing`); a candidate row carries `held_edge` (`null` with `held_edge_skipped`). A first choice whose top does not jump reads nothing new: a walk without a part held above its head is cut, written and warned about byte for byte as before. [docs/loop-repair.md](docs/loop-repair.md#the-held-side--a-staff-that-closes-at-the-top-and-swings-below-the-hand).+- **New warning: a held part that no window one or two steps long closes.** The top band's cut stands and `jolt.warnings` and stderr gain `the held part does not close at the wrap on the <side> side of the silhouette, below its top: …x its rows' median step (over 1.2); no window one or two cycles long closes it — it swings on a beat of its own` (or, where `--max-len` kept windows two steps long from being read, `no window one cycle long closes it, and windows two cycles long (…-… frames) are over --max-len N, so they were not read`); a held side that could not be read is said as well. Nothing fails on it.+- **Output change: `video-cycle-align` keeps a loop cut two steps long on purpose two steps long.** A loop whose `strip.json` says `cycles: 2` is not stopped as a suspect (its suspects carry `status: "declared"`), counts half its length toward the set's length, and is resampled to twice that length; its row and its `strip.json` `cycle_align` carry `cycles_kept`. Before, the screen stopped the set on it, and `--cycles <loop>=2` cut the held part's wrap back in while `=1` played it twice as fast. A `--cycles` count given for it is still the last word. Every loop without `cycles` in its `strip.json` is aligned as before, its row, `strip.json` and cells byte for byte (no `cycles_kept`).+- **`tests/video/test_loop_prop_seam_held.py`** draws a walker stepping every 24 frames with a staff turning about the hand every 48: v2.35.0 cuts it one step long where the top closes and the staff's foot swings back at the wrap at twice its largest step inside the loop; now every cut one step long whose top closes reads a held seam of 2.0 to 5.2, and the window two steps long taken reads 0. A staff swinging with the step below a pennant that sways on its own beat stays one step long (0 to 0.5); a staff whose foot swings every 37 frames is kept on the top band's cut and warned about; a walk without a staff reads nothing below its top; the set alignment keeps the two-step loop at twice the set's length. With `--max-len 25` the staff walker is cut one step long and warned about, and two loops without a staff are aligned with exactly the `strip.json` and `cycle_align` keys v2.35.0 wrote.## v2.35.0 - A staff that swings on its own beat is not cut where it jumpsdiff --git a/docs/loop-repair.md b/docs/loop-repair.mdindex 5f34a4a..94b5a31 100644--- a/docs/loop-repair.md+++ b/docs/loop-repair.md@@ -342,12 +342,18 @@ A cut with fewer than two clip frames on either side has nothing to read its wrathat cannot be read is not taken) is cut, the smallest held seam first: `cycle.cycles` is **2**,`cycle.period_local` half its length, `cycle.seam_pop.chosen.cycles` 2 and `strip.json` `cycles: 2`.`two_cycle` records the lengths tried and how many were `measured`, `unread`, `top_pops` and- `closing`.+ `closing`. An explicit `--max-len` is the caller's ceiling on the cut and stays one: a window two+ steps long over it is not read (`two_cycle_capped`: `max_len`, `lengths_over`), and where every+ such length is over it, nothing two steps long is read at all. The state's default window is no+ ceiling here: without `--max-len` every length is read.3. If no window one or two steps long closes it, the top band's choice stands (as above),`held_edge.chosen` records its seam, and `jolt.warnings` and stderr gain`video-loop: warning: the held part does not close at the wrap on the right side of thesilhouette, below its top: 5.50x its rows' median step (over 1.2); no window one or two cycles- long closes it — it swings on a beat of its own`. A side that could not be read is said as well.+ long closes it — it swings on a beat of its own`. Where `--max-len` kept windows two steps long+ from being read, the line ends `no window one cycle long closes it, and windows two cycles long+ (47-49 frames) are over --max-len 25, so they were not read` instead. A side that could not be+ read is said as well.A first choice whose top does not pop reads nothing here: a walk without a part held above its headis cut, written and warned about exactly as before.@@ -383,7 +389,9 @@ sprite-gen video-cycle-align --loop-dir set/front-walk/loop --loop-dir set/side-cuts two steps where a held part closes only there (section 3, "The held side") and marks it`cycles: 2` in `strip.json`. The alignment does not stop on it: its length counts per cycle towardthe set's length, and it is resampled to twice that length, keeping both cycles (`cycles_kept` on- its row and in its `strip.json` `cycle_align`; its suspects carry `status: "declared"`). A+ its row and in its `strip.json` `cycle_align`; its suspects carry `status: "declared"`). Only a+ loop whose `strip.json` declares `cycles` gets `cycles_kept`: every other loop's row, `strip.json`+ and cells are written as before, byte for byte. A`--cycles` count given for it is still the last word: `--cycles <loop>=2` takes one cycle out ofit (the held part then swings back at that cut's wrap), `=1` aligns it at the set's length.- **Two cycles in one loop are stopped, and counted by whoever looks**: one length for the set isdiff --git a/sprite_gen/video/align.py b/sprite_gen/video/align.pyindex 385a1d1..fee9451 100644--- a/sprite_gen/video/align.py+++ b/sprite_gen/video/align.py@@ -723,7 +723,9 @@ def align_set(loop_dirs: list[Path], *, length: int | None = None, interpolate:**{key: strike[key] for key in ("foot", "foot_why", "foot_given", "foot_unnamed_why", "foot_disagrees") if key in strike},"stride_swing": strike["stride_swing"], "reach_swing": strike["reach_swing"],"fps": round(fps, 4), "source": SOURCE_DIR, "cycles_given": given.get(i), "cycle_screen": screens[i],- **({"cycle_taken": taken[i]} if i in taken else {}), "cycles_kept": kept[i],+ **({"cycle_taken": taken[i]} if i in taken else {}),+ # only on a loop its cutter declared more than one cycle long: every other loop's record is as before+ **({"cycles_kept": kept[i]} if "cycles" in loops[i][2] else {}),"made_at": [(k - start) % len(out) for k in facts["made_at"]]}if "nearest_at" in facts:record["nearest_at"] = sorted((k - start) % len(out) for k in facts["nearest_at"])diff --git a/sprite_gen/video/local_cycle.py b/sprite_gen/video/local_cycle.pyindex d1f5012..9fe568f 100644--- a/sprite_gen/video/local_cycle.py+++ b/sprite_gen/video/local_cycle.py@@ -65,13 +65,14 @@ def _held(measured):return {'skipped': measured['skipped']} if 'skipped' in measured else {'seam': measured['seam'], 'closes': measured['closes']}-def _held_rank(candidates, calm, chosen, wrap_pop, held_edge):+def _held_rank(candidates, calm, chosen, wrap_pop, held_edge, length_cap=None):"""Below the top band (`held_edge`, repair.held_edge on the side the popping first choice holds itspart): among the calm candidates, those whose held side closes, the same score tolerance, then thesmallest held seam. When no one-cycle candidate closes it, windows twice a candidate's length(`cycles` 2): a part swinging once in two cycles closes only there. Such a window is two cycles ofa repeat the search confirmed, not itself seen repeating; it is taken when its held side closes and- its top does not pop, the smallest held seam first. Returns (picked or None, record)."""+ its top does not pop, the smallest held seam first. A window longer than `length_cap` (an explicit+ --max-len) is not one. Returns (picked or None, record)."""side = held_edge.side(chosen['start'], chosen['length'])if 'skipped' in side:return None, {'method': 'held-side-edge-v1', 'skipped': side['skipped']}@@ -95,6 +96,13 @@ def _held_rank(candidates, calm, chosen, wrap_pop, held_edge):record.update(cycles=1, chosen={'start': picked['start'], 'length': picked['length'], 'seam': picked['held_edge'], 'closes': True})return picked, recordlengths = sorted({2*row['length']+d for row in candidates for d in (-1, 0, 1)})+ if length_cap is not None:+ over = [length for length in lengths if length > length_cap]+ lengths = [length for length in lengths if length <= length_cap]+ if over:+ record['two_cycle_capped'] = {'max_len': length_cap, 'lengths_over': [over[0], over[-1]]}+ if not lengths:+ return None, recordwindows = []counts = {'measured': 0, 'unread': 0, 'top_pops': 0}for length in lengths:@@ -121,7 +129,7 @@ def _held_rank(candidates, calm, chosen, wrap_pop, held_edge):return None, record-def _shape_rank(candidates, chosen, wrap_pop, held_edge=None):+def _shape_rank(candidates, chosen, wrap_pop, held_edge=None, length_cap=None):"""Choose again when the chosen cut's top pops at the wrap (`wrap_pop`, repair.seam_pop on theanalysed frames): among the candidates whose top was read and does not pop, the same scoretolerance, then the smallest pop. Nothing is measured past the first choice when it does not pop,@@ -131,7 +139,7 @@ def _shape_rank(candidates, chosen, wrap_pop, held_edge=None):With `held_edge` (loop.HeldEdge), a popping first choice has its held part read below the top too(`_held_rank`): a cut whose held side closes is taken first, one or two cycles long. Where nonecloses, the choice is the top band's, and `held_edge.chosen` records that it does not close (the- jolt warns, repair.held_edge_verdict)."""+ jolt warns, repair.held_edge_verdict). A two-cycle window is never longer than `length_cap`."""first = wrap_pop(chosen['start'], chosen['length'])record = {'method': 'top-band-wrap-v1', 'reference': first['reference'],'first_choice': {'start': chosen['start'], 'length': chosen['length'], **_read(first)},@@ -150,7 +158,7 @@ def _shape_rank(candidates, chosen, wrap_pop, held_edge=None):record.update(measured=len(candidates)-unread, unread=unread)held = Noneif held_edge is not None:- picked, held = _held_rank(candidates, calm, chosen, wrap_pop, held_edge)+ picked, held = _held_rank(candidates, calm, chosen, wrap_pop, held_edge, length_cap)record['held_edge'] = heldif picked is not None:record.update(applied=True, chosen={'start': picked['start'], 'length': picked['length'], 'pop': picked['seam_pop'],@@ -172,12 +180,14 @@ def _shape_rank(candidates, chosen, wrap_pop, held_edge=None):def detect(distances, trajectory, *, min_len, max_len, gait_floor,periodicity_min, double_tolerance, double_search, max_fraction=.5, signals=None, wrap_pop=None,- held_edge=None):+ held_edge=None, length_cap=None):"""`wrap_pop(start, length)`, when given, is the top band's jump at that cut's wrap(repair.seam_pop): a chosen cut that pops is chosen again (`_shape_rank`), and a search that findsnothing raises with the windows it refused, popping ones last (`ValueError.diagnostics`).`held_edge` (loop.HeldEdge) reads the held side below the top of a cut chosen again; the cut it- takes may be two cycles long (`cycles` 2 in the result)."""+ takes may be two cycles long (`cycles` 2 in the result), but never longer than `length_cap`, an+ explicit --max-len: the caller's ceiling on the cut, which `max_len` alone does not mark (the+ state's default window is one too)."""n = len(distances)# A cycle has to be seen repeating: half the clip by default, more for the gait fallback.lo, hi = max(6, min_len), min(max_len, int(n*max_fraction))@@ -271,7 +281,7 @@ def detect(distances, trajectory, *, min_len, max_len, gait_floor,key=lambda row: (row['start'], row['score'], row['length']))shape = Noneif wrap_pop is not None:- chosen, shape = _shape_rank(candidates, chosen, wrap_pop, held_edge)+ chosen, shape = _shape_rank(candidates, chosen, wrap_pop, held_edge, length_cap)radius, js = _around(chosen['start'], chosen['length'])profile = _profile(distances, js, radius, lo, hi)fundamental = period_mod.screen(diff --git a/sprite_gen/video/loop.py b/sprite_gen/video/loop.pyindex ab8018e..4ac3356 100644--- a/sprite_gen/video/loop.py+++ b/sprite_gen/video/loop.py@@ -1028,7 +1028,7 @@ def run_loop(try:moved = moved_alpha(source_frames, analysis)cycle = local_cycle.detect(D, trajectory, min_len=lo, max_len=hi, signals=leg_signals(source_frames),- wrap_pop=wrap_pop_on(moved), held_edge=HeldEdge(moved), **detect)+ wrap_pop=wrap_pop_on(moved), held_edge=HeldEdge(moved), length_cap=max_len, **detect)except ValueError as first:# A front or back gait that walked toward the camera, or a slow one: one more# search, recorded (`gait_fallback`), and only after the first found nothing.@@ -1051,7 +1051,7 @@ def run_loop(cycle = local_cycle.detect(D, trajectory, min_len=lo, max_len=hi_long,max_fraction=gait_fallback.LONG_CYCLE_FRACTION if max_len is None else .5,signals=leg_signals(source_frames), wrap_pop=wrap_pop_on(moved),- held_edge=HeldEdge(moved), **detect)+ held_edge=HeldEdge(moved), length_cap=max_len, **detect)except ValueError as second:failed = ValueError(f"{second} (also with the gait fallback: window [{lo}, {hi_long}], "f"scale drift {drift['drift']:+.1%}{', undone' if fallback['scale_undone'] else ''})")diff --git a/sprite_gen/video/repair.py b/sprite_gen/video/repair.pyindex aa63f3e..bc64d80 100644--- a/sprite_gen/video/repair.py+++ b/sprite_gen/video/repair.py@@ -319,9 +319,15 @@ def held_edge_verdict(shape: dict[str, Any] | None) -> list[str]:"closes below its top is not known"]if chosen["closes"]:return []- return [f"the held part does not close at the wrap on the {held['side']} side of the silhouette, below its top: "- f"{chosen['seam']:.2f}x its rows' median step (over {held['reference']:g}); no window one or two cycles long "- "closes it — it swings on a beat of its own"]+ line = (f"the held part does not close at the wrap on the {held['side']} side of the silhouette, below its top: "+ f"{chosen['seam']:.2f}x its rows' median step (over {held['reference']:g}); ")+ capped = held.get("two_cycle_capped")+ if capped:+ # An explicit --max-len is the caller's ceiling: windows two cycles long past it are not read.+ low, high = capped["lengths_over"]+ return [line + f"no window one cycle long closes it, and windows two cycles long ({low}-{high} frames) are over "+ f"--max-len {capped['max_len']}, so they were not read"]+ return [line + "no window one or two cycles long closes it — it swings on a beat of its own"]def measure_jolt(frames: list[Image.Image], *, facing: str = "right") -> dict[str, Any]:diff --git a/tests/video/test_loop_prop_seam_held.py b/tests/video/test_loop_prop_seam_held.pyindex cd68e51..3adbee7 100644--- a/tests/video/test_loop_prop_seam_held.py+++ b/tests/video/test_loop_prop_seam_held.py@@ -14,6 +14,7 @@ from __future__ import annotationsimport jsonimport math+import shutilfrom pathlib import Pathimport numpy as np@@ -66,10 +67,10 @@ def _keyed(root: Path, **kw) -> Path:return keyed-def _cut(root: Path, keyed: Path) -> dict:+def _cut(root: Path, keyed: Path, *extra: str) -> dict:out = root / "out"assert loop.main(["--frames-dir", str(keyed), "--out-dir", str(out), "--state", "walk",- "--anchor", "motion-auto", "--repair", "off"]) == 0+ "--anchor", "motion-auto", "--repair", "off", *extra]) == 0return json.loads((out / "loop.loop.report.json").read_text())@@ -138,6 +139,21 @@ def test_a_held_part_no_window_closes_is_kept_on_the_top_bands_choice_and_warnedassert len(lines) == 1 and "right side" in lines[0]+def test_an_explicit_max_len_is_not_widened_by_a_window_two_cycles_long(tmp_path):+ """--max-len 25 is the caller's ceiling: the windows two steps long (47-49 frames) that would close+ the staff are over it and are not read. The cut is the top band's, one step long, and the jolt says+ the held part does not close and why nothing longer was looked at."""+ report = _cut(tmp_path, _keyed(tmp_path), "--max-len", "25")+ cycle = report["cycle"]+ assert cycle["length"] <= 25 and "cycles" not in cycle+ held_edge = cycle["seam_pop"]["held_edge"]+ assert held_edge["two_cycle_capped"] == {"max_len": 25, "lengths_over": [2 * STEP - 1, 2 * STEP + 1]}+ assert "two_cycle" not in held_edge and held_edge["chosen"]["closes"] is False+ assert "cycles" not in json.loads((tmp_path / "out" / "loop.strip.json").read_text())+ (line,) = [line for line in report["jolt"]["warnings"] if "held part does not close" in line]+ assert "over --max-len 25" in line++def test_a_walk_whose_top_does_not_pop_reads_nothing_below_it(tmp_path):report = _cut(tmp_path, _keyed(tmp_path, staff=False))shape = report["cycle"]["seam_pop"]@@ -203,6 +219,10 @@ def test_held_edge_verdict_speaks_only_for_a_held_side_that_does_not_close():(line,) = repair.held_edge_verdict({"held_edge": {"side": "right", "reference": 1.2,"chosen": {"start": 0, "length": 23, "skipped": "the clip has no two frames"}}})assert "could not be read at this cut" in line+ capped = {"held_edge": {**misses["held_edge"], "two_cycle_capped": {"max_len": 25, "lengths_over": [45, 47]}}}+ (line,) = repair.held_edge_verdict(capped)+ assert "no window one cycle long closes it" in line and "(45-47 frames) are over --max-len 25" in line+ assert "beat of its own" not in line# --- choosing on it ---------------------------------------------------------------------------@@ -262,6 +282,25 @@ def test_shape_rank_takes_two_cycles_when_no_one_cycle_cut_closes_and_never_an_uassert record["chosen"] == {"start": 12, "length": 47, "pop": 0.0, "cycles": 2}+def test_shape_rank_reads_no_window_two_cycles_long_over_the_length_cap():+ table = {(10, 48): 0.9, (12, 47): 0.4, (20, 49): 0.3}+ # Under a cap of 46 no window two cycles long is read: the top band's choice, and the record says why.+ candidates = [dict(r) for r in ROWS]+ fake = _FakeHeld(dict(table))+ chosen, record = local_cycle._shape_rank(candidates, candidates[0], _pop({(0, 24): 14.0}), fake, length_cap=46)+ assert (chosen["start"], chosen["length"]) == (3, 24) and "cycles" not in chosen+ assert all(length <= 46 for _, length in fake.read)+ held = record["held_edge"]+ assert held["two_cycle_capped"] == {"max_len": 46, "lengths_over": [47, 49]} and "two_cycle" not in held+ # A cap of 48 reads 47 and 48 only: (20, 49) is over it, so (12, 47) is taken.+ candidates = [dict(r) for r in ROWS]+ fake = _FakeHeld(dict(table))+ chosen, record = local_cycle._shape_rank(candidates, candidates[0], _pop({(0, 24): 14.0}), fake, length_cap=48)+ assert (chosen["start"], chosen["length"], chosen["cycles"]) == (12, 47, 2)+ assert record["held_edge"]["two_cycle"]["lengths"] == [47, 48] and max(length for _, length in fake.read) == 48+ assert record["held_edge"]["two_cycle_capped"] == {"max_len": 48, "lengths_over": [49, 49]}++def test_shape_rank_without_a_closing_window_keeps_the_top_bands_choice_and_records_it():candidates = [dict(r) for r in ROWS]chosen, record = local_cycle._shape_rank(candidates, candidates[0], _pop({(0, 24): 14.0}), _FakeHeld({}, frames=60))@@ -294,7 +333,7 @@ def test_cycle_align_keeps_a_two_cycle_loop_two_cycles_at_twice_the_set_length(htwo, one = out["loops"]target = round(float(np.median([lengths[0] / 2, lengths[1]])))assert out["length"] == target and two["to"] == 2 * target and one["to"] == target- assert two["cycles_kept"] == 2 and one["cycles_kept"] == 1+ assert two["cycles_kept"] == 2 and "cycles_kept" not in oneassert all(e["status"] == "declared" for e in out["suspects"] if e["dir"] == str((root / "out").resolve()))assert json.loads((root / "out" / "loop.strip.json").read_text())["cycles"] == 2assert "cycles" not in json.loads((one_step / "out" / "loop.strip.json").read_text())@@ -302,3 +341,28 @@ def test_cycle_align_keeps_a_two_cycle_loop_two_cycles_at_twice_the_set_length(hout = align.align_set([root / "out", one_step / "out"], between="nearest", cycles={str(root / "out"): 2})assert out["loops"][0]["cycles_kept"] == 1 and "cycle_taken" in out["loops"][0]assert "cycles" not in json.loads((root / "out" / "loop.strip.json").read_text())+++# What v2.35.0 wrote for a loop cut one cycle long (no `cycles` in its strip metadata): aligning it+# writes exactly these, so a set without a held part is rewritten as before.+STRIP_KEYS_2350 = {"body_h", "body_height_target", "body_ref", "body_src_h", "cell_cap", "cell_height_cap", "cycle_align",+ "cycle_drawings", "cycle_frames", "cycle_seconds", "delay_ms", "drawings", "drift_px", "foot_anchor",+ "foot_sway_px", "foot_x", "frames", "h", "kind", "loop", "motion_anchor", "scale", "state", "subsampled",+ "top_margin_px", "w"}+CYCLE_ALIGN_KEYS_2350 = {"between", "cycle_screen", "cycles_given", "drawings", "foot_why", "fps", "from", "made_at",+ "made_by_rife", "nearest_at", "reach_swing", "retake", "seam_ratio", "source", "start_foot",+ "start_foot_source", "stride_swing", "strikes", "taken", "to", "turned_by", "turned_on", "view"}+++def test_cycle_align_writes_a_loop_without_a_held_part_as_before(tmp_path):+ src = tmp_path / "src"+ _cut(src, _keyed(src, staff=False))+ dirs = []+ for name in ("a", "b"):+ shutil.copytree(src / "out", tmp_path / name)+ dirs.append(tmp_path / name)+ out = align.align_set(dirs, between="nearest")+ assert all("cycles_kept" not in row for row in out["loops"])+ for d in dirs:+ meta = json.loads((d / "loop.strip.json").read_text())+ assert set(meta) == STRIP_KEYS_2350 and set(meta["cycle_align"]) == CYCLE_ALIGN_KEYS_2350