Tests: lock the yt-dlp JS-runtime startup warning seam

Warns exactly once when deno is missing (naming the cryptic failure it
prevents users from having to debug), stays silent when deno is on PATH.
This commit is contained in:
BoulderBadgeDad 2026-06-06 16:52:52 -07:00
parent 303b09f1b5
commit 00e50c2fcb

View file

@ -0,0 +1,44 @@
"""Seam tests for the yt-dlp JS-runtime startup check.
YouTube gates downloadable formats behind JS challenges; without Deno on PATH
every stream / music-video download fails with the cryptic "Requested format
is not available". The check must say so plainly in the log — once — and stay
silent when deno is present.
"""
from __future__ import annotations
import core.youtube_client as yc
def _reset():
yc._JS_RUNTIME_WARNED = False
def _capture_warnings(monkeypatch):
calls = []
monkeypatch.setattr(yc.logger, 'warning', lambda msg, *a: calls.append(msg % a if a else msg))
return calls
def test_warns_once_when_deno_missing(monkeypatch):
_reset()
warnings = _capture_warnings(monkeypatch)
monkeypatch.setattr('shutil.which', lambda name: None)
yc._warn_if_no_js_runtime()
yc._warn_if_no_js_runtime() # second call must not duplicate
assert len(warnings) == 1
assert 'Requested format is not available' in warnings[0]
assert 'Deno' in warnings[0] or 'deno' in warnings[0]
def test_silent_when_deno_present(monkeypatch):
_reset()
warnings = _capture_warnings(monkeypatch)
monkeypatch.setattr('shutil.which', lambda name: '/usr/local/bin/deno' if name == 'deno' else None)
yc._warn_if_no_js_runtime()
assert warnings == []