Files
momentum-system/tests/unit/test_youtube_playlists.py
T
momentum devandClaude Fable 5 92488b72bc youtube: YT_PLAYLIST_URLS — comma-separated playlists via env, synced at boot
One playlist per add-playlist CLI call made adding a second playlist a chore.
Now YT_PLAYLIST_URLS takes a comma-separated list of playlist URLs (list=
param extracted) or bare ids; the transcripts service seeds the playlists
table from it at boot (insert-if-missing — hand-set labels are never
clobbered), and `python -m youtube_claims.run sync-playlists` does the same
on demand. Documented in both compose files; 3 tests.

Also: queue the two executor-surfaced defects (OrderFilledEvent side,
/api/attribution env hardcode) + the flaky nightly regime build-features
step in the plans index; regime_features 07-16 backfilled supervised.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 09:14:22 -05:00

35 lines
1.4 KiB
Python

"""YT_PLAYLIST_URLS parsing + boot sync — playlists come from ONE comma-separated
env var (URLs or bare ids) instead of one add-playlist CLI call each, so adding a
second playlist is editing one line of .env. Sync must never clobber a label the
owner set by hand (insert-if-missing, not upsert)."""
from youtube_claims import config
def test_playlist_urls_parses_urls_and_bare_ids(monkeypatch):
monkeypatch.setenv(
"YT_PLAYLIST_URLS",
"https://www.youtube.com/playlist?list=PLabc123 , "
"https://youtube.com/watch?v=xyz&list=PLdef456&index=2, "
"PLghi789",
)
assert config.playlist_urls() == ["PLabc123", "PLdef456", "PLghi789"]
def test_playlist_urls_empty_and_junk(monkeypatch):
monkeypatch.setenv("YT_PLAYLIST_URLS", " , https://youtube.com/watch?v=noList , ")
assert config.playlist_urls() == [] # a URL with no list= param is not a playlist
monkeypatch.delenv("YT_PLAYLIST_URLS", raising=False)
assert config.playlist_urls() == []
def test_sync_env_playlists_inserts_without_clobbering(monkeypatch):
from youtube_claims import run as run_mod
monkeypatch.setenv("YT_PLAYLIST_URLS", "PLnew1, https://www.youtube.com/playlist?list=PLnew2")
calls = []
monkeypatch.setattr(run_mod.db, "ensure_playlist", lambda pid, label: calls.append((pid, label)))
n = run_mod.sync_env_playlists()
assert n == 2
assert calls == [("PLnew1", "PLnew1"), ("PLnew2", "PLnew2")]