Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
143 lines
6.2 KiB
Python
143 lines
6.2 KiB
Python
"""Apps-shelf preview-loop rendering (2026-10-28): the real local-tool renders
|
|
that unhide ``transition``/``beat_cut``/``hook_score``/``remove_bg`` on the
|
|
shelf. Mirrors ``test_wp_pm1_2_presets_hub.py``'s ``preview_render`` coverage:
|
|
real ffmpeg/PIL output over synthetic sources, no network.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import shutil
|
|
import subprocess
|
|
|
|
import pytest
|
|
|
|
from app.domains.apps_shelf import preview_render
|
|
|
|
FFMPEG = shutil.which("ffmpeg")
|
|
REMBG_AVAILABLE = importlib.util.find_spec("rembg") is not None
|
|
|
|
|
|
def _probe(path: str) -> dict:
|
|
import json
|
|
|
|
out = subprocess.run(
|
|
["ffprobe", "-v", "error", "-show_entries", "format=duration:stream=width,height,codec_type",
|
|
"-of", "json", path],
|
|
capture_output=True, text=True, check=True,
|
|
)
|
|
return json.loads(out.stdout)
|
|
|
|
|
|
def _synthetic_video(path, *, size="540x960", seconds=9, rate=30) -> None:
|
|
subprocess.run(["ffmpeg", "-v", "error", "-y", "-f", "lavfi",
|
|
"-i", f"testsrc2=size={size}:rate={rate}:duration={seconds}",
|
|
"-f", "lavfi", "-i", f"sine=frequency=440:duration={seconds}",
|
|
"-pix_fmt", "yuv420p", "-shortest", str(path)], check=True, timeout=120)
|
|
|
|
|
|
def _synthetic_photo(path, *, size=(540, 960), color=(200, 120, 90)) -> None:
|
|
from PIL import Image
|
|
|
|
Image.new("RGB", size, color).save(path)
|
|
|
|
|
|
def _synthetic_tone(path, *, seconds=12) -> None:
|
|
subprocess.run(["ffmpeg", "-v", "error", "-y", "-f", "lavfi",
|
|
"-i", f"sine=frequency=440:beep_factor=4:duration={seconds}", str(path)], check=True, timeout=60)
|
|
|
|
|
|
pytestmark = pytest.mark.skipif(not FFMPEG, reason="ffmpeg not installed")
|
|
|
|
|
|
def test_render_transition_is_a_real_5s_loop(tmp_path):
|
|
first, second = tmp_path / "a.jpg", tmp_path / "b.jpg"
|
|
_synthetic_photo(first, color=(200, 120, 90))
|
|
_synthetic_photo(second, color=(60, 90, 160))
|
|
out_dir = tmp_path / "out"
|
|
entry = preview_render.render_transition(str(first), str(second), out_dir)
|
|
assert entry == {"loop": "presets/apps/transition.mp4", "poster": "presets/apps/transition.jpg"}
|
|
probe = _probe(str(out_dir / "transition.mp4"))
|
|
assert abs(float(probe["format"]["duration"]) - preview_render.runners.TRANSITION_SECONDS) < 0.3
|
|
assert (out_dir / "transition.jpg").is_file()
|
|
|
|
|
|
def test_render_beat_cut_snaps_to_real_beats(tmp_path):
|
|
clip, music = tmp_path / "clip.mp4", tmp_path / "music.wav"
|
|
_synthetic_video(clip, seconds=9)
|
|
_synthetic_tone(music, seconds=12)
|
|
out_dir = tmp_path / "out"
|
|
entry = preview_render.render_beat_cut(str(clip), str(music), out_dir)
|
|
assert entry == {"loop": "presets/apps/beat-cut.mp4", "poster": "presets/apps/beat-cut.jpg"}
|
|
out = out_dir / "beat-cut.mp4"
|
|
probe = _probe(str(out))
|
|
assert float(probe["format"]["duration"]) <= preview_render.runners.BEAT_CUT_MAX_S + 0.5
|
|
assert any(s["codec_type"] == "audio" for s in probe["streams"])
|
|
assert (out_dir / "beat-cut.jpg").is_file()
|
|
|
|
|
|
def test_render_hook_score_loops_the_real_clip_it_scores(tmp_path):
|
|
clip = tmp_path / "clip.mp4"
|
|
_synthetic_video(clip, seconds=9)
|
|
out_dir = tmp_path / "out"
|
|
entry = preview_render.render_hook_score(str(clip), out_dir)
|
|
assert entry == {"loop": "presets/apps/hook-score.mp4", "poster": "presets/apps/hook-score.jpg"}
|
|
out = out_dir / "hook-score.mp4"
|
|
probe = _probe(str(out))
|
|
assert abs(float(probe["format"]["duration"]) - preview_render.HOOK_SCORE_LOOP_SECONDS) < 0.3
|
|
assert not any(s["codec_type"] == "audio" for s in probe["streams"]) # muted, same as the preset-shelf loops
|
|
|
|
|
|
def test_flatten_cutout_composites_real_alpha_onto_the_backdrop(tmp_path):
|
|
from PIL import Image
|
|
|
|
cutout = tmp_path / "cutout.png"
|
|
rgba = Image.new("RGBA", (20, 20), (255, 0, 0, 0))
|
|
for x in range(10):
|
|
for y in range(20):
|
|
rgba.putpixel((x, y), (255, 0, 0, 255)) # opaque left half, transparent right half
|
|
rgba.save(cutout)
|
|
|
|
# Lossless destination: isolates the real compositing math from JPEG artifacts.
|
|
dest = tmp_path / "flat.png"
|
|
preview_render.flatten_cutout(str(cutout), str(dest), rgb=(10, 20, 30))
|
|
|
|
flat = Image.open(dest).convert("RGB")
|
|
assert flat.getpixel((2, 10)) == (255, 0, 0) # opaque side keeps the real cutout colour
|
|
assert flat.getpixel((17, 10)) == (10, 20, 30) # transparent side shows the real backdrop, exactly
|
|
|
|
|
|
@pytest.mark.skipif(not REMBG_AVAILABLE, reason="rembg not installed")
|
|
def test_render_remove_bg_end_to_end_with_a_real_rembg_cutout(tmp_path):
|
|
"""Real rembg session, real cutout, real crossfade — the same path production runs."""
|
|
photo = tmp_path / "photo.jpg"
|
|
_synthetic_photo(photo, color=(220, 200, 180))
|
|
out_dir = tmp_path / "out"
|
|
entry = preview_render.render_remove_bg(str(photo), out_dir)
|
|
assert entry == {"loop": "presets/apps/remove-background.mp4", "poster": "presets/apps/remove-background.jpg"}
|
|
out = out_dir / "remove-background.mp4"
|
|
assert out.is_file() and out.stat().st_size > 0
|
|
probe = _probe(str(out))
|
|
assert abs(float(probe["format"]["duration"]) - preview_render.runners.TRANSITION_SECONDS) < 0.3
|
|
assert (out_dir / "remove-background-cutout.png").is_file()
|
|
|
|
|
|
def test_render_dispatches_by_app_id(tmp_path, monkeypatch):
|
|
calls: list[str] = []
|
|
monkeypatch.setattr(preview_render, "render_transition", lambda *a, **k: calls.append("transition") or {})
|
|
monkeypatch.setattr(preview_render, "render_beat_cut", lambda *a, **k: calls.append("beat_cut") or {})
|
|
monkeypatch.setattr(preview_render, "render_hook_score", lambda *a, **k: calls.append("hook_score") or {})
|
|
monkeypatch.setattr(preview_render, "render_remove_bg", lambda *a, **k: calls.append("remove_bg") or {})
|
|
sources = tmp_path / "sources"
|
|
sources.mkdir()
|
|
for tool in preview_render.ZERO_DEP_TOOLS:
|
|
preview_render.render(tool, sources=sources, out_dir=tmp_path / "out")
|
|
assert calls == list(preview_render.ZERO_DEP_TOOLS)
|
|
|
|
|
|
def test_render_rejects_an_unknown_app_id(tmp_path):
|
|
# "expand" is now a real, supported image_edit renderer (Muse Image, live
|
|
# 2026-10-28) — use a genuinely unknown id to exercise the error path.
|
|
with pytest.raises(ValueError, match="no renderer"):
|
|
preview_render.render("not-a-real-app", sources=tmp_path, out_dir=tmp_path / "out")
|