diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/tasks/test_scanner.py | 54 |
1 files changed, 54 insertions, 0 deletions
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), + ] |
