diff options
| author | Dennis Fink | 2026-11-17 19:43:04 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-17 19:43:04 +0100 |
| commit | 5e24e8307f650e72881f747661a2b6e52db15f2d (patch) | |
| tree | 585b456b9439a17957e8633f566c0725bb9d8595 /tests/tasks | |
| parent | 6d6d079a3a99d3d3a922a640b6925eb2adf044de (diff) | |
| download | webmentions-ssg-5e24e8307f650e72881f747661a2b6e52db15f2d.tar.gz webmentions-ssg-5e24e8307f650e72881f747661a2b6e52db15f2d.zip | |
feat(receiver): add Webmention detail and status history
Add an authenticated detail view with full failure information,
timestamps, actions, public status links, and recorded lifecycle
transitions.
Persist verification and resubmission events, backfill existing rows
during migration, and clean up history when received Webmentions are
deleted.
Diffstat (limited to '')
| -rw-r--r-- | tests/tasks/test_retention.py | 39 | ||||
| -rw-r--r-- | tests/tasks/test_verification.py | 53 |
2 files changed, 92 insertions, 0 deletions
diff --git a/tests/tasks/test_retention.py b/tests/tasks/test_retention.py index a3891a9..f32f2cb 100644 --- a/tests/tasks/test_retention.py +++ b/tests/tasks/test_retention.py @@ -67,3 +67,42 @@ def test_retention_uses_admin_configured_days(app: Flask) -> None: ) db.session.commit() assert purge_old_received_webmentions() == 1 + + +def test_retention_removes_only_deleted_webmention_history(app: Flask) -> None: + from webmentions_ssg.models.received import ( + ReceivedWebmentionStatus, + ReceivedWebmentionStatusEvent, + ) + + app.config["RECEIVED_RETENTION_DAYS"] = 7 + now = datetime.now(UTC) + expired = uuid.uuid7() + kept = uuid.uuid7() + with app.app_context(): + for identifier, source, age in ( + (expired, "https://source.example/expired", 10), + (kept, "https://source.example/kept", 1), + ): + mention = ReceivedWebmention( + uuid=identifier, + source=source, + target="https://dennisfink.me/target", + status=ReceivedWebmentionStatus.FAILED, + updated_at=now - timedelta(days=age), + ) + mention.status_events.append( + ReceivedWebmentionStatusEvent( + webmention_uuid=identifier, + status=ReceivedWebmentionStatus.FAILED, + action="Verification completed", + occurred_at=now - timedelta(days=age), + ) + ) + db.session.add(mention) + db.session.commit() + + assert purge_old_received_webmentions() == 1 + history = db.session.scalars(sa.select(ReceivedWebmentionStatusEvent)).all() + assert len(history) == 1 + assert history[0].webmention_uuid == kept diff --git a/tests/tasks/test_verification.py b/tests/tasks/test_verification.py index 3547464..f36da44 100644 --- a/tests/tasks/test_verification.py +++ b/tests/tasks/test_verification.py @@ -781,3 +781,56 @@ def test_source_mentions_target_falls_back_for_unknown_encoding( assert verification.source_mentions_target(SOURCE_URL, TARGET_URL) fetch_source_document.assert_called_once_with(SOURCE_URL) + + +def test_verification_records_claim_and_outcome_history( + app: Flask, verification: ModuleType +) -> None: + from webmentions_ssg.models.received import ( + ReceivedWebmentionStatus, + ReceivedWebmentionStatusEvent, + ) + + identifier = create_webmention(app, recovery_attempts=2) + with app.app_context(): + claim = verification.claim_for_verification(identifier) + assert claim is not None + stored = verification.store_verification_outcome( + claim, ReceivedWebmentionStatus.FAILED, "Full verification failure" + ) + assert stored + history = db.session.scalars( + sa.select(ReceivedWebmentionStatusEvent) + .where(ReceivedWebmentionStatusEvent.webmention_uuid == identifier) + .order_by(ReceivedWebmentionStatusEvent.id) + ).all() + assert [event.status for event in history] == [ + ReceivedWebmentionStatus.VERIFYING, + ReceivedWebmentionStatus.FAILED, + ] + assert [event.recovery_attempts for event in history] == [2, 2] + assert history[1].failure_reason == "Full verification failure" + + +def test_stale_recovery_records_history_and_attempt_count( + app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch +) -> None: + from webmentions_ssg.models.received import ReceivedWebmentionStatusEvent + + identifier = create_webmention(app, status="verifying", recovery_attempts=1) + set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1)) + enqueue = Mock() + monkeypatch.setattr(verification, "verify_webmention", enqueue) + + with app.app_context(): + assert verification.recover_stale_verifications() == 1 + events = db.session.scalars( + sa.select(ReceivedWebmentionStatusEvent).where( + ReceivedWebmentionStatusEvent.webmention_uuid == identifier + ) + ).all() + assert len(events) == 1 + assert events[0].action == "Stale verification recovered" + assert events[0].status == "received" + assert events[0].recovery_attempts == 2 + enqueue.assert_called_once_with(identifier) |
