Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
test(out-dir): what a verb writes is judged at the path it writes, a link already there included — correction-loop given an attempt, candidate, best candidate, attempt file or report that is a link to the run or into it keeps the run byte for byte and refuses before anything is made, and loops into its own default out dir twice; video-loop-compare, video-loop-repair, video-source-manifest and shadow given an output spelt in capitals of an input keep it; video-extend and video-edit given a <out>.part linked to the clip, or --report naming it, keep it (red)
Soohong Kimd61948a10506
diff --git a/tests/conftest.py b/tests/conftest.pyindex 99a3fdb..ab74867 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -78,6 +78,10 @@ NOT_RIFE_SKIPS = {"tests/gen/test_video_modes.py::test_the_result_is_never_published_over_the_clip_it_is_made_from[extend-capitals]","tests/gen/test_video_modes.py::test_the_result_is_never_published_over_the_clip_it_is_made_from[edit-capitals]","tests/video/test_follow_inspect.py::test_the_loop_directory_spelt_in_capitals_is_the_loop_directory",+ "tests/video/test_loop_compare.py::test_a_report_spelt_in_capitals_of_an_input_is_refused",+ "tests/video/test_source_restoration.py::test_a_report_spelt_in_capitals_of_an_input_is_refused",+ "tests/video/test_source_restoration.py::test_a_manifest_spelt_in_capitals_of_an_input_is_refused",+ "tests/effects/test_shadow.py::test_an_output_spelt_in_capitals_of_the_source_is_refused",}diff --git a/tests/effects/test_shadow.py b/tests/effects/test_shadow.pyindex bcbb249..e3cd2d8 100644--- a/tests/effects/test_shadow.py+++ b/tests/effects/test_shadow.py@@ -280,6 +280,23 @@ def test_outputs_cannot_overwrite_input_files(tmp_path, filename):assert {path: path.read_bytes() for path in tmp_path.iterdir()} == before+def test_an_output_spelt_in_capitals_of_the_source_is_refused(tmp_path):+ """On a volume that ignores case `SHADOW.png` is `shadow.png`: a source so named is the strip the run writes."""+ source = tmp_path / "SHADOW.png"+ _silhouette().save(source)+ if not (tmp_path / "shadow.png").exists():+ pytest.skip("대소문자를 가리는 볼륨 — 철자가 다르면 다른 파일이다")+ before = {path.name: path.read_bytes() for path in tmp_path.iterdir()}+ try:+ shadow.run(source=source, out_dir=tmp_path)+ said = "written"+ except ValueError as refusal:+ said = str(refusal)+ assert source.read_bytes() == before["SHADOW.png"], f"그림자가 대문자 철자의 원본 위에 써졌다 ({said})"+ assert "--source and shadow.png in --out-dir are the same file" in said, said+ assert {path.name: path.read_bytes() for path in tmp_path.iterdir()} == before++def test_output_cannot_overwrite_a_frame_referenced_by_descriptor(tmp_path):source = _asset_files(tmp_path)data = json.loads(source.read_text())diff --git a/tests/gen/test_video_modes.py b/tests/gen/test_video_modes.pyindex ae63318..a4e3150 100644--- a/tests/gen/test_video_modes.py+++ b/tests/gen/test_video_modes.py@@ -297,6 +297,51 @@ def test_the_result_is_never_published_over_the_clip_it_is_made_from(tmp_path: Passert api.calls == [][email protected]("verb", ["extend", "edit"])+def test_the_download_is_never_staged_through_a_link_to_the_clip(tmp_path: Path, verb: str) -> None:+ """The result is downloaded to `<out>.part` before it is published over `--out`: a `<out>.part` already there as a+ link to the input clip is refused before any call — the download would be written through it, over the clip."""+ given = MP4 + b"the input clip"+ api = _FakeApi(done={"status": "done", "video": {"url": "https://vidgen.x.ai/v/5.mp4", "duration": 5}, "model": "grok-imagine-video"})+ clip, out = tmp_path / "take.mp4", tmp_path / "result.mp4"+ request = _ext(tmp_path, video=clip, out=out) if verb == "extend" else _edit(tmp_path, video=clip, out=out)+ _clip(tmp_path, "take.mp4", given)+ (tmp_path / "result.mp4.part").symlink_to(clip)+ make = video.extend_video if verb == "extend" else video.edit_video+ try:+ make(request, probe=_probe(5.0, 10.0), **api.kw())+ said = "published"+ except SystemExit as refusal:+ said = str(refusal)+ assert clip.read_bytes() == given, f"video-{verb} 이 <out>.part 링크를 지나 입력 클립 위에 내려받았다 ({said}, calls {len(api.calls)})"+ assert re.search(rf"video-{verb}: --video and result\.mp4\.part beside --out are the same file", said), said+ assert api.calls == []++[email protected]("verb", ["extend", "edit"])+def test_the_report_is_never_written_over_the_clip_it_is_made_from(tmp_path: Path, monkeypatch, verb: str) -> None:+ """`--report` naming the input clip is refused before any call: the report is written once the result is made, and+ would replace the clip."""+ given = MP4 + b"the input clip"+ api = _FakeApi(done={"status": "done", "video": {"url": "https://vidgen.x.ai/v/6.mp4", "duration": 5}, "model": "grok-imagine-video"})+ monkeypatch.setattr(video, "resolve_credential", lambda **_: CRED)+ monkeypatch.setattr(video, "http_json", api.call)+ monkeypatch.setattr(video, "http_download", api.download)+ monkeypatch.setattr(video.time, "sleep", lambda s: None)+ monkeypatch.setattr(video, "probe_duration_seconds", lambda clip, *, verb: 11.0 if clip.name.endswith(".part") else 6.0)+ clip = _clip(tmp_path, "take.mp4", given)+ run = video.run_extend if verb == "extend" else video.run_edit+ try:+ run(video=clip, prompt="go on", prompt_file=None, out=tmp_path / "result.mp4", report=clip,+ **({"duration": 5} if verb == "extend" else {}))+ said = "written"+ except SystemExit as refusal:+ said = str(refusal)+ assert clip.read_bytes() == given, f"video-{verb} 이 입력 클립 위에 보고서를 썼다 ({said}, calls {len(api.calls)})"+ assert re.search(rf"video-{verb}: --video and --report are the same file", said), said+ assert api.calls == []++def test_edit_accepts_exactly_the_limit(tmp_path: Path) -> None:api = _FakeApi()video.edit_video(_edit(tmp_path), probe=lambda clip: 8.7, **api.kw())diff --git a/tests/qa/test_correction_loop_inputs_kept.py b/tests/qa/test_correction_loop_inputs_kept.pyindex e10cceb..9eb9eff 100644--- a/tests/qa/test_correction_loop_inputs_kept.py+++ b/tests/qa/test_correction_loop_inputs_kept.py@@ -2,16 +2,21 @@"""`correction-loop` 이 읽는 런을 지키는 계약 — 출력 폴더가 런과 겹치는 배치.지키는 것 (구현이 아니라 계약):- 1. 런 폴더(`--run-dir`)와 최선 후보의 복사가 따라가는 링크 하나하나(그 경로가 지나는 링크와 폴더까지)가- `--out-dir` 와 같거나 그 안에 들면 아무것도 만들기 전에 거절한다 — 루프는 거기에 시도와 최선 후보를 쓰고- 옛 최선 후보를 지운다+ 1. 런 폴더(`--run-dir`)와 최선 후보의 복사가 그 안에서 읽는 파일·폴더·링크 하나하나(그 경로가 지나는 링크와+ 폴더까지)가 루프가 쓰는 것 — `--out-dir`, 그 안의 시도 폴더와 그 파일, 공급자가 만드는 후보, 최선 후보,+ 보고서 — 과 같거나 그 안에 들면 아무것도 만들기 전에 거절한다. 쓰는 자리마다 그 이름으로 본다: 그 자리에+ 이미 있는 링크가 런이나 런 안으로 가도 같은 항목이다2. `--out-dir` 가 런 폴더 안이면(기본값 `<run-dir>/correction-loop`) 루프는 거기에 더할 뿐이고, 최선 후보의- 복사는 그 폴더를 빼고 런만 복사한다 — 제 출력을 제 안에 복사하지 않는다+ 복사는 그 폴더를 빼고 런만 복사한다 — 제 출력을 제 안에 복사하지 않는다. 그 폴더에 앞선 루프가 남긴 것이+ 있어도 같다"""from __future__ import annotationsimport re+import shlex+import shutil+import sysfrom pathlib import Pathimport pytest@@ -53,7 +58,43 @@ def _a_link_in_the_run_into_the_best_candidate(root: Path, run: Path):return run, root / "loop", r"notes\.txt in --run-dir lies inside --out-dir"-OVERLAPS = [_run_is_the_best_candidate, _run_is_the_out_dir, _a_link_in_the_run_into_the_best_candidate]+def _an_attempt_linked_to_the_run(root: Path, run: Path):+ (run / "inspect.json").write_bytes(b'{"sentinel":"the original input report"}\n')+ (root / "loop").mkdir()+ (root / "loop" / "attempt-1").symlink_to(run, target_is_directory=True)+ return run, root / "loop", r"--run-dir and attempt-1 in --out-dir are the same folder"+++def _an_attempt_linked_into_the_run(root: Path, run: Path):+ (run / "old-loop" / "attempt-1").mkdir(parents=True)+ (run / "old-loop" / "attempt-1" / "inspect.json").write_bytes(b'{"sentinel":"an earlier loop kept in the run"}\n')+ (root / "loop").mkdir()+ (root / "loop" / "attempt-1").symlink_to(run / "old-loop" / "attempt-1", target_is_directory=True)+ return run, root / "loop", r"old-loop/attempt-1 in --run-dir and attempt-1 in --out-dir are the same folder"+++def _the_best_candidate_linked_into_the_run(root: Path, run: Path):+ (root / "loop").mkdir()+ (root / "loop" / "best-candidate").symlink_to(run / "raw", target_is_directory=True)+ return run, root / "loop", r"raw in --run-dir and best-candidate in --out-dir are the same folder"+++def _an_attempt_file_linked_to_a_run_file(root: Path, run: Path):+ (root / "loop" / "attempt-1").mkdir(parents=True)+ (root / "loop" / "attempt-1" / "score.json").symlink_to(run / "sprite-request.json")+ return run, root / "loop", r"sprite-request\.json in --run-dir and attempt-1/score\.json in --out-dir are the same file"+++def _the_report_linked_to_a_run_file(root: Path, run: Path):+ (root / "loop").mkdir()+ (root / "loop" / "correction-loop.report.json").symlink_to(run / "sprite-request.json")+ return (run, root / "loop",+ r"sprite-request\.json in --run-dir and correction-loop\.report\.json in --out-dir are the same file")+++OVERLAPS = [_run_is_the_best_candidate, _run_is_the_out_dir, _a_link_in_the_run_into_the_best_candidate,+ _an_attempt_linked_to_the_run, _an_attempt_linked_into_the_run, _the_best_candidate_linked_into_the_run,+ _an_attempt_file_linked_to_a_run_file, _the_report_linked_to_a_run_file]@pytest.mark.parametrize("layout", OVERLAPS, ids=[layout.__name__.strip("_") for layout in OVERLAPS])@@ -66,6 +107,28 @@ def test_the_loop_never_writes_over_or_deletes_the_run_it_reads(tmp_path, fixturassert _state(tmp_path) == before, f"거절했는데 무엇이 생기거나 바뀌었다 ({said})"+def test_a_candidate_the_provider_would_make_over_the_run_is_refused_before_it_runs(tmp_path, fixture_run_dir) -> None:+ """공급자는 다음 후보를 루프가 정한 자리(`--out-dir` 의 `candidate-<n>`)에 만든다 — 그 자리가 런으로 가는 링크면+ 공급자가 읽는 런 위에 쓴다: 공급자를 부르기 전에, 아무것도 만들기 전에 거절한다."""+ made = tmp_path / "made" # 공급자가 내놓는 런 — 원래 런과 바이트가 다르다+ shutil.copytree(fixture_run_dir, made)+ (made / "raw" / "idle.png").write_bytes((made / "raw" / "walk.png").read_bytes())+ (tmp_path / "loop").mkdir()+ (tmp_path / "loop" / "candidate-2").symlink_to(fixture_run_dir, target_is_directory=True)+ provider = shlex.join([sys.executable, "-c", "import shutil, sys; shutil.copytree(sys.argv[1], sys.argv[2], dirs_exist_ok=True)",+ str(made), "{next_run_dir}"])+ read, before = _readable(fixture_run_dir), _state(tmp_path)+ try:+ result = run_loop(fixture_run_dir, states="walk", out_dir=tmp_path / "loop", max_passes=2, pass_score=1000.0,+ provider_command=provider)+ said = f"rc=0, best {result['preserved_best']}"+ except (SystemExit, OSError) as stopped:+ said = f"{type(stopped).__name__}: {str(stopped)[:300]}"+ assert _readable(fixture_run_dir) == read, f"공급자가 루프가 읽는 런 위에 후보를 썼다 ({said})"+ assert re.search(r"--run-dir and candidate-2 in --out-dir are the same folder", said), f"런으로 가는 후보 자리를 거절하지 않았다 ({said})"+ assert _state(tmp_path) == before, f"거절했는데 무엇이 생기거나 바뀌었다 ({said})"++# ── 2. 기본 out 은 런 안 — 더할 뿐, 복사는 그 폴더를 뺀다 ──────────────────────────def test_the_default_out_dir_inside_the_run_is_left_out_of_the_best_candidates_copy(fixture_run_dir) -> None:@@ -76,3 +139,14 @@ def test_the_default_out_dir_inside_the_run_is_left_out_of_the_best_candidates_cassert _readable(best) == read, "최선 후보가 런 그대로가 아니다 — 제 출력을 제 안에 복사했다"kept = {name: data for name, data in _readable(fixture_run_dir).items() if not name.startswith("correction-loop/")}assert kept == read, "런의 원래 파일이 바뀌었다"+++def test_a_second_loop_into_the_default_out_dir_is_the_loops_own(fixture_run_dir) -> None:+ """앞선 루프의 시도·최선 후보·보고서가 이미 있는 기본 out 은 루프 제 것이다 — 두 번째 루프도 거절하지 않고,+ 최선 후보는 여전히 런 그대로다."""+ read = _readable(fixture_run_dir)+ first, second = _loop(fixture_run_dir, None), _loop(fixture_run_dir, None)+ assert first.startswith("rc=0") and second.startswith("rc=0"), f"기본 out 으로 다시 돌지 못했다 ({first} / {second})"+ assert _readable(fixture_run_dir / "correction-loop" / "best-candidate") == read, "두 번째 최선 후보가 런 그대로가 아니다"+ kept = {name: data for name, data in _readable(fixture_run_dir).items() if not name.startswith("correction-loop/")}+ assert kept == read, "런의 원래 파일이 바뀌었다"diff --git a/tests/video/test_loop_compare.py b/tests/video/test_loop_compare.pyindex 3af3870..b666761 100644--- a/tests/video/test_loop_compare.py+++ b/tests/video/test_loop_compare.py@@ -169,6 +169,27 @@ def test_cli_writes_unknown_successfully_and_refuses_corrupt_input_or_overwrite(main(args + ["--report", str(output)])+def test_a_report_spelt_in_capitals_of_an_input_is_refused(tmp_path):+ """On a volume that ignores case `STRIP.JSON` is `strip.json`: a report so named is the input it would replace."""+ a, b = _artifact(tmp_path, "a"), _artifact(tmp_path, "b")+ _edit(b["report"], lambda d: d.pop("source"))+ args = ["video-loop-compare"]+ for side, paths in (("baseline", a), ("candidate", b)):+ for key, path in paths.items():+ args.extend([f"--{side}-{key}", str(path)])+ report = a["meta"].with_name(a["meta"].name.upper())+ if not report.exists():+ pytest.skip("대소문자를 가리는 볼륨 — 철자가 다르면 다른 파일이다")+ kept = hashlib.sha256(a["meta"].read_bytes()).hexdigest()+ try:+ main(args + ["--report", str(report)])+ said = "written"+ except SystemExit as refusal:+ said = str(refusal)+ assert hashlib.sha256(a["meta"].read_bytes()).hexdigest() == kept, f"비교 보고서가 대문자 철자의 입력 위에 써졌다 ({said})"+ assert "video-loop-compare: --baseline-meta and --report are the same file" in said, said++def test_gait_evidence_is_observation_for_fixed_and_automatic(tmp_path):for kind in ("fixed", "periodic"):r = evidence.gait_observation(_frames(), {"start": 0, "length": 12, "kind": kind})diff --git a/tests/video/test_source_restoration.py b/tests/video/test_source_restoration.pyindex a76e2d5..aea5b45 100644--- a/tests/video/test_source_restoration.py+++ b/tests/video/test_source_restoration.py@@ -606,6 +606,43 @@ def test_overwriting_any_input_is_refused(case,tmp_path):assert paths['meta'].read_bytes()==old and not (tmp_path/'unsafe').exists()+def test_a_report_spelt_in_capitals_of_an_input_is_refused(case,tmp_path):+ """On a volume that ignores case `B.JSON` is `b.json`: a repair report so named is the input it would replace."""+ paths,_,_=case+ baseline,origin,src=cli_args(case)+ spelt=paths['meta'].with_name(paths['meta'].name.upper())+ if not spelt.exists():+ pytest.skip('대소문자를 가리는 볼륨 — 철자가 다르면 다른 파일이다')+ old=evidence.digest(paths['meta'].read_bytes())+ try:+ main(['video-loop-repair',*baseline,*origin,*src,'--out-dir',str(tmp_path/'unsafe'),'--report',str(spelt)])+ said='written'+ except SystemExit as refusal:+ said=str(refusal)+ assert evidence.digest(paths['meta'].read_bytes())==old, f'수리 보고서가 대문자 철자의 입력 위에 써졌다 ({said})'+ assert 'video-loop-repair: --baseline-meta and --report are the same file' in said, said+ assert not (tmp_path/'unsafe').exists()+++def test_a_manifest_spelt_in_capitals_of_an_input_is_refused(case,tmp_path):+ """On a volume that ignores case `FRAMES.JSON` is `frames.json`: a source manifest so named is the frames report it+ reads."""+ _,inputs,_=case+ freport=inputs['source_frames_report']+ spelt=freport.with_name(freport.name.upper())+ if not spelt.exists():+ pytest.skip('대소문자를 가리는 볼륨 — 철자가 다르면 다른 파일이다')+ old=evidence.digest(freport.read_bytes())+ try:+ main(['video-source-manifest','--clip',str(inputs['source_clip']),'--canvas',str(inputs['source_canvas']),+ '--frames-report',str(freport),'--frames-dir',str(inputs['source_frames_dir']),'--out',str(spelt)])+ said='written'+ except SystemExit as refusal:+ said=str(refusal)+ assert evidence.digest(freport.read_bytes())==old, f'원천 매니페스트가 대문자 철자의 입력 위에 써졌다 ({said})'+ assert 'video-source-manifest: --frames-report and --out are the same file' in said, said++def test_legacy_ambiguous_projection_cannot_choose_one_crop():# Severe downscaling erases differences between several integer crops.# A single best-looking crop is insufficient evidence.