From ef90dc381322122ecfb9af039cf790de92807514 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 21 Nov 2026 14:49:28 +0100 Subject: feat(sender): split source and delivery history Add per-Webmention detail pages so delivery state, failure guidance, status URLs, and delivery history no longer crowd the source overview. Track source lifecycle events separately for discovery, revision, deletion, and restoration, and add a source-level action to resend only failed Webmentions. --- tests/tasks/test_scanner.py | 54 +++++++++++++++++++++++++++++++++++++++ tests/tasks/test_source_parser.py | 5 +--- tests/tasks/test_verification.py | 18 ++++++++----- 3 files changed, 67 insertions(+), 10 deletions(-) (limited to 'tests/tasks') diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py index af5a64e..dae4628 100644 --- a/tests/tasks/test_scanner.py +++ b/tests/tasks/test_scanner.py @@ -1521,3 +1521,57 @@ def test_failed_scan_does_not_update_completion_time( state = db.session.get(ScanState, 1) assert state is not None assert state.last_completed_at == previous_time + + +def test_source_lifecycle_history_records_real_transitions_only( + app: Flask, scanner_module: ModuleType +) -> None: + """An unchanged rescan is not an event; changes are preserved per source.""" + from webmentions_ssg.models.sources import SourceDocumentEvent + + timestamp = datetime(2026, 11, 1, tzinfo=UTC) + original = source_parser.ScannedSource( + path="tracked/index.html", + url="https://site.example/tracked/", + content_hash="0" * 32, + targets=frozenset({"https://example.org/linked"}), + ) + changed = source_parser.ScannedSource( + path=original.path, + url=original.url, + content_hash="1" * 32, + targets=original.targets, + ) + + with app.app_context(): + source = scanner_module.build_source(original, timestamp) + db.session.add(source) + db.session.commit() + assert [(event.action, event.revision) for event in source.history_events] == [ + ("Discovered", 1) + ] + scanner_module.apply_scan_to_source( + source, original, timestamp + timedelta(days=1) + ) + assert len(source.history_events) == 1 + scanner_module.apply_scan_to_source( + source, changed, timestamp + timedelta(days=2) + ) + scanner_module.mark_missing_sources_deleted( + {source.path: source}, frozenset(), timestamp + timedelta(days=3) + ) + scanner_module.apply_scan_to_source( + source, original, timestamp + timedelta(days=4) + ) + db.session.commit() + persisted = db.session.scalars( + sa.select(SourceDocumentEvent) + .where(SourceDocumentEvent.source_uuid == source.uuid) + .order_by(SourceDocumentEvent.id) + ).all() + assert [(event.action, event.revision) for event in persisted] == [ + ("Discovered", 1), + ("Revised", 2), + ("Deleted", 3), + ("Restored", 4), + ] diff --git a/tests/tasks/test_source_parser.py b/tests/tasks/test_source_parser.py index 38a5dc1..8c9b74a 100644 --- a/tests/tasks/test_source_parser.py +++ b/tests/tasks/test_source_parser.py @@ -1035,10 +1035,7 @@ def test_outgoing_targets_skip_urls_with_unparseable_hostname( monkeypatch.setattr(source_parser_module, "normalize_hostname", invalid_hostname) assert list( source_parser_module.iter_outgoing_targets( - content, - {}, - base_url=SOURCE_URL, - source_url=SOURCE_URL, + content, {}, base_url=SOURCE_URL, source_url=SOURCE_URL ) ) == ["https://good.example/post"] diff --git a/tests/tasks/test_verification.py b/tests/tasks/test_verification.py index d9c2f77..a581cc1 100644 --- a/tests/tasks/test_verification.py +++ b/tests/tasks/test_verification.py @@ -849,9 +849,12 @@ def test_verification_claim_race_rolls_back_without_status_event( row = db.session.get(ReceivedWebmention, identifier) assert row is not None assert row.status == "received" - assert db.session.scalar( - sa.select(sa.func.count(ReceivedWebmentionStatusEvent.id)) - ) == 0 + assert ( + db.session.scalar( + sa.select(sa.func.count(ReceivedWebmentionStatusEvent.id)) + ) + == 0 + ) def test_stale_verification_claim_race_does_not_enqueue( @@ -870,7 +873,10 @@ def test_stale_verification_claim_race_does_not_enqueue( row = db.session.get(ReceivedWebmention, identifier) assert row is not None assert row.status == "verifying" - assert db.session.scalar( - sa.select(sa.func.count(ReceivedWebmentionStatusEvent.id)) - ) == 0 + assert ( + db.session.scalar( + sa.select(sa.func.count(ReceivedWebmentionStatusEvent.id)) + ) + == 0 + ) enqueue.assert_not_called() -- cgit v1.3.1