Add federation milestones: scrobble-count, artist-plays, top-10 entries
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 15s
CI / federation-interop (push) Successful in 1m1s
CI / test (push) Successful in 3m7s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Failing after 2m31s
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 15s
CI / federation-interop (push) Successful in 1m1s
CI / test (push) Successful in 3m7s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Failing after 2m31s
Adds publishing/milestones.py: one post per check, in priority order (scrobble count > top-10 entry > artist plays), each threshold marked done the first time it's reached so it's never posted twice. A live scrobble queues a per-user FederationPendingCheck row (collapsing repeats so the event receiver stays fast); the new federation.milestones worker task drains it, requeuing to the back of the queue on failure rather than retrying immediately, since a milestone check is a pure DB read with no external server to fail against. Enabling sharing, and finishing an import, call set_baseline() instead of a live check: every threshold already passed is marked done without posting, so history already on file never produces a burst of retroactive "milestone" posts. Wired into sharing.update()'s enable-toggle branch with a local import, mirroring farewell_user()'s existing precedent for the same sharing<->federation-internals circularity. A top-10 entry now requires the user to actually have TOP_N distinct artists first - caught by a test with unpatched thresholds, where every first play of a new artist was trivially "entering an empty top 10". Fixes test_federation_boundary.py's off-means-off check: blinker signals are process-wide, so once any app in the test process enables federation the milestone receivers stay connected for the rest of the run regardless of which app is "current" - there's no per-app scoping to introspect. Replaced the receiver-absence assertion with a behavioural one (firing an event through the off app's own context is a no-op), and kept the existing per-app-scoped view/worker checks as they were. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
0766c09fb3
commit
c3a8233e73
5 files changed
+603
-4
No files matched your search
@@ -16,6 +16,7 @@ import pytest
|
||||
|
||||
from scrobbler import create_app, events, worker
|
||||
from scrobbler.config import TestConfig
|
||||
from scrobbler.extensions import db
|
||||
from scrobbler.federation.config import FederationConfigError
|
||||
|
||||
SRC = Path(__file__).resolve().parents[1] / "src"
|
||||
@@ -165,11 +166,26 @@ def test_nothing_is_registered_when_federation_is_off(app):
|
||||
assert app.extensions["federation"].enabled is False
|
||||
views = [view for view in app.view_functions.values() if _from_federation(view)]
|
||||
assert views == []
|
||||
for signal in (events.scrobbles_stored, events.now_playing_changed, events.import_finished):
|
||||
assert not any(_from_federation(r) for r in signal.receivers_for(None))
|
||||
assert not any(name.startswith("federation") for name in worker.registered(app))
|
||||
|
||||
|
||||
def test_federation_event_receivers_are_no_ops_when_this_app_is_off(app, make_user):
|
||||
"""Receivers connect to blinker's process-wide signals, which have no notion of
|
||||
"app": once any app in this test process enables federation (fed_app, or the
|
||||
create_app(_Enabled) calls below), the signal keeps those receivers connected for
|
||||
the rest of the run, whatever this test's own `app` says. So "off" can't be shown by
|
||||
an absence of receivers — it's enforced by each receiver checking *this app's own*
|
||||
config at call time. Firing an event inside this off app's context must therefore
|
||||
still be a no-op, whatever else has already run in the process."""
|
||||
from scrobbler.federation.models import FederationPendingCheck
|
||||
|
||||
assert app.extensions["federation"].enabled is False
|
||||
user = make_user()
|
||||
events.send(events.scrobbles_stored, user, scrobbles=["placeholder"], source="scrobble")
|
||||
events.send(events.import_finished, user, job=None)
|
||||
assert db.session.get(FederationPendingCheck, user.id) is None
|
||||
|
||||
|
||||
class _Enabled(TestConfig):
|
||||
FEDERATION_ENABLED = "1"
|
||||
FEDERATION_DOMAIN = "scrobble.example"
|
||||
|
||||
Reference in new issue
Block a user