clipwright/tests/test_bridge.py

101 lines
4.1 KiB
Python

"""Shorts -> long-form bridge copy (PLAN #6): pure, deterministic generation.
The bridge is derived from the active profile (+ its ``published_video_history``)
and the clip, with an optional explicit target. No LLM, no network: the same
inputs must always yield the same copy.
"""
import pytest
from clipwright.pipeline import bridge, profiles
TARGET = "https://www.youtube.com/watch?v=LONGFORM123"
@pytest.fixture(scope="module")
def cseea():
return profiles.load_profile("cseea")
def _clip():
return {"video_title_for_youtube_short": "I broke the world",
"viral_hook_text": "I broke the world in one block"}
def test_explicit_target_reaches_every_field(cseea):
result = bridge.build_bridge(cseea, clip=_clip(), related_video_url=TARGET)
assert result["related_video_url"] == TARGET
assert TARGET in result["description_bridge"]
assert TARGET in result["first_comment"]
assert any(TARGET in step for step in result["checklist"])
assert result["manual_pin_required"] is True
def test_checklist_names_the_manual_studio_steps(cseea):
result = bridge.build_bridge(cseea, clip=_clip(), related_video_url=TARGET)
joined = "\n".join(result["checklist"])
assert "Studio" in joined
assert "Related video" in joined
assert "Pin" in joined
assert "no api" in joined.lower()
def test_no_target_uses_profile_links_and_invents_no_url(cseea):
result = bridge.build_bridge(cseea, clip=_clip(), related_video_url=None)
assert result["related_video_url"] is None
# The channel's own links still appear; no watch URL is fabricated.
assert "youtube.com/@cseea" in result["description_bridge"]
assert "youtube.com/@cseea" in result["first_comment"]
assert "watch?v=" not in result["description_bridge"]
# The checklist tells the operator to paste the target themselves.
assert any("paste" in step.lower() for step in result["checklist"])
def test_published_history_supplies_the_target_when_none_given():
profile = profiles.Profile(
slug="t",
description_template="{hook}\n\nFull video: {link}",
links=["https://example.com/channel"],
published_video_history=[
{"id": "OLD", "published_at": "2026-01-01"},
{"id": "NEW", "published_at": "2026-06-01"},
],
)
result = bridge.build_bridge(profile, clip=_clip())
assert result["related_video_url"] == "https://www.youtube.com/watch?v=NEW"
assert "watch?v=NEW" in result["first_comment"]
def test_explicit_target_wins_over_history_and_url_field_preferred():
profile = profiles.Profile(
slug="t",
published_video_history=[{"url": "https://youtu.be/HISTORY"}],
)
assert bridge.target_video(profile, TARGET) == TARGET
assert bridge.target_video(profile) == "https://youtu.be/HISTORY"
def test_profiles_produce_different_bridge_copy(cseea):
pedro = profiles.load_profile("pedro")
cseea_bridge = bridge.build_bridge(cseea, clip=_clip(), related_video_url=TARGET)
pedro_bridge = bridge.build_bridge(pedro, clip=_clip(), related_video_url=TARGET)
assert cseea_bridge["description_bridge"] != pedro_bridge["description_bridge"]
assert "#minecraft" in cseea_bridge["description_bridge"]
assert "Chapters and source" in pedro_bridge["description_bridge"]
def test_no_profile_still_produces_usable_copy():
result = bridge.build_bridge(None, clip=_clip(), related_video_url=TARGET)
assert TARGET in result["first_comment"]
assert TARGET in result["description_bridge"]
assert result["checklist"] # never empty
def test_bridge_fields_merge_into_clip_metadata(cseea):
"""The exact merge ``main.py`` performs must land every bridge field."""
clip = _clip()
clip.update(bridge.build_bridge(cseea, clip=clip, related_video_url=TARGET))
assert set(bridge.build_bridge(cseea, clip=clip).keys()) <= set(clip.keys())
assert clip["related_video_url"] == TARGET
assert isinstance(clip["checklist"], list)
assert isinstance(clip["description_bridge"], str) and clip["description_bridge"]
assert isinstance(clip["first_comment"], str) and clip["first_comment"]