Update(Person) vocabulary and the live now-playing actor field (phase 4, step 2)
CI / validate-monitoring (push) Successful in 15s
CI / lint (push) Successful in 16s
CI / federation-interop (push) Successful in 1m47s
CI / test (push) Successful in 3m51s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s

vocab.update() wraps a document as an Update, addressed explicitly
(unlike undo(), which derives `to` from the undone activity - an actor
document has no `to` of its own).

New actors.py builds the actor document body, shared by GET /users/<u>
(live) and the coming Update(Person) push (throttled) so both render
the same shape without web.py depending on the worker-side module or
vice versa. now_playing_field() reads core's get_now_playing()
directly - never federation's own throttled push state - so a fetch
always shows the truth, whatever the last proactive push said.

GET /users/<u> now includes a "Now playing" PropertyValue attachment
whenever something unexpired is playing, and omits it otherwise.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
mattandClaude Sonnet 5 committed 2026-09-26 17:03:04 +01:00
1 parent cb8f9c997e
commit c38e2e392a
6 files changed
+108 -13

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
"""Actor document building (actors.py): shared by the live GET /users/<u> route and the
now-playing Update(Person) push."""
from scrobbler.federation import actors, sharing
from scrobbler.federation.protocol import vocab
from scrobbler.services.scrobbles import TrackInput, update_now_playing
URLS = vocab.actor_urls(
"https://scrobble.test", "alice", "https://scrobble.test/profile.html?u=alice"
)
def test_now_playing_field_is_empty_when_nothing_is_playing(fed_ctx, user):
assert actors.now_playing_field(user) == []
def test_now_playing_field_shows_the_current_track(fed_ctx, user):
update_now_playing(user, TrackInput(artist="Radiohead", track="Reckoner"))
assert actors.now_playing_field(user) == [("Now playing", "Reckoner by Radiohead")]
def test_build_document_includes_the_now_playing_field(fed_ctx, user):
sharing.update(user.id, {"enabled": True, "display_name": "Alice", "bio": "Hi."})
update_now_playing(user, TrackInput(artist="Radiohead", track="Reckoner"))
settings = sharing.settings_for(user.id)
doc = actors.build_document(URLS, user, settings)
assert doc["attachment"] == [
{"type": "PropertyValue", "name": "Now playing", "value": "Reckoner by Radiohead"}
]
def test_build_document_has_no_now_playing_field_when_idle(fed_ctx, user):
sharing.update(user.id, {"enabled": True})
settings = sharing.settings_for(user.id)
doc = actors.build_document(URLS, user, settings)
assert doc["attachment"] == []