clipwright/tests/test_probe_plan.py
juancarlos.cavero 658defe614 fix(proxy): probe the duration over the static pool, not the per-GB proxy
The static ISP pool (dfa3124) moved downloads off the paid proxy but never
touched cloud/metering.py, so probe_url_minutes kept reading PROXY_URL alone.
Every managed YouTube submission still paid DataImpulse for 0.2-1 MB of yt-dlp
metadata (measured through a counting proxy) while the download itself went out
free over Decodo — and invisibly, because PROXY_BYTES only counts the bytes of
the winning download attempt.

The probe now walks the same cheapest-first chain as the download: direct when
DIRECT_FIRST=1, then the statics rotated per probe, then the paid proxy as the
last resort. Proxies are the outer loop and extractor strategies the inner one,
so the paid route is only reached after every free one has failed on both.
That also stops a drained paid proxy from taking YouTube ingest down on its own
("Could not determine the video duration") while the statics are healthy.

Two smaller cuts on the same path: a user with no minutes left now gets its 402
before the probe instead of after it, and a failed route no longer dumps a
yt-dlp ERROR block per proxy per strategy into the API log (the watcher is what
reports a dead route).
2026-08-21 22:45:53 +02:00

35 lines
1.1 KiB
Python

"""Duration-probe proxy ordering: cheapest bandwidth first.
The probe runs on every managed YouTube submission. It read PROXY_URL only
until 21-aug-2026, so it kept paying the per-GB proxy for metadata long after
downloads had moved to the flat-rate static pool — invisibly, because the
PROXY_BYTES counter only sees download bytes.
"""
import pytest
metering = pytest.importorskip("cloud.metering")
plan = metering.plan_probe_proxies
STATICS = ["http://s1", "http://s2", "http://s3"]
PAID = "http://paid"
class TestOrdering:
def test_full_chain(self):
assert plan(True, STATICS, PAID) == [None] + STATICS + [PAID]
def test_paid_is_last_resort(self):
got = plan(False, STATICS, PAID)
assert got == STATICS + [PAID]
assert got.index(PAID) == len(got) - 1
def test_statics_only_never_reaches_a_paid_proxy(self):
assert plan(False, STATICS, "") == STATICS
def test_selfhost_no_proxies_probes_direct(self):
assert plan(False, [], "") == [None]
assert plan(True, [], "") == [None]
def test_no_statics_matches_legacy_paid_only_behavior(self):
assert plan(False, [], PAID) == [PAID]