Notifications move to /admin/settings. /admin/log lists everything failing now (crossposts, response checks, outgoing webmentions, reply contexts, WebSub, notifications, refused silo credentials) with the affected post, the error and Retry/Check now. Back to Dashboard button removed; nav gains Webmentions, Log (with error count) and Settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
5.3 KiB
Python
120 lines
5.3 KiB
Python
"""Admin Log and Settings pages (v2.18.0)"""
|
|
|
|
import pytest
|
|
|
|
from starpunk import backfeed, create_app, error_log
|
|
from starpunk.auth import create_session
|
|
from starpunk.database import get_db
|
|
from starpunk.notes import create_note
|
|
|
|
SITE = "https://blog.example.com"
|
|
|
|
|
|
@pytest.fixture
|
|
def app(tmp_path):
|
|
app = create_app({
|
|
"TESTING": True, "SITE_URL": SITE, "ADMIN_ME": "https://example.com",
|
|
"DATABASE_PATH": tmp_path / "starpunk.db", "DATA_PATH": tmp_path,
|
|
"NOTES_PATH": tmp_path / "notes", "SESSION_SECRET": "test", "CSRF_ENABLED": False,
|
|
"BACKGROUND_WORKERS_ENABLED": False, "WEBMENTION_ENABLED": True,
|
|
})
|
|
backfeed.denied.clear()
|
|
yield app
|
|
backfeed.denied.clear()
|
|
|
|
|
|
@pytest.fixture
|
|
def browser(app):
|
|
with app.test_request_context():
|
|
token = create_session("https://example.com")
|
|
client = app.test_client()
|
|
client.set_cookie("starpunk_session", token)
|
|
return client
|
|
|
|
|
|
def _failures(app):
|
|
"""One of each kind of error, on two notes"""
|
|
with app.app_context():
|
|
broken = create_note(content="A crosspost that broke", published=True)
|
|
reply = create_note(content="Replying", published=True)
|
|
db = get_db(app)
|
|
db.execute("UPDATE notes SET in_reply_to = 'https://gone.example/post' WHERE id = ?", (reply.id,))
|
|
db.execute("INSERT INTO syndications (note_id, target, state, last_error, updated_at) "
|
|
"VALUES (?, 'bluesky', 'failed', 'HTTP 400: post too long', '2026-11-12 10:00:00')",
|
|
(broken.id,))
|
|
db.execute("INSERT INTO syndications (note_id, target, state, remote_url, backfeed_error, "
|
|
"backfeed_checked_at) VALUES (?, 'gotosocial', 'synced', 'https://social.example/1', "
|
|
"'HTTP 404 from GoToSocial', '2026-11-12 11:00:00')", (broken.id,))
|
|
db.execute("INSERT INTO webmention_queue (source_url, target_url, source_note_id, status, last_error) "
|
|
"VALUES (?, 'https://other.example/a', ?, 'failed', 'Endpoint returned 500')",
|
|
(f"{SITE}/note/{reply.slug}", reply.id))
|
|
db.execute("INSERT INTO reply_contexts (url, fetch_status, fetch_error) "
|
|
"VALUES ('https://gone.example/post', 'error', 'HTTP 410 Gone')")
|
|
db.execute("INSERT INTO syndications (note_id, target, state, last_error) "
|
|
"VALUES (?, 'threads', 'synced', 'old error, since fixed')", (reply.id,))
|
|
db.commit()
|
|
return broken, reply
|
|
|
|
|
|
def test_log_lists_each_error_with_its_post(app, browser):
|
|
broken, reply = _failures(app)
|
|
backfeed.denied["threads"] = "Needs a Threads token with threads_manage_replies"
|
|
|
|
page = browser.get("/admin/log").get_data(as_text=True)
|
|
for text in ("Crosspost to Bluesky", "HTTP 400: post too long", "Retry",
|
|
"Response check on GoToSocial", "HTTP 404 from GoToSocial", "Check now",
|
|
"Webmention sent", "https://other.example/a", "Endpoint returned 500",
|
|
"Reply context fetch", "HTTP 410 Gone",
|
|
"Response checks on Threads", "Needs a Threads token", "Site-wide"):
|
|
assert text in page, text
|
|
assert f"/admin/edit/{broken.id}" in page and f"/admin/edit/{reply.id}" in page
|
|
assert "old error, since fixed" not in page, "synced crossposts aren't errors"
|
|
assert 'class="badge badge-error">5<' in page
|
|
|
|
with app.app_context():
|
|
assert error_log.count() == 5
|
|
areas = [e["area"] for e in error_log.entries()]
|
|
assert areas[0] == "Response checks on Threads", "site-wide problems first"
|
|
assert areas.index("Response check on GoToSocial") < areas.index("Crosspost to Bluesky"), "newest first"
|
|
|
|
|
|
def test_log_retry_clears_the_crosspost_error(app, browser):
|
|
broken, _ = _failures(app)
|
|
with app.app_context():
|
|
sid = get_db(app).execute("SELECT id FROM syndications WHERE target = 'bluesky'").fetchone()[0]
|
|
browser.post(f"/admin/syndication/{sid}/retry")
|
|
assert "HTTP 400: post too long" not in browser.get("/admin/log").get_data(as_text=True)
|
|
|
|
|
|
def test_empty_log_and_no_badge(browser):
|
|
page = browser.get("/admin/log").get_data(as_text=True)
|
|
assert "No errors." in page and "badge-error" not in page
|
|
|
|
|
|
def test_notification_error_is_logged(app, browser):
|
|
with app.app_context():
|
|
get_db(app).execute("INSERT INTO site_state (key, value) VALUES "
|
|
"('notify_last_error', '2026-11-12 09:00:00 UTC gotify: 401 Unauthorized')")
|
|
get_db(app).commit()
|
|
page = browser.get("/admin/log").get_data(as_text=True)
|
|
assert "Notifications" in page and "gotify: 401 Unauthorized" in page and "2026-11-12 09:00:00" in page
|
|
|
|
|
|
def test_webmentions_page_is_decluttered(browser):
|
|
page = browser.get("/admin/webmentions").get_data(as_text=True)
|
|
assert "Back to Dashboard" not in page
|
|
assert "Send test notification" not in page and "<h3>Notifications</h3>" not in page
|
|
|
|
|
|
def test_nav_and_settings_page(browser):
|
|
page = browser.get("/admin/settings").get_data(as_text=True)
|
|
assert "<h3>Notifications</h3>" in page and "NOTIFY_URLS" in page
|
|
for link in ("/admin/webmentions", "/admin/log", "/admin/settings", "/admin/tokens"):
|
|
assert f'href="{link}"' in page, link
|
|
|
|
|
|
def test_pages_require_login(app):
|
|
client = app.test_client()
|
|
for path in ("/admin/log", "/admin/settings"):
|
|
assert client.get(path).status_code == 302
|