Admin post-weekly command and GoToSocial post interop checks (phase 3, step 10)
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 1m8s
CI / test (push) Successful in 2m56s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 1m8s
CI / test (push) Successful in 2m56s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
`flask federation post-weekly --user <name> --now` posts a user's
summary for the week still in progress immediately, ignoring the
Monday-09:00 gate - for operators, and so the interop test can produce
a real post without waiting on calendar time. Backed by a new
weekly.post_now(), sharing _post_for_window() with the normal
check_and_post() path so both go through the same has_post/empty-week/
publish logic; only the window (this week so far, vs. the last gated
one) differs.
Extends the GoToSocial interop driver to a second phase: run.sh seeds
one scrobble directly (the driver container has no way to sign a
Last.fm-API request, and doesn't need one just to seed data), triggers
the CLI command via `docker compose exec api`, then re-runs the driver
with --check-posts to confirm the post reaches the already-following
GoToSocial account's home timeline as `private` (followers-only, our
default) with the expected content, deletes it via the existing
DELETE /posts/{id} API, and confirms it disappears from GoToSocial's
timeline too. The main flow now ends by re-following instead of the
previous test's decline, so the post-check phase has a follower to
check against.
Verified end to end against a real GoToSocial 0.22.1 container locally
before pushing (scripts/interop/run.sh), not just left to CI:
private post: '<p><strong>My week in music: 1 play</strong></p>...'
All post interop checks passed
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
de1519a066
commit
860d4d0f93
8 files changed
+244
-8
No files matched your search
@@ -30,11 +30,13 @@ def init_app(app: Flask) -> None:
|
||||
|
||||
from scrobbler.api import get_api
|
||||
from scrobbler.federation import api, openapi, web
|
||||
from scrobbler.federation.cli import federation_cli
|
||||
|
||||
app.register_blueprint(web.bp)
|
||||
core_api = get_api(app)
|
||||
core_api.register_blueprint(api.blp, url_prefix="/api/v1/federation")
|
||||
openapi.register(app, core_api)
|
||||
app.cli.add_command(federation_cli)
|
||||
|
||||
from scrobbler import events, worker
|
||||
from scrobbler.federation import delivery, inbox
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Fediverse admin commands (`flask federation ...`)."""
|
||||
|
||||
import click
|
||||
from flask.cli import AppGroup, with_appcontext
|
||||
|
||||
federation_cli = AppGroup("federation", help="Fediverse admin commands.")
|
||||
|
||||
|
||||
@federation_cli.command("post-weekly")
|
||||
@click.option("--user", "username", required=True, help="Username to post for.")
|
||||
@click.option(
|
||||
"--now",
|
||||
"immediately",
|
||||
is_flag=True,
|
||||
required=True,
|
||||
help="Post about the week still in progress right now, ignoring the Monday-09:00 "
|
||||
"gate (the only mode this command supports, for operators and testing).",
|
||||
)
|
||||
@with_appcontext
|
||||
def post_weekly(username: str, immediately: bool) -> None:
|
||||
"""Post one user's weekly summary immediately."""
|
||||
from scrobbler.extensions import db
|
||||
from scrobbler.federation.publishing import weekly
|
||||
from scrobbler.services import accounts
|
||||
|
||||
user = accounts.find_user(username)
|
||||
if user is None:
|
||||
raise click.ClickException(f"No such user: {username}")
|
||||
result = weekly.post_now(user.id)
|
||||
db.session.commit()
|
||||
if result == "posted":
|
||||
click.echo(f"Posted a weekly summary for {username}.")
|
||||
elif result == "already_posted":
|
||||
click.echo(f"{username} already has a post for this week.")
|
||||
elif result == "skipped_empty":
|
||||
click.echo(f"{username} hasn't scrobbled anything this week.")
|
||||
else:
|
||||
raise click.ClickException(f"{username} isn't sharing weekly summaries.")
|
||||
@@ -4,12 +4,18 @@ Weeks run Monday 00:00 to Sunday 24:00 *local time*, computed in the zone itself
|
||||
a fixed UTC offset), so the window is correct across a daylight-saving change.
|
||||
"""
|
||||
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from datetime import UTC, date, datetime, timedelta
|
||||
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
||||
|
||||
POST_HOUR = 9 # local time a week's summary becomes postable, on the following Monday
|
||||
|
||||
|
||||
def week_key(day: date) -> str:
|
||||
"""The ISO year-week key (e.g. "2026-W02") for the week a date falls in."""
|
||||
year, week, _ = day.isocalendar()
|
||||
return f"{year}-W{week:02d}"
|
||||
|
||||
|
||||
def target_week(now_utc: datetime, tz: ZoneInfo) -> tuple[datetime, datetime, str]:
|
||||
"""The [start, end) UTC window, and ISO year-week key (e.g. "2026-W02"), of the most
|
||||
recent Monday-Sunday week whose Monday-POST_HOUR-local posting gate has passed.
|
||||
@@ -26,8 +32,7 @@ def target_week(now_utc: datetime, tz: ZoneInfo) -> tuple[datetime, datetime, st
|
||||
|
||||
start_local = datetime(week_start.year, week_start.month, week_start.day, tzinfo=tz)
|
||||
end_local = start_local + timedelta(days=7) # wall-clock +7 days: DST-correct on conversion
|
||||
year, week, _ = week_start.isocalendar()
|
||||
return start_local.astimezone(UTC), end_local.astimezone(UTC), f"{year}-W{week:02d}"
|
||||
return start_local.astimezone(UTC), end_local.astimezone(UTC), week_key(week_start)
|
||||
|
||||
|
||||
def current_week_start(now_utc: datetime, tz: ZoneInfo) -> datetime:
|
||||
|
||||
@@ -76,6 +76,10 @@ def _check_and_post(settings: FederationSettings, now_utc: datetime) -> str:
|
||||
|
||||
tz = schedule.resolve_timezone(settings.timezone)
|
||||
start, end, key = schedule.target_week(now_utc, tz)
|
||||
return _post_for_window(user, key, start, end)
|
||||
|
||||
|
||||
def _post_for_window(user, key: str, start: datetime, end: datetime) -> str:
|
||||
if publishing.has_post(user.id, KIND, key):
|
||||
return "already_posted" # the common case: checked before, nothing new to do
|
||||
|
||||
@@ -90,6 +94,28 @@ def _check_and_post(settings: FederationSettings, now_utc: datetime) -> str:
|
||||
return "posted" if post is not None else "already_posted" # lost a race with another pass
|
||||
|
||||
|
||||
def post_now(user_id: int, now_utc: datetime | None = None) -> str:
|
||||
"""Post this user's summary immediately, for the week still in progress, ignoring
|
||||
the Monday-09:00 gate. For operators (`flask federation post-weekly --now`) and the
|
||||
interop test - not part of the automated pipeline (check_and_post/check_all), so it
|
||||
isn't itself gated on post_weekly_summary being checked by a worker pass."""
|
||||
settings = sharing.settings_for(user_id)
|
||||
if not (settings.enabled and settings.post_weekly_summary):
|
||||
result = "disabled"
|
||||
else:
|
||||
user = accounts.get_user(user_id)
|
||||
if user is None:
|
||||
result = "disabled"
|
||||
else:
|
||||
now_utc = now_utc or datetime.now(UTC)
|
||||
tz = schedule.resolve_timezone(settings.timezone)
|
||||
start = schedule.current_week_start(now_utc, tz)
|
||||
key = schedule.week_key(start.astimezone(tz).date())
|
||||
result = _post_for_window(user, key, start, now_utc)
|
||||
fed_metrics.weekly_total.labels(result=result).inc()
|
||||
return result
|
||||
|
||||
|
||||
def preview(user_id: int, now_utc: datetime | None = None) -> tuple[str, str] | None:
|
||||
"""What a weekly summary would say right now, for the week still in progress. Never
|
||||
stored or posted: for the Sharing page's live preview. None if the account is gone."""
|
||||
|
||||
Reference in new issue
Block a user