Skip to content

Open-source AI podcast clipper. Generate vertical clips with face tracking and burned-in captions. CLI, MCP server, web app.

Expand highlight-reel test coverage

Nika Siradze8f5877da57ca
diff --git a/tests/test_reel.py b/tests/test_reel.py
index 9ad6663..643655b 100644
--- a/tests/test_reel.py
+++ b/tests/test_reel.py
@@ -1,8 +1,11 @@
"""Tests for backend.services.reel session + edit logic (no video/render)."""
import os
+import shutil
import sys
+import tempfile
import unittest
+from unittest import mock
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
BACKEND_ROOT = os.path.join(ROOT, "backend")
@@ -73,6 +76,28 @@ class EditTests(unittest.TestCase):
self.assertFalse(self.s.moments[0].enabled)
self.assertEqual(len(self.s.moments), 2)
+ def test_set_absolute_bounds(self):
+ R.edit_moment(self.s, 1, "set", start=90.5, end=110.4)
+ m = self.s.moments[0]
+ self.assertEqual((m.start, m.end), (90.5, 110.4))
+ self.assertTrue(m.dirty)
+
+ def test_set_start_only_keeps_end(self):
+ R.edit_moment(self.s, 1, "set", start=95.0)
+ self.assertEqual((self.s.moments[0].start, self.s.moments[0].end), (95.0, 120.0))
+
+ def test_set_end_only_keeps_start(self):
+ R.edit_moment(self.s, 1, "set", end=140.0)
+ self.assertEqual((self.s.moments[0].start, self.s.moments[0].end), (100.0, 140.0))
+
+ def test_set_clamps_negative_start(self):
+ R.edit_moment(self.s, 1, "set", start=-5.0)
+ self.assertEqual(self.s.moments[0].start, 0.0)
+
+ def test_set_keeps_end_above_start(self):
+ R.edit_moment(self.s, 1, "set", start=118.0, end=100.0)
+ self.assertGreater(self.s.moments[0].end, self.s.moments[0].start)
+
def test_bad_index_raises(self):
with self.assertRaises(IndexError):
R.edit_moment(self.s, 99, "longer", 5)
@@ -118,6 +143,91 @@ class FormatTests(unittest.TestCase):
vf = R._scale_filter("square")
self.assertIn("crop=1080:1080", vf)
+ def test_unknown_format_falls_back(self):
+ self.assertIn("1080:1920", R._scale_filter("bogus"))
+
+
+class SeedSessionTests(unittest.TestCase):
+ def tearDown(self):
+ p = R.session_path("seed_test")
+ if os.path.exists(p):
+ os.remove(p)
+
+ def test_builds_moments_and_stores_format(self):
+ clips = [{"start_second": 10.24, "end_second": 25.71, "reasons": ["laughter"]}]
+ with mock.patch("services.saliency.detect_highlights", return_value=clips):
+ s = R.seed_session("seed_test", "/tmp/v.mp4", "/tmp/o", format="vertical", top_n=5)
+ self.assertEqual(s.format, "vertical")
+ self.assertEqual(len(s.moments), 1)
+ self.assertEqual((s.moments[0].start, s.moments[0].end), (10.2, 25.7))
+ self.assertEqual(s.moments[0].why, "laughter")
+
+ def test_unknown_format_normalized_on_seed(self):
+ with mock.patch("services.saliency.detect_highlights", return_value=[]):
+ s = R.seed_session("seed_test", "/tmp/v.mp4", "/tmp/o", format="bogus")
+ self.assertEqual(s.format, "vertical")
+
+
+class BuildReelTests(unittest.TestCase):
+ def setUp(self):
+ self.dir = tempfile.mkdtemp()
+ self.s = R.ReelSession(
+ "build_test", "/tmp/src.mp4", "auto", self.dir, format="vertical",
+ moments=[R.Moment(10.0, 20.0, "x", "a"), R.Moment(30.0, 45.0, "y", "b")],
+ )
+
+ def tearDown(self):
+ shutil.rmtree(self.dir, ignore_errors=True)
+ p = R.session_path("build_test")
+ if os.path.exists(p):
+ os.remove(p)
+
+ def _build(self):
+ with mock.patch.object(R, "proc_run", return_value=mock.Mock(returncode=0)) as pr:
+ R.build_reel(self.s)
+ return pr
+
+ @staticmethod
+ def _cut_calls(pr):
+ return [c for c in pr.call_args_list if "-vf" in c.args[0]]
+
+ def test_cut_uses_session_format_dimensions(self):
+ pr = self._build()
+ cuts = self._cut_calls(pr)
+ self.assertEqual(len(cuts), 2)
+ for c in cuts:
+ argv = c.args[0]
+ vf = argv[argv.index("-vf") + 1]
+ self.assertIn("1080:1920", vf)
+
+ def test_clean_existing_clips_are_reused(self):
+ clips = os.path.join(self.dir, "clips")
+ os.makedirs(clips, exist_ok=True)
+ for i in (1, 2):
+ open(os.path.join(clips, f"clip_{i:02d}.mp4"), "w").close()
+ for m in self.s.moments:
+ m.dirty = False
+ pr = self._build()
+ self.assertEqual(self._cut_calls(pr), [])
+
+ def test_only_enabled_moments_reach_the_concat(self):
+ self.s.moments[0].enabled = False
+ self._build()
+ with open(os.path.join(self.dir, "_concat.txt")) as f:
+ lines = [ln for ln in f if ln.strip()]
+ self.assertEqual(len(lines), 1)
+
+ def test_drop_then_build_recuts_shifted_moment(self):
+ clips = os.path.join(self.dir, "clips")
+ os.makedirs(clips, exist_ok=True)
+ for i in (1, 2):
+ open(os.path.join(clips, f"clip_{i:02d}.mp4"), "w").close()
+ for m in self.s.moments:
+ m.dirty = False
+ R.edit_moment(self.s, 1, "drop")
+ pr = self._build()
+ self.assertEqual(len(self._cut_calls(pr)), 1)
+
class SessionRegistryTests(unittest.TestCase):
_ids = ("registry_a", "registry_b")
diff --git a/tests/test_saliency.py b/tests/test_saliency.py
index 8734ec7..8ed1e3f 100644
--- a/tests/test_saliency.py
+++ b/tests/test_saliency.py
@@ -75,6 +75,22 @@ class FuseChannelsTests(unittest.TestCase):
self.assertTrue(np.allclose(fused, 0.0))
+class ProfileTests(unittest.TestCase):
+ def test_auto_is_a_saliency_profile(self):
+ p = get_profile("auto")
+ self.assertEqual(p.name, "auto")
+ self.assertEqual(p.candidate_source, "saliency")
+
+ def test_auto_fuses_multiple_channels(self):
+ # auto blends audio_event, energy and motion, so any one can drive a peak
+ channels = {"motion": np.array([0.0, 0.0, 5.0]), "energy": np.array([1.0, 1.0, 1.0])}
+ fused = sal.fuse_channels(channels, get_profile("auto"))
+ self.assertEqual(int(np.argmax(fused)), 2)
+
+ def test_unknown_profile_falls_back(self):
+ self.assertEqual(get_profile("nonsense").name, "podcast")
+
+
class WindowForPeakTests(unittest.TestCase):
def setUp(self):
self.energy_flat = np.zeros(200)