import os, sys, unittest
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import vlib as V

class TestSyncEnd(unittest.TestCase):
    def test_scattered_orange_no_cap(self):
        clips = [
            {"startFrame": 0, "durationFrames": 100, "orange": True},
            {"startFrame": 5000, "durationFrames": 100, "orange": True},
            {"startFrame": 100000, "durationFrames": 5000, "orange": False},
        ]
        end = V.derive_sync_end(clips, end_fallback=999)
        self.assertEqual(end, 999)

    def test_big_orange_block(self):
        # contiguous orange starts spanning >= 30s of startFrames
        clips = [{"startFrame": i*100, "durationFrames": 50, "orange": True} for i in range(20)]  # 0..1900
        clips.append({"startFrame": 50000, "durationFrames": 1000, "orange": False})
        end = V.derive_sync_end(clips, end_fallback=999999)
        self.assertEqual(end, 0)  # big block from 0

if __name__ == "__main__":
    unittest.main(verbosity=2)
