E2: Migrate YouTube to declared rate-limit policy

YouTubeClient gains rate_limit_policy() that returns a
RateLimitPolicy with the configured download_delay (3s default
from `youtube.download_delay`). Engine reads this at
register_plugin time + applies to engine.worker.

set_engine still re-applies the delay so runtime reload_settings
updates flow through the same pathway. Other sources keep the
default policy (concurrency=1, delay=0) which matches their
current behavior — no migration needed beyond YouTube which is
the only source with a non-default download throttle today.

New pinning test asserts the policy shape (delay=3.0, concurrency=1).
Suite still green (2042 passed).
This commit is contained in:
Broque Thomas 2026-05-04 14:45:52 -07:00
parent a3929b457b
commit 1062589501
2 changed files with 26 additions and 1 deletions

View file

@ -125,10 +125,24 @@ class YouTubeClient:
# tests that bypass the orchestrator.
self._engine = None
def rate_limit_policy(self):
"""YouTube reads its download delay from user-tunable config
(``youtube.download_delay``, default 3s). Engine reads this
at ``register_plugin`` time, then ``set_engine`` runs and
re-applies if the config changed since instance construction."""
from core.download_engine import RateLimitPolicy
return RateLimitPolicy(
download_concurrency=1,
download_delay_seconds=float(self._download_delay),
)
def set_engine(self, engine):
"""Engine callback — gives the client access to the central
thread worker + state store. Engine calls this during
``register_plugin`` if the plugin defines it."""
``register_plugin`` if the plugin defines it. Worker delay
was already set from rate_limit_policy() re-apply here so
runtime ``reload_settings`` updates take effect via the
same pathway."""
self._engine = engine
engine.worker.set_delay('youtube', float(self._download_delay))

View file

@ -149,6 +149,17 @@ def test_set_engine_configures_worker_delay(yt_client_with_engine):
assert engine.worker._get_delay('youtube') == 3.0
def test_rate_limit_policy_reflects_configured_delay(yt_client_with_engine):
"""Pinning (Phase E): YouTube's rate_limit_policy() returns a
RateLimitPolicy with the configured download_delay (3s default
from `youtube.download_delay` config). Engine reads this at
register_plugin time."""
client, _ = yt_client_with_engine
policy = client.rate_limit_policy()
assert policy.download_delay_seconds == 3.0
assert policy.download_concurrency == 1
# ---------------------------------------------------------------------------
# Query / cancel — engine-backed reads
# ---------------------------------------------------------------------------