aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/tasks/test_consumer.py6
-rw-r--r--tests/tasks/test_endpoint_discovery.py (renamed from tests/tasks/test_discovery.py)8
-rw-r--r--tests/tasks/test_extension.py28
-rw-r--r--tests/tasks/test_init.py6
-rw-r--r--tests/tasks/test_json_serializer.py10
-rw-r--r--tests/tasks/test_notifications.py14
-rw-r--r--tests/tasks/test_retention.py6
-rw-r--r--tests/tasks/test_scanner.py84
-rw-r--r--tests/tasks/test_sender.py51
-rw-r--r--tests/tasks/test_verification.py (renamed from tests/tasks/test_receiver.py)235
-rw-r--r--tests/test_cli.py134
-rw-r--r--tests/test_forms.py6
-rw-r--r--tests/test_init.py2
-rw-r--r--tests/test_models.py121
-rw-r--r--tests/test_net.py4
-rw-r--r--tests/views/helpers.py32
-rw-r--r--tests/views/test_admin.py4
-rw-r--r--tests/views/test_endpoint.py4
-rw-r--r--webmentions_ssg/config.py2
-rw-r--r--webmentions_ssg/extensions.py4
-rw-r--r--webmentions_ssg/forms.py9
-rw-r--r--webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py178
-rw-r--r--webmentions_ssg/migrations/versions/d845aa7fbc19_portable_url_fingerprints.py3
-rw-r--r--webmentions_ssg/models.py88
-rw-r--r--webmentions_ssg/tasks/__init__.py4
-rw-r--r--webmentions_ssg/tasks/consumer.py12
-rw-r--r--webmentions_ssg/tasks/endpoint_discovery.py (renamed from webmentions_ssg/tasks/discovery.py)0
-rw-r--r--webmentions_ssg/tasks/extension.py6
-rw-r--r--webmentions_ssg/tasks/notifications.py6
-rw-r--r--webmentions_ssg/tasks/retention.py7
-rw-r--r--webmentions_ssg/tasks/scanner.py38
-rw-r--r--webmentions_ssg/tasks/sender.py38
-rw-r--r--webmentions_ssg/tasks/verification.py (renamed from webmentions_ssg/tasks/receiver.py)47
-rw-r--r--webmentions_ssg/templates/received.html2
-rw-r--r--webmentions_ssg/templates/sent_source.html12
-rw-r--r--webmentions_ssg/templates/status.html2
-rw-r--r--webmentions_ssg/views/admin.py20
-rw-r--r--webmentions_ssg/views/endpoint.py9
38 files changed, 799 insertions, 443 deletions
diff --git a/tests/tasks/test_consumer.py b/tests/tasks/test_consumer.py
index 78f1b6b..bc18583 100644
--- a/tests/tasks/test_consumer.py
+++ b/tests/tasks/test_consumer.py
@@ -37,13 +37,13 @@ def test_consumer_registers_scanner_digest_reaper_and_retention(
monkeypatch.setattr(huey, "periodic_task", periodic_task)
consumer = importlib.import_module("webmentions_ssg.tasks.consumer")
- from webmentions_ssg.tasks import notifications, receiver, retention, scanner
+ from webmentions_ssg.tasks import notifications, retention, scanner, verification
assert consumer.huey is huey.huey
assert periodic_task.call_count == 4
assert registered_tasks == [
scanner.scan_sources,
- receiver.recover_stale_verifications,
- notifications.send_webmention_digest,
+ verification.recover_stale_verifications,
+ notifications.email_verified_digest,
retention.purge_old_received_webmentions,
]
diff --git a/tests/tasks/test_discovery.py b/tests/tasks/test_endpoint_discovery.py
index 4616a53..98c167b 100644
--- a/tests/tasks/test_discovery.py
+++ b/tests/tasks/test_endpoint_discovery.py
@@ -10,7 +10,7 @@ import httpx
import pytest
from flask import Flask
-from webmentions_ssg.tasks import discovery
+from webmentions_ssg.tasks import endpoint_discovery
SOURCE_URL = "https://dennisfink.me/blog/example/"
TARGET_URL = "https://example.com/post"
@@ -21,9 +21,9 @@ STATUS_URL = "https://example.com/webmention/status/123"
@pytest.fixture
def sender_module(app: Flask) -> ModuleType:
_ = app
- from webmentions_ssg.tasks import discovery
+ from webmentions_ssg.tasks import endpoint_discovery
- return discovery
+ return endpoint_discovery
@pytest.mark.parametrize(
@@ -707,7 +707,7 @@ def test_resolve_endpoint_url_rejects_invalid_url(
sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch
) -> None:
is_http_url = Mock(return_value=False)
- monkeypatch.setattr(discovery, "is_http_url", is_http_url)
+ monkeypatch.setattr(endpoint_discovery, "is_http_url", is_http_url)
response = httpx.Response(HTTPStatus.OK, request=httpx.Request("GET", TARGET_URL))
with pytest.raises(
sender_module.PermanentDeliveryError, match="Invalid Webmention endpoint"
diff --git a/tests/tasks/test_extension.py b/tests/tasks/test_extension.py
index 323353e..adbad09 100644
--- a/tests/tasks/test_extension.py
+++ b/tests/tasks/test_extension.py
@@ -11,18 +11,18 @@ import pytest
from flask import Flask, current_app, has_app_context
from huey import crontab
-from webmentions_ssg.tasks.extension import Huey
+from webmentions_ssg.tasks.extension import FlaskHuey
def test_init_without_app() -> None:
- huey = Huey()
+ huey = FlaskHuey()
assert huey.app is None
with pytest.raises(RuntimeError, match="Huey has not been initialized"):
_ = huey.huey
def test_init_with_app(app: Flask) -> None:
- huey = Huey(app)
+ huey = FlaskHuey(app)
assert huey.app is app
assert huey.huey.name == app.import_name
assert huey.huey.results is True
@@ -42,7 +42,7 @@ def test_init_app_uses_huey_configuration(app: Flask) -> None:
"immediate": False,
}
- huey = Huey()
+ huey = FlaskHuey()
huey.init_app(app)
assert huey.huey.name == "custom-name"
@@ -56,12 +56,14 @@ def test_huey_url_takes_precedence_over_huey_configuration(app: Flask) -> None:
app.config["HUEY"] = {"url": "blackhole://"}
app.config["HUEY_URL"] = "memory://"
- huey = Huey(app)
+ huey = FlaskHuey(app)
assert type(huey.huey).__name__ == "MemoryHuey"
-def task_decorator(huey: Huey, periodic: bool) -> Callable[[Callable[..., Any]], Any]:
+def task_decorator(
+ huey: FlaskHuey, periodic: bool
+) -> Callable[[Callable[..., Any]], Any]:
if periodic:
return huey.periodic_task(crontab(minute="*"))
@@ -70,7 +72,7 @@ def task_decorator(huey: Huey, periodic: bool) -> Callable[[Callable[..., Any]],
@pytest.mark.parametrize("periodic", [False, True], ids=["task", "periodic-task"])
def test_task_runs_in_app_context(app: Flask, periodic: bool) -> None:
- huey = Huey(app)
+ huey = FlaskHuey(app)
@task_decorator(huey, periodic)
def add(a: int, b: int) -> int:
@@ -82,7 +84,7 @@ def test_task_runs_in_app_context(app: Flask, periodic: bool) -> None:
@pytest.mark.parametrize("periodic", [False, True], ids=["task", "periodic-task"])
def test_task_raises_without_app(app: Flask, periodic: bool) -> None:
- huey = Huey(app)
+ huey = FlaskHuey(app)
@task_decorator(huey, periodic)
def task() -> None:
@@ -100,7 +102,7 @@ def test_task_declaration_before_init_and_rebind_after_init(periodic: bool) -> N
:param periodic: Pytest fixture providing the periodic-task test function.
"""
- queue = Huey()
+ queue = FlaskHuey()
observed_apps: list[str] = []
@task_decorator(queue, periodic)
@@ -138,7 +140,7 @@ def test_task_declaration_before_init_and_rebind_after_init(periodic: bool) -> N
def test_multiple_deferred_tasks_registered_on_initialization() -> None:
- queue = Huey()
+ queue = FlaskHuey()
@queue.task(retries=2, retry_delay=50)
def first(value: int) -> int:
@@ -157,7 +159,7 @@ def test_multiple_deferred_tasks_registered_on_initialization() -> None:
def test_getattr_delegates_to_huey(app: Flask) -> None:
- huey = Huey(app)
+ huey = FlaskHuey(app)
assert huey.immediate is True
@@ -221,7 +223,7 @@ def test_backend_from_url(
monkeypatch.setattr(huey_package, backend_name, backend_class)
- actual_class, actual_storage_kwargs = Huey.backend_from_url(url)
+ actual_class, actual_storage_kwargs = FlaskHuey.backend_from_url(url)
assert actual_class is backend_class
assert actual_storage_kwargs == storage_kwargs
@@ -254,4 +256,4 @@ def test_backend_from_url(
)
def test_backend_from_url_rejects_invalid_url(url: str, message: str) -> None:
with pytest.raises(RuntimeError, match=re.escape(message)):
- Huey.backend_from_url(url)
+ FlaskHuey.backend_from_url(url)
diff --git a/tests/tasks/test_init.py b/tests/tasks/test_init.py
index 1a51fb8..380f885 100644
--- a/tests/tasks/test_init.py
+++ b/tests/tasks/test_init.py
@@ -4,9 +4,9 @@
"""Test the public background-task package API."""
-from webmentions_ssg.tasks import Huey
-from webmentions_ssg.tasks.extension import Huey as ExtensionHuey
+from webmentions_ssg.tasks import FlaskHuey
+from webmentions_ssg.tasks.extension import FlaskHuey as ExtensionHuey
def test_tasks_package_exports_huey_extension() -> None:
- assert Huey is ExtensionHuey
+ assert FlaskHuey is ExtensionHuey
diff --git a/tests/tasks/test_json_serializer.py b/tests/tasks/test_json_serializer.py
index 442e6a9..6077ebd 100644
--- a/tests/tasks/test_json_serializer.py
+++ b/tests/tasks/test_json_serializer.py
@@ -12,13 +12,13 @@ import pytest
from flask import Flask
from huey.utils import SKIPPED, Error
-from webmentions_ssg.tasks.extension import Huey
+from webmentions_ssg.tasks.extension import FlaskHuey
from webmentions_ssg.tasks.json_serializer import TaggedJSONSerializer
def test_json_is_default_even_for_production_style_broker(app: Flask) -> None:
app.config["HUEY"] = {"immediate": False}
- huey = Huey(app)
+ huey = FlaskHuey(app)
assert isinstance(huey.huey.serializer, TaggedJSONSerializer)
assert huey.huey.serializer.serialize("hello") == b'"hello"'
@@ -26,7 +26,7 @@ def test_json_is_default_even_for_production_style_broker(app: Flask) -> None:
def test_uuid_and_retry_message_survive_enqueue_dequeue(app: Flask) -> None:
app.config["HUEY"] = {"immediate": False}
- huey = Huey(app)
+ huey = FlaskHuey(app)
identifier = uuid.uuid4()
@huey.task(retries=2, retry_delay=50)
@@ -87,12 +87,12 @@ def test_rejects_unknown_and_malformed_types() -> None:
def test_refuses_unsafe_serializer_configuration(app: Flask) -> None:
app.config["HUEY"] = {"serializer": None}
with pytest.raises(RuntimeError, match="JSON is required"):
- Huey(app)
+ FlaskHuey(app)
def test_compression_with_json(app: Flask) -> None:
app.config["HUEY"] = {"compression": True, "immediate": False}
- huey = Huey(app)
+ huey = FlaskHuey(app)
payload = {"id": uuid.uuid4()}
raw = huey.huey.serializer.serialize(payload)
diff --git a/tests/tasks/test_notifications.py b/tests/tasks/test_notifications.py
index a1a002e..ca89a7a 100644
--- a/tests/tasks/test_notifications.py
+++ b/tests/tasks/test_notifications.py
@@ -49,8 +49,8 @@ def test_digest_sends_one_email_for_multiple_verified_mentions(
with app.app_context():
with patch("webmentions_ssg.tasks.notifications.mail.send") as send:
- notifications.send_webmention_digest()
- notifications.send_webmention_digest()
+ notifications.email_verified_digest()
+ notifications.email_verified_digest()
send.assert_called_once()
message = send.call_args.args[0]
@@ -80,7 +80,7 @@ def test_digest_skips_when_notifications_disabled(
with app.app_context():
with patch("webmentions_ssg.tasks.notifications.mail.send") as send:
- notifications.send_webmention_digest()
+ notifications.email_verified_digest()
send.assert_not_called()
mention = db.session.get(ReceivedWebmention, identifier)
@@ -103,7 +103,7 @@ def test_digest_does_not_mark_mentions_when_email_fails(
),
pytest.raises(RuntimeError, match="SMTP unavailable"),
):
- notifications.send_webmention_digest()
+ notifications.email_verified_digest()
mention = db.session.get(ReceivedWebmention, identifier)
@@ -111,7 +111,7 @@ def test_digest_does_not_mark_mentions_when_email_fails(
assert mention.notification_sent_at is None
with patch("webmentions_ssg.tasks.notifications.mail.send") as send:
- notifications.send_webmention_digest()
+ notifications.email_verified_digest()
send.assert_called_once()
mention = db.session.get(ReceivedWebmention, identifier)
@@ -127,7 +127,7 @@ def test_digest_skips_when_no_new_mentions(
with app.app_context():
with patch("webmentions_ssg.tasks.notifications.mail.send") as send:
- notifications.send_webmention_digest()
+ notifications.email_verified_digest()
send.assert_not_called()
@@ -149,4 +149,4 @@ def test_digest_lock_uses_current_backend(
huey.lock_task("send-webmention-digest"),
pytest.raises(TaskLockedException),
):
- notifications.send_webmention_digest()
+ notifications.email_verified_digest()
diff --git a/tests/tasks/test_retention.py b/tests/tasks/test_retention.py
index 9e08837..70ab0e0 100644
--- a/tests/tasks/test_retention.py
+++ b/tests/tasks/test_retention.py
@@ -22,9 +22,9 @@ def test_retention_only_removes_old_failed_or_deleted_rows(app: Flask) -> None:
with app.app_context():
for suffix, status, age_days in (
("old-failed", "failed", 31),
- ("old-deleted", "deleted", 31),
+ ("old-source-removed", "source_removed", 31),
("recent-failed", "failed", 2),
- ("recent-deleted", "deleted", 2),
+ ("recent-source-removed", "source_removed", 2),
("old-verified", "verified", 50),
("old-received", "received", 50),
("old-verifying", "verifying", 50),
@@ -49,7 +49,7 @@ def test_retention_only_removes_old_failed_or_deleted_rows(app: Flask) -> None:
assert remaining == {
identifier
for key, identifier in identifiers.items()
- if key not in {"old-failed", "old-deleted"}
+ if key not in {"old-failed", "old-source-removed"}
}
diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py
index 00256d0..4cf2a67 100644
--- a/tests/tasks/test_scanner.py
+++ b/tests/tasks/test_scanner.py
@@ -17,7 +17,7 @@ from huey.exceptions import RetryTask
from pytest import MonkeyPatch
from webmentions_ssg import db
-from webmentions_ssg.models import SentWebmention, SentWebmentionStatus, Source
+from webmentions_ssg.models import SentWebmention, SentWebmentionStatus, SourceDocument
from webmentions_ssg.tasks import source_parser
from .scanner_helpers import BASE_URL, SOURCE_URL, configure_scanner, write_post
@@ -65,7 +65,7 @@ def test_manual_scan_runs_without_lock_contention(
with app.app_context():
scanner_module.manual_scan_sources.call_local()
source = db.session.scalar(
- sa.select(Source).where(Source.path == "manual/index.html")
+ sa.select(SourceDocument).where(SourceDocument.path == "manual/index.html")
)
assert source is not None
assert source.url == f"{BASE_URL}manual/"
@@ -101,7 +101,7 @@ def test_reconcile_source_tree_returns_count_and_seen_paths(
)
monkeypatch.setattr(scanner_module, "scan_source_file", parse)
- sources: dict[str, Source] = {}
+ sources: dict[str, SourceDocument] = {}
urls: dict[str, str] = {}
with app.app_context():
@@ -141,7 +141,7 @@ def test_scan_creates_source_and_webmentions(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
assert source is not None
assert source.path == "example/index.html"
@@ -161,7 +161,7 @@ def test_scan_creates_source_and_webmentions(
"https://example.com/b",
]
- assert all(webmention.active for webmention in webmentions)
+ assert all(webmention.linked for webmention in webmentions)
assert all(webmention.desired_revision == 1 for webmention in webmentions)
assert all(webmention.processed_revision is None for webmention in webmentions)
@@ -198,7 +198,7 @@ def test_duplicate_canonical_url_skips_alias_and_commits_other_sources(
run_scan(app, scanner_module)
with app.app_context():
- sources = list(db.session.scalars(sa.select(Source)))
+ sources = list(db.session.scalars(sa.select(SourceDocument)))
webmentions = list(db.session.scalars(sa.select(SentWebmention)))
assert len(sources) == 2
@@ -262,7 +262,7 @@ def test_existing_source_owns_canonical_url_when_alias_is_added(
run_scan(app, scanner_module)
with app.app_context():
- sources = list(db.session.scalars(sa.select(Source)))
+ sources = list(db.session.scalars(sa.select(SourceDocument)))
targets = list(db.session.scalars(sa.select(SentWebmention.target)))
assert len(sources) == 1
@@ -311,7 +311,8 @@ def test_deleted_source_still_reserves_its_canonical_url(
with app.app_context():
sources = {
- source.path: source for source in db.session.scalars(sa.select(Source))
+ source.path: source
+ for source in db.session.scalars(sa.select(SourceDocument))
}
assert set(sources) == {"owner/index.html", "unrelated/index.html"}
assert sources["owner/index.html"].deleted_at is not None
@@ -358,7 +359,7 @@ def test_unchanged_source_does_not_increment_revision(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
assert source is not None
assert source.revision == 1
@@ -388,7 +389,7 @@ def test_changing_relative_timestamp_does_not_resend(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None and webmention is not None
original_hash = source.content_hash
@@ -405,7 +406,7 @@ def test_changing_relative_timestamp_does_not_resend(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None and webmention is not None
assert source.content_hash == original_hash
@@ -485,7 +486,7 @@ def test_updated_source_increments_revision(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None
@@ -493,7 +494,7 @@ def test_updated_source_increments_revision(
assert source.revision == 2
- assert webmention.active
+ assert webmention.linked
assert webmention.desired_revision == 2
assert webmention.processed_revision == 1
assert webmention.sent_revision == 1
@@ -555,7 +556,7 @@ def test_new_target_is_added_on_update(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None
@@ -564,7 +565,7 @@ def test_new_target_is_added_on_update(
assert source.revision == 2
assert webmention.target == ("https://example.com/new")
- assert webmention.active
+ assert webmention.linked
assert webmention.desired_revision == 2
assert webmention.processed_revision is None
assert webmention.sent_revision is None
@@ -638,7 +639,7 @@ def test_removed_sent_target_is_queued_again(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None
@@ -646,7 +647,7 @@ def test_removed_sent_target_is_queued_again(
assert source.revision == 2
- assert not webmention.active
+ assert not webmention.linked
assert webmention.desired_revision == 2
assert webmention.processed_revision == 1
assert webmention.sent_revision == 1
@@ -706,7 +707,7 @@ def test_removed_unsent_target_is_not_queued(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None
@@ -714,7 +715,7 @@ def test_removed_unsent_target_is_not_queued(
assert source.revision == 2
- assert not webmention.active
+ assert not webmention.linked
assert webmention.desired_revision == 2
assert webmention.processed_revision == 2
assert webmention.sent_revision is None
@@ -756,14 +757,14 @@ def test_empty_output_directory_does_not_delete_sources_or_queue_removals(
run_scan(app, scanner_module)
with app.app_context():
- sources = list(db.session.scalars(sa.select(Source)))
+ sources = list(db.session.scalars(sa.select(SourceDocument)))
webmentions = list(db.session.scalars(sa.select(SentWebmention)))
assert len(sources) == 2
assert all(source.revision == 1 for source in sources)
assert all(source.deleted_at is None for source in sources)
assert len(webmentions) == 2
- assert all(webmention.active for webmention in webmentions)
+ assert all(webmention.linked for webmention in webmentions)
assert all(webmention.desired_revision == 1 for webmention in webmentions)
assert queued == []
@@ -775,7 +776,7 @@ def test_empty_output_directory_does_not_delete_sources_or_queue_removals(
run_scan(app, scanner_module)
with app.app_context():
- sources = list(db.session.scalars(sa.select(Source)))
+ sources = list(db.session.scalars(sa.select(SourceDocument)))
assert all(source.revision == 1 for source in sources)
assert all(source.deleted_at is None for source in sources)
@@ -802,7 +803,7 @@ def test_no_successful_pages_defers_pending_webmentions(
assert queued == []
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None and source.deleted_at is None
assert webmention is not None and webmention.desired_revision == 1
@@ -826,7 +827,7 @@ def test_failed_scan_does_not_delete_missing_source(
run_scan(app, scanner_module)
with app.app_context():
- sources = list(db.session.scalars(sa.select(Source)))
+ sources = list(db.session.scalars(sa.select(SourceDocument)))
assert len(sources) == 2
assert all(source.revision == 1 for source in sources)
assert all(source.deleted_at is None for source in sources)
@@ -873,7 +874,9 @@ def test_deleted_source_queues_previously_sent_webmention(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source).where(Source.url == SOURCE_URL))
+ source = db.session.scalar(
+ sa.select(SourceDocument).where(SourceDocument.url == SOURCE_URL)
+ )
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None
@@ -882,7 +885,7 @@ def test_deleted_source_queues_previously_sent_webmention(
assert source.revision == 2
assert source.deleted_at is not None
- assert not webmention.active
+ assert not webmention.linked
assert webmention.desired_revision == 2
assert webmention.processed_revision == 1
assert webmention.sent_revision == 1
@@ -919,7 +922,9 @@ def test_deleted_source_does_not_queue_unsent_webmention(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source).where(Source.url == SOURCE_URL))
+ source = db.session.scalar(
+ sa.select(SourceDocument).where(SourceDocument.url == SOURCE_URL)
+ )
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None
@@ -928,7 +933,7 @@ def test_deleted_source_does_not_queue_unsent_webmention(
assert source.revision == 2
assert source.deleted_at is not None
- assert not webmention.active
+ assert not webmention.linked
assert webmention.desired_revision == 2
assert webmention.processed_revision == 2
assert webmention.sent_revision is None
@@ -988,7 +993,9 @@ def test_restored_source_creates_new_revision(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source).where(Source.url == SOURCE_URL))
+ source = db.session.scalar(
+ sa.select(SourceDocument).where(SourceDocument.url == SOURCE_URL)
+ )
webmention = db.session.scalar(sa.select(SentWebmention))
assert source is not None
@@ -997,7 +1004,7 @@ def test_restored_source_creates_new_revision(
assert source.revision == 3
assert source.deleted_at is None
- assert webmention.active
+ assert webmention.linked
assert webmention.desired_revision == 3
assert webmention.sent_revision == 1
@@ -1129,7 +1136,7 @@ def test_invalid_known_source_is_not_deleted(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
assert source is not None
assert source.revision == 1
@@ -1186,7 +1193,7 @@ def test_unexpected_parser_error_does_not_abort_other_sources(
run_scan(app, scanner_module)
with app.app_context():
- sources = list(db.session.scalars(sa.select(Source)))
+ sources = list(db.session.scalars(sa.select(SourceDocument)))
webmention = db.session.scalar(sa.select(SentWebmention))
assert [source.path for source in sources] == ["good/index.html"]
@@ -1225,7 +1232,8 @@ def test_unexpected_parser_error_does_not_delete_known_source(
with app.app_context():
sources = {
- source.path: source for source in db.session.scalars(sa.select(Source))
+ source.path: source
+ for source in db.session.scalars(sa.select(SourceDocument))
}
bad = sources["bad/index.html"]
good = sources["good/index.html"]
@@ -1274,7 +1282,7 @@ def test_scan_sources_skips_symlink_outside_root(
run_scan(app, scanner_module)
with app.app_context():
- sources = list(db.session.scalars(sa.select(Source)))
+ sources = list(db.session.scalars(sa.select(SourceDocument)))
assert len(sources) == 1
assert sources[0].path == "example/index.html"
assert "escapes source directory" in caplog.text
@@ -1314,7 +1322,7 @@ def test_scan_sources_accepts_valid_base_url(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
assert source is not None
assert source.url == SOURCE_URL
@@ -1364,7 +1372,7 @@ def test_changed_source_url_is_rejected(
run_scan(app, scanner_module)
with app.app_context():
- source = db.session.scalar(sa.select(Source))
+ source = db.session.scalar(sa.select(SourceDocument))
assert source is not None
assert source.url == SOURCE_URL
@@ -1381,7 +1389,7 @@ def test_scan_sources_returns_when_source_directory_is_not_configured(
run_scan(app, scanner_module)
with app.app_context():
- assert db.session.scalar(sa.select(Source)) is None
+ assert db.session.scalar(sa.select(SourceDocument)) is None
def test_scan_sources_rejects_missing_source_directory(
@@ -1448,7 +1456,7 @@ def test_scan_sources_ignores_root_index(
run_scan(app, scanner_module)
with app.app_context():
- sources = list(db.session.scalars(sa.select(Source)))
+ sources = list(db.session.scalars(sa.select(SourceDocument)))
assert len(sources) == 1
assert sources[0].path == "example/index.html"
diff --git a/tests/tasks/test_sender.py b/tests/tasks/test_sender.py
index 032b638..9a0430c 100644
--- a/tests/tasks/test_sender.py
+++ b/tests/tasks/test_sender.py
@@ -14,7 +14,7 @@ import pytest
from flask import Flask
from webmentions_ssg import db
-from webmentions_ssg.models import SentWebmention, SentWebmentionStatus, Source
+from webmentions_ssg.models import SentWebmention, SentWebmentionStatus, SourceDocument
SOURCE_URL = "https://dennisfink.me/blog/example/"
TARGET_URL = "https://example.com/post"
@@ -25,7 +25,7 @@ STATUS_URL = "https://example.com/webmention/status/123"
def create_sent_webmention(
app: Flask,
*,
- active: bool = True,
+ linked: bool = True,
desired_revision: int = 1,
processed_revision: int | None = None,
sent_revision: int | None = None,
@@ -40,7 +40,7 @@ def create_sent_webmention(
now = datetime.now(UTC)
with app.app_context():
- source = Source(
+ source = SourceDocument(
path="example/index.html",
url=SOURCE_URL,
content_hash="0" * 32,
@@ -51,14 +51,14 @@ def create_sent_webmention(
webmention = SentWebmention(
target=TARGET_URL,
- active=active,
+ linked=linked,
desired_revision=desired_revision,
processed_revision=processed_revision,
sent_revision=sent_revision,
status=status,
failure_reason=failure_reason,
- endpoint=endpoint,
- response_status=response_status,
+ webmention_endpoint=endpoint,
+ endpoint_response_status=response_status,
status_url=status_url,
attempt_count=attempt_count,
next_retry_at=next_retry_at,
@@ -145,8 +145,7 @@ def test_attempt_delivery_returns_retryable_outcome(
reason="Webmention endpoint returned HTTP 503",
endpoint=ENDPOINT_URL,
response_status=HTTPStatus.SERVICE_UNAVAILABLE,
- terminal=False,
- temporary_failure=True,
+ retryable=True,
)
@@ -174,8 +173,8 @@ def test_send_webmention_persists_success(
assert webmention.sent_revision == 1
assert webmention.status == SentWebmentionStatus.SENT
assert webmention.failure_reason is None
- assert webmention.endpoint == ENDPOINT_URL
- assert webmention.response_status == HTTPStatus.CREATED
+ assert webmention.webmention_endpoint == ENDPOINT_URL
+ assert webmention.endpoint_response_status == HTTPStatus.CREATED
assert webmention.status_url == STATUS_URL
assert webmention.last_attempted_at is not None
assert webmention.last_sent_at is not None
@@ -212,10 +211,10 @@ def test_send_webmention_marks_unsupported_target_processed(
assert webmention is not None
assert webmention.processed_revision == 2
assert webmention.sent_revision == 1
- assert webmention.status == SentWebmentionStatus.UNSUPPORTED
+ assert webmention.status == SentWebmentionStatus.NO_ENDPOINT
assert webmention.failure_reason == "No Webmention endpoint discovered"
- assert webmention.endpoint is None
- assert webmention.response_status is None
+ assert webmention.webmention_endpoint is None
+ assert webmention.endpoint_response_status is None
assert webmention.status_url is None
assert webmention.last_attempted_at is not None
@@ -246,8 +245,8 @@ def test_send_webmention_persists_permanent_failure(
assert webmention.sent_revision == 1
assert webmention.status == SentWebmentionStatus.FAILED
assert webmention.failure_reason == "Webmention endpoint returned HTTP 400"
- assert webmention.endpoint == ENDPOINT_URL
- assert webmention.response_status == HTTPStatus.BAD_REQUEST
+ assert webmention.webmention_endpoint == ENDPOINT_URL
+ assert webmention.endpoint_response_status == HTTPStatus.BAD_REQUEST
assert webmention.status_url is None
@@ -277,8 +276,8 @@ def test_send_webmention_persists_temporary_failure_with_backoff(
assert webmention.sent_revision == 1
assert webmention.status == SentWebmentionStatus.FAILED
assert webmention.failure_reason == "Webmention endpoint returned HTTP 503"
- assert webmention.endpoint == ENDPOINT_URL
- assert webmention.response_status == HTTPStatus.SERVICE_UNAVAILABLE
+ assert webmention.webmention_endpoint == ENDPOINT_URL
+ assert webmention.endpoint_response_status == HTTPStatus.SERVICE_UNAVAILABLE
assert webmention.status_url is None
assert webmention.attempt_count == 1
assert webmention.next_retry_at is not None
@@ -443,8 +442,10 @@ def test_sender_malformed_request_is_terminal(
assert webmention.processed_revision == 1
assert webmention.attempt_count == 1
assert webmention.next_retry_at is None
- assert webmention.endpoint == (ENDPOINT_URL if stage == "post" else None)
- assert webmention.response_status is None
+ assert webmention.webmention_endpoint == (
+ ENDPOINT_URL if stage == "post" else None
+ )
+ assert webmention.endpoint_response_status is None
assert webmention.last_attempted_at is not None
assert httpx_client.call_count == 1
@@ -554,7 +555,7 @@ def test_send_webmention_lock_is_scoped_to_uuid(
first = db.session.get(SentWebmention, first_id)
assert first is not None
second = SentWebmention(
- source_id=first.source_id, target=other_target, desired_revision=1
+ source_uuid=first.source_uuid, target=other_target, desired_revision=1
)
db.session.add(second)
db.session.commit()
@@ -601,7 +602,7 @@ def test_send_webmention_ignores_processed_revision(
@pytest.mark.parametrize(
- "outcome", ["success", "unsupported", "temporary-failure", "permanent-failure"]
+ "outcome", ["success", "no_endpoint", "temporary-failure", "permanent-failure"]
)
def test_send_webmention_ignores_superseded_attempt(
app: Flask, sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch, outcome: str
@@ -627,12 +628,12 @@ def test_send_webmention_ignores_superseded_attempt(
post.side_effect = post_success
- case "unsupported":
+ case "no_endpoint":
- def discover_unsupported(*args, **kwargs) -> None:
+ def discover_no_endpoint(*args, **kwargs) -> None:
supersede_revision()
- discover.side_effect = discover_unsupported
+ discover.side_effect = discover_no_endpoint
case "temporary-failure":
@@ -708,5 +709,5 @@ def test_send_does_not_persist_unsafe_status_url(
mention = db.session.get(SentWebmention, identifier)
assert mention is not None
assert mention.status == SentWebmentionStatus.SENT
- assert mention.response_status == HTTPStatus.CREATED
+ assert mention.endpoint_response_status == HTTPStatus.CREATED
assert mention.status_url == expected
diff --git a/tests/tasks/test_receiver.py b/tests/tasks/test_verification.py
index 7241247..c336b19 100644
--- a/tests/tasks/test_receiver.py
+++ b/tests/tasks/test_verification.py
@@ -23,10 +23,10 @@ TARGET_URL = "https://dennisfink.me/blog/example/"
@pytest.fixture
-def receiver(app: Flask) -> ModuleType:
- from webmentions_ssg.tasks import receiver
+def verification(app: Flask) -> ModuleType:
+ from webmentions_ssg.tasks import verification
- return receiver
+ return verification
def create_webmention(
@@ -69,9 +69,9 @@ def set_stream_response(httpx_client: Mock, response: httpx.Response) -> Mock:
return client
-@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+@patch("webmentions_ssg.tasks.verification.httpx.Client")
def test_fetch_source_document_returns_response_and_body(
- httpx_client: Mock, app: Flask, receiver: ModuleType
+ httpx_client: Mock, app: Flask, verification: ModuleType
) -> None:
response = httpx.Response(
HTTPStatus.OK,
@@ -82,7 +82,7 @@ def test_fetch_source_document_returns_response_and_body(
client = set_stream_response(httpx_client, response)
with app.app_context():
- fetched_response, body = receiver.fetch_source_document(SOURCE_URL)
+ fetched_response, body = verification.fetch_source_document(SOURCE_URL)
assert fetched_response is response
assert body == b"<p>Document</p>"
@@ -92,7 +92,7 @@ def test_fetch_source_document_returns_response_and_body(
assert options["headers"] == {
"Accept": "text/html, application/xhtml+xml;q=0.9, text/plain;q=0.8",
- "User-Agent": f"{receiver.APP_NAME}/{receiver.VERSION} ReceivedWebmention",
+ "User-Agent": f"{verification.APP_NAME}/{verification.VERSION} ReceivedWebmention",
}
assert options["follow_redirects"] is True
assert options["max_redirects"] == app.config.get("MAX_REDIRECTS", 20)
@@ -100,7 +100,7 @@ def test_fetch_source_document_returns_response_and_body(
assert options["transport"].__class__.__name__ == "PublicHTTPTransport"
-@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+@patch("webmentions_ssg.tasks.verification.httpx.Client")
@pytest.mark.parametrize(
("status_code", "exception_name"),
[
@@ -117,7 +117,7 @@ def test_fetch_source_document_returns_response_and_body(
def test_fetch_source_document_maps_http_status_to_exception(
httpx_client: Mock,
app: Flask,
- receiver: ModuleType,
+ verification: ModuleType,
status_code: int,
exception_name: str,
) -> None:
@@ -126,15 +126,15 @@ def test_fetch_source_document_maps_http_status_to_exception(
httpx.Response(status_code, request=httpx.Request("GET", SOURCE_URL)),
)
- exception_type = getattr(receiver, exception_name)
+ exception_type = getattr(verification, exception_name)
with app.app_context(), pytest.raises(exception_type, match=f"HTTP {status_code}"):
- receiver.fetch_source_document(SOURCE_URL)
+ verification.fetch_source_document(SOURCE_URL)
-@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+@patch("webmentions_ssg.tasks.verification.httpx.Client")
def test_fetch_source_document_propagates_network_error(
- httpx_client: Mock, app: Flask, receiver: ModuleType
+ httpx_client: Mock, app: Flask, verification: ModuleType
) -> None:
client = httpx_client.return_value.__enter__.return_value
client.stream.side_effect = httpx.ConnectError(
@@ -145,12 +145,12 @@ def test_fetch_source_document_propagates_network_error(
app.app_context(),
pytest.raises(httpx.ConnectError, match="Connection refused"),
):
- receiver.fetch_source_document(SOURCE_URL)
+ verification.fetch_source_document(SOURCE_URL)
-@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+@patch("webmentions_ssg.tasks.verification.httpx.Client")
def test_fetch_source_document_rejects_declared_oversized_body(
- httpx_client: Mock, app: Flask, receiver: ModuleType
+ httpx_client: Mock, app: Flask, verification: ModuleType
) -> None:
app.config["MAX_RECEIVED_SOURCE_BYTES"] = 10
@@ -166,14 +166,16 @@ def test_fetch_source_document_rejects_declared_oversized_body(
with (
app.app_context(),
- pytest.raises(receiver.VerificationError, match="Source document is too large"),
+ pytest.raises(
+ verification.VerificationError, match="Source document is too large"
+ ),
):
- receiver.fetch_source_document(SOURCE_URL)
+ verification.fetch_source_document(SOURCE_URL)
-@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+@patch("webmentions_ssg.tasks.verification.httpx.Client")
def test_fetch_source_document_rejects_streamed_oversized_body(
- httpx_client: Mock, app: Flask, receiver: ModuleType
+ httpx_client: Mock, app: Flask, verification: ModuleType
) -> None:
app.config["MAX_RECEIVED_SOURCE_BYTES"] = 10
@@ -194,16 +196,18 @@ def test_fetch_source_document_rejects_streamed_oversized_body(
with (
app.app_context(),
- pytest.raises(receiver.VerificationError, match="Source document is too large"),
+ pytest.raises(
+ verification.VerificationError, match="Source document is too large"
+ ),
):
- receiver.fetch_source_document(SOURCE_URL)
+ verification.fetch_source_document(SOURCE_URL)
-@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+@patch("webmentions_ssg.tasks.verification.httpx.Client")
def test_fetch_source_document_does_not_mask_unexpected_value_error(
httpx_client: Mock,
app: Flask,
- receiver: ModuleType,
+ verification: ModuleType,
monkeypatch: pytest.MonkeyPatch,
) -> None:
set_stream_response(
@@ -211,14 +215,16 @@ def test_fetch_source_document_does_not_mask_unexpected_value_error(
httpx.Response(HTTPStatus.OK, request=httpx.Request("GET", SOURCE_URL)),
)
monkeypatch.setattr(
- receiver, "read_limited_body", Mock(side_effect=ValueError("unexpected bug"))
+ verification,
+ "read_limited_body",
+ Mock(side_effect=ValueError("unexpected bug")),
)
with app.app_context(), pytest.raises(ValueError, match="unexpected bug"):
- receiver.fetch_source_document(SOURCE_URL)
+ verification.fetch_source_document(SOURCE_URL)
-@patch("webmentions_ssg.tasks.receiver.fetch_source_document")
+@patch("webmentions_ssg.tasks.verification.fetch_source_document")
@pytest.mark.parametrize(
("content_type", "body", "expected"),
[
@@ -271,7 +277,7 @@ def test_fetch_source_document_does_not_mask_unexpected_value_error(
)
def test_source_mentions_target_by_media_type(
fetch_source_document: Mock,
- receiver: ModuleType,
+ verification: ModuleType,
content_type: str,
body: bytes,
expected: bool,
@@ -284,11 +290,11 @@ def test_source_mentions_target_by_media_type(
)
fetch_source_document.return_value = response, body
- assert receiver.source_mentions_target(SOURCE_URL, TARGET_URL) is expected
+ assert verification.source_mentions_target(SOURCE_URL, TARGET_URL) is expected
fetch_source_document.assert_called_once_with(SOURCE_URL)
-@patch("webmentions_ssg.tasks.receiver.fetch_source_document")
+@patch("webmentions_ssg.tasks.verification.fetch_source_document")
@pytest.mark.parametrize(
("content_type", "expected_media_type"),
[
@@ -299,7 +305,7 @@ def test_source_mentions_target_by_media_type(
)
def test_source_mentions_target_rejects_unsupported_media_type(
fetch_source_document: Mock,
- receiver: ModuleType,
+ verification: ModuleType,
content_type: str,
expected_media_type: str,
) -> None:
@@ -317,37 +323,42 @@ def test_source_mentions_target_rejects_unsupported_media_type(
fetch_source_document.return_value = response, b"Document"
with pytest.raises(
- receiver.VerificationError,
+ verification.VerificationError,
match=f"Unsupported source content type: {expected_media_type}",
):
- receiver.source_mentions_target(SOURCE_URL, TARGET_URL)
+ verification.source_mentions_target(SOURCE_URL, TARGET_URL)
@pytest.mark.parametrize(
("mentions", "expected_status", "expected_reason"),
- [(True, "verified", None), (False, "deleted", "Source does not mention target")],
+ [
+ (True, "verified", None),
+ (False, "source_removed", "Source does not mention target"),
+ ],
)
def test_determine_verification_outcome_returns_outcome(
- receiver: ModuleType,
+ verification: ModuleType,
monkeypatch: pytest.MonkeyPatch,
mentions: bool,
expected_status: str,
expected_reason: str | None,
) -> None:
- monkeypatch.setattr(receiver, "source_mentions_target", Mock(return_value=mentions))
- claim = receiver.VerificationClaim(
+ monkeypatch.setattr(
+ verification, "source_mentions_target", Mock(return_value=mentions)
+ )
+ claim = verification.VerificationClaim(
uuid.uuid7(), SOURCE_URL, TARGET_URL, datetime.now(UTC)
)
- assert receiver.determine_verification_outcome(claim) == (
+ assert verification.determine_verification_outcome(claim) == (
expected_status,
expected_reason,
)
-@patch("webmentions_ssg.tasks.receiver.source_mentions_target")
+@patch("webmentions_ssg.tasks.verification.source_mentions_target")
def test_verify_webmention_marks_row_verifying_before_check(
- source_mentions_target: Mock, app: Flask, receiver: ModuleType
+ source_mentions_target: Mock, app: Flask, verification: ModuleType
) -> None:
identifier = create_webmention(
app, status="failed", failure_reason="Earlier failure"
@@ -365,24 +376,24 @@ def test_verify_webmention_marks_row_verifying_before_check(
return True
source_mentions_target.side_effect = verify_source
- receiver.verify_webmention.call_local(identifier)
+ verification.verify_webmention.call_local(identifier)
assert get_webmention_state(app, identifier) == ("verified", None)
-@patch("webmentions_ssg.tasks.receiver.source_mentions_target")
+@patch("webmentions_ssg.tasks.verification.source_mentions_target")
@pytest.mark.parametrize(
("outcome", "expected_status", "expected_reason"),
[
("verified", "verified", None),
- ("missing", "deleted", "Source does not mention target"),
- ("gone", "deleted", "Source returned HTTP 410"),
+ ("missing", "source_removed", "Source does not mention target"),
+ ("gone", "source_removed", "Source returned HTTP 410"),
("permanent-failure", "failed", "Source returned HTTP 404"),
],
)
def test_verify_webmention_persists_final_state(
source_mentions_target: Mock,
app: Flask,
- receiver: ModuleType,
+ verification: ModuleType,
outcome: str,
expected_status: str,
expected_reason: str | None,
@@ -395,30 +406,30 @@ def test_verify_webmention_persists_final_state(
case "missing":
source_mentions_target.return_value = False
case "gone":
- source_mentions_target.side_effect = receiver.SourceGoneError(
+ source_mentions_target.side_effect = verification.SourceGoneError(
"Source returned HTTP 410"
)
case "permanent-failure":
- source_mentions_target.side_effect = receiver.VerificationError(
+ source_mentions_target.side_effect = verification.VerificationError(
"Source returned HTTP 404"
)
case _:
raise AssertionError(f"Unexpected outcome: {outcome}")
- receiver.verify_webmention.call_local(identifier)
+ verification.verify_webmention.call_local(identifier)
assert get_webmention_state(app, identifier) == (expected_status, expected_reason)
-@patch("webmentions_ssg.tasks.receiver.source_mentions_target")
+@patch("webmentions_ssg.tasks.verification.source_mentions_target")
@pytest.mark.parametrize("failure", ["temporary-http", "network"])
def test_verify_webmention_persists_retryable_failure_and_reraises(
- source_mentions_target: Mock, app: Flask, receiver: ModuleType, failure: str
+ source_mentions_target: Mock, app: Flask, verification: ModuleType, failure: str
) -> None:
identifier = create_webmention(app)
match failure:
case "temporary-http":
- exception = receiver.RetryableFetchError("Source returned HTTP 503")
+ exception = verification.RetryableFetchError("Source returned HTTP 503")
case "network":
exception = httpx.ConnectError(
"Connection refused", request=httpx.Request("GET", SOURCE_URL)
@@ -429,19 +440,19 @@ def test_verify_webmention_persists_retryable_failure_and_reraises(
source_mentions_target.side_effect = exception
with pytest.raises(type(exception), match=str(exception)):
- receiver.verify_webmention.call_local(identifier)
+ verification.verify_webmention.call_local(identifier)
assert get_webmention_state(app, identifier) == ("failed", str(exception))
-@patch("webmentions_ssg.tasks.receiver.source_mentions_target")
-@pytest.mark.parametrize("status", ["verifying", "verified", "deleted"])
+@patch("webmentions_ssg.tasks.verification.source_mentions_target")
+@pytest.mark.parametrize("status", ["verifying", "verified", "source_removed"])
def test_verify_webmention_skips_active_and_terminal_states(
- source_mentions_target: Mock, app: Flask, receiver: ModuleType, status: str
+ source_mentions_target: Mock, app: Flask, verification: ModuleType, status: str
) -> None:
identifier = create_webmention(app, status=status)
- receiver.verify_webmention.call_local(identifier)
+ verification.verify_webmention.call_local(identifier)
assert get_webmention_state(app, identifier) == (status, None)
source_mentions_target.assert_not_called()
@@ -461,17 +472,17 @@ def set_webmention_updated_at(
@pytest.mark.parametrize("status", ["verifying", "received"])
def test_reaper_requeues_stale_verifications(
- app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch, status: str
+ app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch, status: str
) -> None:
app.config["VERIFICATION_STALE_AFTER_SECONDS"] = 900
identifier = create_webmention(app, status=status, failure_reason="Interrupted")
set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1))
enqueue = Mock()
- monkeypatch.setattr(receiver, "verify_webmention", enqueue)
+ monkeypatch.setattr(verification, "verify_webmention", enqueue)
with app.app_context():
- assert receiver.recover_stale_verifications() == 1
- assert receiver.recover_stale_verifications() == 0
+ assert verification.recover_stale_verifications() == 1
+ assert verification.recover_stale_verifications() == 0
row = db.session.get(ReceivedWebmention, identifier)
assert row is not None
assert row.updated_at.replace(tzinfo=UTC) > datetime.now(UTC) - timedelta(
@@ -483,7 +494,7 @@ def test_reaper_requeues_stale_verifications(
def test_reaper_does_not_touch_recent_or_terminal_webmentions(
- app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch
+ app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch
) -> None:
recent_verifying = create_webmention(app, status="verifying")
recent_received = create_webmention(
@@ -494,10 +505,10 @@ def test_reaper_does_not_touch_recent_or_terminal_webmentions(
)
set_webmention_updated_at(app, old_verified, datetime.now(UTC) - timedelta(hours=1))
enqueue = Mock()
- monkeypatch.setattr(receiver, "verify_webmention", enqueue)
+ monkeypatch.setattr(verification, "verify_webmention", enqueue)
with app.app_context():
- assert receiver.recover_stale_verifications() == 0
+ assert verification.recover_stale_verifications() == 0
assert get_webmention_state(app, recent_verifying) == ("verifying", None)
assert get_webmention_state(app, recent_received) == ("received", None)
@@ -506,14 +517,16 @@ def test_reaper_does_not_touch_recent_or_terminal_webmentions(
def test_reaper_recovers_after_enqueue_failure(
- app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch
+ app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch
) -> None:
identifier = create_webmention(app, status="verifying")
set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1))
- monkeypatch.setattr(receiver, "verify_webmention", Mock(side_effect=RuntimeError))
+ monkeypatch.setattr(
+ verification, "verify_webmention", Mock(side_effect=RuntimeError)
+ )
with app.app_context(), pytest.raises(RuntimeError):
- receiver.recover_stale_verifications()
+ verification.recover_stale_verifications()
assert get_webmention_state(app, identifier) == ("received", None)
@@ -521,26 +534,26 @@ def test_reaper_recovers_after_enqueue_failure(
# but before Huey persisted the task.
app.config["VERIFICATION_STALE_AFTER_SECONDS"] = 0
enqueue = Mock()
- monkeypatch.setattr(receiver, "verify_webmention", enqueue)
+ monkeypatch.setattr(verification, "verify_webmention", enqueue)
with app.app_context():
- assert receiver.recover_stale_verifications() == 1
+ assert verification.recover_stale_verifications() == 1
enqueue.assert_called_once_with(identifier)
def test_late_worker_cannot_overwrite_recovered_verification(
- app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch
+ app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch
) -> None:
identifier = create_webmention(app)
- original_verify = receiver.verify_webmention
+ original_verify = verification.verify_webmention
def concurrent_recovery(_source: str, _target: str) -> bool:
# The reaper supersedes this still-running attempt; a newer attempt
# subsequently completes before the original fetch returns.
app.config["VERIFICATION_STALE_AFTER_SECONDS"] = 0
with app.app_context():
- with patch.object(receiver, "verify_webmention", Mock()) as enqueue:
- assert receiver.recover_stale_verifications() == 1
+ with patch.object(verification, "verify_webmention", Mock()) as enqueue:
+ assert verification.recover_stale_verifications() == 1
enqueue.assert_called_once_with(identifier)
db.session.execute(
sa.update(ReceivedWebmention)
@@ -550,28 +563,28 @@ def test_late_worker_cannot_overwrite_recovered_verification(
db.session.commit()
return False
- monkeypatch.setattr(receiver, "source_mentions_target", concurrent_recovery)
+ monkeypatch.setattr(verification, "source_mentions_target", concurrent_recovery)
original_verify.call_local(identifier)
assert get_webmention_state(app, identifier) == ("verified", None)
def test_reaper_requeues_and_verifies_integration(
- app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch
+ app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch
) -> None:
identifier = create_webmention(app, status="verifying")
set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1))
check = Mock(return_value=True)
- monkeypatch.setattr(receiver, "source_mentions_target", check)
+ monkeypatch.setattr(verification, "source_mentions_target", check)
with app.app_context():
- assert receiver.recover_stale_verifications() == 1
+ assert verification.recover_stale_verifications() == 1
assert get_webmention_state(app, identifier) == ("verified", None)
check.assert_called_once_with(SOURCE_URL, TARGET_URL)
-@patch("webmentions_ssg.tasks.receiver.source_mentions_target")
+@patch("webmentions_ssg.tasks.verification.source_mentions_target")
@pytest.mark.parametrize(
"unexpected_error",
[
@@ -584,29 +597,29 @@ def test_reaper_requeues_and_verifies_integration(
def test_verify_webmention_records_unexpected_error_as_terminal_failure(
source_mentions_target: Mock,
app: Flask,
- receiver: ModuleType,
+ verification: ModuleType,
unexpected_error: Exception,
) -> None:
identifier = create_webmention(app, source="http://ex☃mple.test/")
source_mentions_target.side_effect = unexpected_error
- receiver.verify_webmention.call_local(identifier)
+ verification.verify_webmention.call_local(identifier)
assert get_webmention_state(app, identifier) == ("failed", str(unexpected_error))
source_mentions_target.assert_called_once()
# Failed rows are not eligible for automatic reaper recovery.
set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1))
with app.app_context():
- assert receiver.recover_stale_verifications() == 0
+ assert verification.recover_stale_verifications() == 0
def test_reaper_caps_stale_verification_recoveries(
- app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch
+ app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch
) -> None:
app.config["VERIFICATION_MAX_RECOVERIES"] = 3
identifier = create_webmention(app, status="verifying")
enqueue = Mock()
- monkeypatch.setattr(receiver, "verify_webmention", enqueue)
+ monkeypatch.setattr(verification, "verify_webmention", enqueue)
# Simulate workers that repeatedly crash before completing the task.
for attempt in range(3):
@@ -614,7 +627,7 @@ def test_reaper_caps_stale_verification_recoveries(
app, identifier, datetime.now(UTC) - timedelta(hours=1)
)
with app.app_context():
- assert receiver.recover_stale_verifications() == 1
+ assert verification.recover_stale_verifications() == 1
row = db.session.get(ReceivedWebmention, identifier)
assert row is not None
assert row.status == "received"
@@ -622,69 +635,69 @@ def test_reaper_caps_stale_verification_recoveries(
set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1))
with app.app_context():
- assert receiver.recover_stale_verifications() == 0
+ assert verification.recover_stale_verifications() == 0
row = db.session.get(ReceivedWebmention, identifier)
assert row is not None
assert row.status == "failed"
- assert row.failure_reason == receiver.RECOVERY_EXHAUSTED_REASON
+ assert row.failure_reason == verification.RECOVERY_EXHAUSTED_REASON
assert row.recovery_attempts == 3
- assert receiver.recover_stale_verifications() == 0
+ assert verification.recover_stale_verifications() == 0
assert enqueue.call_count == 3
def test_reaper_caps_received_rows_lost_before_first_task(
- app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch
+ app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch
) -> None:
app.config["VERIFICATION_MAX_RECOVERIES"] = 1
identifier = create_webmention(app, status="received", recovery_attempts=1)
set_webmention_updated_at(app, identifier, datetime.now(UTC) - timedelta(hours=1))
enqueue = Mock()
- monkeypatch.setattr(receiver, "verify_webmention", enqueue)
+ monkeypatch.setattr(verification, "verify_webmention", enqueue)
with app.app_context():
- assert receiver.recover_stale_verifications() == 0
+ assert verification.recover_stale_verifications() == 0
assert get_webmention_state(app, identifier) == (
"failed",
- receiver.RECOVERY_EXHAUSTED_REASON,
+ verification.RECOVERY_EXHAUSTED_REASON,
)
enqueue.assert_not_called()
def test_exhausted_row_cannot_be_revived_by_late_huey_retry(
- app: Flask, receiver: ModuleType, monkeypatch: pytest.MonkeyPatch
+ app: Flask, verification: ModuleType, monkeypatch: pytest.MonkeyPatch
) -> None:
identifier = create_webmention(
app,
status="failed",
- failure_reason=receiver.RECOVERY_EXHAUSTED_REASON,
+ failure_reason=verification.RECOVERY_EXHAUSTED_REASON,
recovery_attempts=3,
)
source_mentions_target = Mock(return_value=True)
- monkeypatch.setattr(receiver, "source_mentions_target", source_mentions_target)
+ monkeypatch.setattr(verification, "source_mentions_target", source_mentions_target)
- receiver.verify_webmention.call_local(identifier)
+ verification.verify_webmention.call_local(identifier)
assert get_webmention_state(app, identifier) == (
"failed",
- receiver.RECOVERY_EXHAUSTED_REASON,
+ verification.RECOVERY_EXHAUSTED_REASON,
)
source_mentions_target.assert_not_called()
def test_verify_webmention_ignores_unknown_identifier(
- receiver: ModuleType, caplog: pytest.LogCaptureFixture
+ verification: ModuleType, caplog: pytest.LogCaptureFixture
) -> None:
identifier = uuid.uuid7()
with caplog.at_level(logging.WARNING):
- receiver.verify_webmention.call_local(identifier)
+ verification.verify_webmention.call_local(identifier)
assert f"Cannot verify unknown ReceivedWebmention {identifier}" in caplog.text
-@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+@patch("webmentions_ssg.tasks.verification.httpx.Client")
def test_fetch_source_document_rejects_unsafe_destination(
- httpx_client: Mock, app: Flask, receiver: ModuleType
+ httpx_client: Mock, app: Flask, verification: ModuleType
) -> None:
from webmentions_ssg.net import UnsafeAddressError
@@ -692,27 +705,27 @@ def test_fetch_source_document_rejects_unsafe_destination(
client.stream.side_effect = UnsafeAddressError("Local address")
with (
app.app_context(),
- pytest.raises(receiver.VerificationError, match="non-public address"),
+ pytest.raises(verification.VerificationError, match="non-public address"),
):
- receiver.fetch_source_document(SOURCE_URL)
+ verification.fetch_source_document(SOURCE_URL)
-@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+@patch("webmentions_ssg.tasks.verification.httpx.Client")
def test_fetch_source_document_treats_dns_failure_as_temporary(
- httpx_client: Mock, app: Flask, receiver: ModuleType
+ httpx_client: Mock, app: Flask, verification: ModuleType
) -> None:
client = httpx_client.return_value.__enter__.return_value
client.stream.side_effect = AddressResolutionError("DNS timeout")
with (
app.app_context(),
- pytest.raises(receiver.RetryableFetchError, match="could not be resolved"),
+ pytest.raises(verification.RetryableFetchError, match="could not be resolved"),
):
- receiver.fetch_source_document(SOURCE_URL)
+ verification.fetch_source_document(SOURCE_URL)
-@patch("webmentions_ssg.tasks.receiver.httpx.Client")
+@patch("webmentions_ssg.tasks.verification.httpx.Client")
def test_fetch_source_document_ignores_invalid_content_length(
- httpx_client: Mock, app: Flask, receiver: ModuleType
+ httpx_client: Mock, app: Flask, verification: ModuleType
) -> None:
response = httpx.Response(
HTTPStatus.OK,
@@ -723,15 +736,15 @@ def test_fetch_source_document_ignores_invalid_content_length(
set_stream_response(httpx_client, response)
with app.app_context():
- fetched_response, body = receiver.fetch_source_document(SOURCE_URL)
+ fetched_response, body = verification.fetch_source_document(SOURCE_URL)
assert fetched_response is response
assert body == b"<p>Document</p>"
-@patch("webmentions_ssg.tasks.receiver.fetch_source_document")
+@patch("webmentions_ssg.tasks.verification.fetch_source_document")
def test_source_mentions_target_falls_back_for_unknown_encoding(
- fetch_source_document: Mock, receiver: ModuleType
+ fetch_source_document: Mock, verification: ModuleType
) -> None:
body = f"Reply to {TARGET_URL}".encode()
@@ -744,5 +757,5 @@ def test_source_mentions_target_falls_back_for_unknown_encoding(
response.encoding = "unknown-encoding"
fetch_source_document.return_value = response, body
- assert receiver.source_mentions_target(SOURCE_URL, TARGET_URL)
+ assert verification.source_mentions_target(SOURCE_URL, TARGET_URL)
fetch_source_document.assert_called_once_with(SOURCE_URL)
diff --git a/tests/test_cli.py b/tests/test_cli.py
index cdaf896..9485494 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -12,13 +12,14 @@ import pytest
import sqlalchemy as sa
from alembic.script import ScriptDirectory
from flask import Flask
+from flask_migrate import downgrade as migrate_downgrade
from flask_migrate import upgrade as migrate_upgrade
from sqlalchemy import inspect
from sqlalchemy.exc import IntegrityError
from webmentions_ssg import create_app, db, migrate
from webmentions_ssg.config import TestingConfig
-from webmentions_ssg.models import ReceivedStatus, ReceivedWebmention, User
+from webmentions_ssg.models import ReceivedWebmention, ReceivedWebmentionStatus, User
def test_cli_groups_are_registered(app: Flask) -> None:
@@ -101,7 +102,20 @@ def test_create_db_builds_schema_and_records_latest_migration(
received_indexes = {
index["name"] for index in inspector.get_indexes("received_webmentions")
}
- assert {"alembic_version", "users", "received_webmentions"} <= table_names
+ assert {
+ "alembic_version",
+ "users",
+ "received_webmentions",
+ "source_documents",
+ } <= table_names
+ assert "sources" not in table_names
+ assert {
+ "source_uuid",
+ "linked",
+ "webmention_endpoint",
+ "endpoint_response_status",
+ } <= columns
+ assert "source_target_digest" in received_columns
assert {"attempt_count", "next_retry_at"} <= columns
assert "recovery_attempts" in received_columns
assert "ix_received_webmentions_status_updated_at" in received_indexes
@@ -236,7 +250,7 @@ def test_upgrade_backfills_portable_digest_for_existing_received_rows(
:param database_app: Flask application connected to the legacy SQLite schema.
"""
- from webmentions_ssg.models import received_url_digest
+ from webmentions_ssg.models import source_target_digest
with database_app.app_context():
migrate_upgrade(revision="c0272f25ce17")
@@ -259,7 +273,7 @@ def test_upgrade_backfills_portable_digest_for_existing_received_rows(
with db.engine.connect() as connection:
result = connection.execute(
sa.text(
- "SELECT source, target, status, url_digest "
+ "SELECT source, target, status, source_target_digest "
"FROM received_webmentions"
)
).one()
@@ -268,14 +282,14 @@ def test_upgrade_backfills_portable_digest_for_existing_received_rows(
sa.text("SELECT recovery_attempts FROM received_webmentions")
).scalar_one()
assert recovery_attempts == 0
- assert result.url_digest == received_url_digest(
+ assert result.source_target_digest == source_target_digest(
result.source, result.target
)
constraints = inspect(connection).get_unique_constraints(
"received_webmentions"
)
assert any(
- constraint["column_names"] == ["url_digest"]
+ constraint["column_names"] == ["source_target_digest"]
for constraint in constraints
)
@@ -314,7 +328,7 @@ def test_upgrade_converts_received_status_without_losing_rows(
for column in inspect(connection).get_columns("received_webmentions")
}
assert isinstance(columns["status"]["type"], sa.String)
- assert columns["status"]["type"].length == 9
+ assert columns["status"]["type"].length == len("source_removed")
assert (
connection.execute(
sa.text("SELECT status FROM received_webmentions")
@@ -324,7 +338,111 @@ def test_upgrade_converts_received_status_without_losing_rows(
mention = db.session.get(ReceivedWebmention, UUID(hex=identifier))
assert mention is not None
- assert mention.status is ReceivedStatus.VERIFYING
+ assert mention.status is ReceivedWebmentionStatus.VERIFYING
+
+
+def test_name_migration_round_trips_existing_webmention_rows(
+ database_app: Flask,
+) -> None:
+ """Keep persisted statuses, UUID foreign keys and unique constraints intact."""
+ source_uuid = "0" * 31 + "1"
+ sent_uuid = "0" * 31 + "2"
+ received_uuid = "0" * 31 + "3"
+
+ with database_app.app_context():
+ migrate_upgrade(revision="7c38bb1a935e")
+ with db.engine.begin() as connection:
+ connection.execute(
+ sa.text(
+ "INSERT INTO sources "
+ "(uuid, path, url, content_hash, revision, "
+ "last_seen_at, revised_at) "
+ "VALUES (:uuid, 'post/index.html', 'https://site.example/post', "
+ ":hash, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
+ ),
+ {"uuid": source_uuid, "hash": "0" * 32},
+ )
+ connection.execute(
+ sa.text(
+ "INSERT INTO sent_webmentions "
+ "(uuid, source_id, target, target_digest, active, desired_revision, "
+ "status, endpoint, response_status, attempt_count) "
+ "VALUES (:uuid, :source_id, 'https://target.example/', :digest, "
+ "1, 1, 'unsupported', 'https://target.example/webmention', 202, 0)"
+ ),
+ {"uuid": sent_uuid, "source_id": source_uuid, "digest": "1" * 64},
+ )
+ connection.execute(
+ sa.text(
+ "INSERT INTO received_webmentions "
+ "(uuid, source, target, url_digest, status, updated_at) "
+ "VALUES (:uuid, 'https://source.example/', "
+ "'https://site.example/', :digest, 'deleted', CURRENT_TIMESTAMP)"
+ ),
+ {"uuid": received_uuid, "digest": "2" * 64},
+ )
+
+ migrate_upgrade()
+ with db.engine.connect() as connection:
+ inspector = inspect(connection)
+ assert "source_documents" in inspector.get_table_names()
+ assert "sources" not in inspector.get_table_names()
+ assert (
+ connection.execute(
+ sa.text("SELECT status FROM received_webmentions")
+ ).scalar_one()
+ == "source_removed"
+ )
+ sent_row = connection.execute(
+ sa.text(
+ "SELECT source_uuid, status, linked, webmention_endpoint, "
+ "endpoint_response_status FROM sent_webmentions"
+ )
+ ).one()
+ assert sent_row == (
+ source_uuid,
+ "no_endpoint",
+ 1,
+ "https://target.example/webmention",
+ 202,
+ )
+ assert any(
+ constraint["column_names"] == ["source_target_digest"]
+ for constraint in inspector.get_unique_constraints(
+ "received_webmentions"
+ )
+ )
+ assert any(
+ constraint["column_names"] == ["source_uuid", "target_digest"]
+ for constraint in inspector.get_unique_constraints("sent_webmentions")
+ )
+ assert any(
+ foreign_key["constrained_columns"] == ["source_uuid"]
+ and foreign_key["referred_table"] == "source_documents"
+ for foreign_key in inspector.get_foreign_keys("sent_webmentions")
+ )
+
+ migrate_downgrade(revision="7c38bb1a935e")
+ with db.engine.connect() as connection:
+ inspector = inspect(connection)
+ assert "sources" in inspector.get_table_names()
+ assert (
+ connection.execute(
+ sa.text("SELECT status FROM received_webmentions")
+ ).scalar_one()
+ == "deleted"
+ )
+ assert (
+ connection.execute(
+ sa.text("SELECT status FROM sent_webmentions")
+ ).scalar_one()
+ == "unsupported"
+ )
+ assert any(
+ foreign_key["constrained_columns"] == ["source_id"]
+ and foreign_key["referred_table"] == "sources"
+ for foreign_key in inspector.get_foreign_keys("sent_webmentions")
+ )
def test_mail_cli_sends_to_configured_notification_email(app: Flask) -> None:
diff --git a/tests/test_forms.py b/tests/test_forms.py
index b5b3296..707ac09 100644
--- a/tests/test_forms.py
+++ b/tests/test_forms.py
@@ -12,7 +12,7 @@ from webmentions_ssg.forms import (
ConfirmActionForm,
LoginForm,
MaxURLBytes,
- PublicIPLiteral,
+ RejectNonPublicIPLiteral,
WebmentionSubmissionForm,
)
@@ -303,12 +303,12 @@ def test_allowed_hostname_uses_custom_message(app: Flask) -> None:
def test_public_ip_literal_rejects_ipv6_transition_addresses(address: str) -> None:
form = URLForm(MultiDict({"url": f"https://[{address}]/"}))
with pytest.raises(ValidationError, match="URL must use a public address"):
- PublicIPLiteral()(form, form.url)
+ RejectNonPublicIPLiteral()(form, form.url)
def test_public_ip_literal_accepts_public_ipv6_address() -> None:
form = URLForm(MultiDict({"url": "https://[2606:2800:220:1:248:1893:25c8:1946]/"}))
- PublicIPLiteral()(form, form.url)
+ RejectNonPublicIPLiteral()(form, form.url)
def test_allowed_hostname_handles_invalid_ipv6(app: Flask) -> None:
diff --git a/tests/test_init.py b/tests/test_init.py
index 44375de..f334c88 100644
--- a/tests/test_init.py
+++ b/tests/test_init.py
@@ -32,7 +32,7 @@ def test_importing_views_and_tasks_before_creating_app() -> None:
script = """
from webmentions_ssg import huey
from webmentions_ssg.tasks.scanner import manual_scan_sources
-from webmentions_ssg.tasks.receiver import verify_webmention
+from webmentions_ssg.tasks.verification import verify_webmention
from webmentions_ssg.tasks.sender import send_webmention
from webmentions_ssg.views import webmentions_bp
diff --git a/tests/test_models.py b/tests/test_models.py
index d2b667c..4e785c7 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -16,28 +16,31 @@ from sqlalchemy.orm import Mapped
from webmentions_ssg import db
from webmentions_ssg.models import (
- ReceivedStatus,
ReceivedWebmention,
+ ReceivedWebmentionStatus,
SentWebmention,
- Source,
+ SourceDocument,
User,
- received_url_digest,
- sent_target_digest,
+ source_target_digest,
+ target_digest,
uuid7_to_datetime,
)
def test_uuid_annotations_and_relationships_resolve() -> None:
"""Verify that UUID columns and forward relationships map correctly."""
- for model in (ReceivedWebmention, Source, SentWebmention):
+ for model in (ReceivedWebmention, SourceDocument, SentWebmention):
assert get_type_hints(model)["uuid"] == Mapped[uuid.UUID]
assert sa.inspect(model).columns["uuid"].primary_key
assert (
- sa.inspect(Source).relationships["sent_webmentions"].mapper.class_
+ sa.inspect(SourceDocument).relationships["sent_webmentions"].mapper.class_
is SentWebmention
)
- assert sa.inspect(SentWebmention).relationships["source"].mapper.class_ is Source
+ assert (
+ sa.inspect(SentWebmention).relationships["source"].mapper.class_
+ is SourceDocument
+ )
def test_user_repr() -> None:
@@ -61,14 +64,16 @@ def test_user_password_is_hashed_and_can_be_checked() -> None:
@pytest.mark.parametrize(
("status", "expected"),
[
- (ReceivedStatus.RECEIVED, False),
- (ReceivedStatus.VERIFYING, False),
- (ReceivedStatus.VERIFIED, True),
- (ReceivedStatus.FAILED, False),
- (ReceivedStatus.DELETED, False),
+ (ReceivedWebmentionStatus.RECEIVED, False),
+ (ReceivedWebmentionStatus.VERIFYING, False),
+ (ReceivedWebmentionStatus.VERIFIED, True),
+ (ReceivedWebmentionStatus.FAILED, False),
+ (ReceivedWebmentionStatus.SOURCE_REMOVED, False),
],
)
-def test_received_webmention_verified(status: ReceivedStatus, expected: bool) -> None:
+def test_received_webmention_verified(
+ status: ReceivedWebmentionStatus, expected: bool
+) -> None:
webmention = ReceivedWebmention(
uuid=uuid.uuid7(),
source="https://source.example/post",
@@ -91,7 +96,7 @@ def test_sent_webmention_pending(
desired_revision=desired_revision,
processed_revision=processed_revision,
)
- assert webmention.pending is expected
+ assert webmention.awaiting_processing is expected
def test_sent_webmention_pending_sql_matches_python(app: Flask) -> None:
@@ -99,7 +104,7 @@ def test_sent_webmention_pending_sql_matches_python(app: Flask) -> None:
with app.app_context():
now = datetime.now(UTC)
- source = Source(
+ source = SourceDocument(
path="pending/index.html",
url="https://site.example/pending/",
content_hash="0" * 32,
@@ -119,18 +124,18 @@ def test_sent_webmention_pending_sql_matches_python(app: Flask) -> None:
pending_ids = set(
db.session.scalars(
- sa.select(SentWebmention.uuid).where(SentWebmention.pending)
+ sa.select(SentWebmention.uuid).where(SentWebmention.awaiting_processing)
)
)
for webmention, (_, _, expected) in zip(
source.sent_webmentions, cases, strict=True
):
- assert webmention.pending is expected
+ assert webmention.awaiting_processing is expected
assert (webmention.uuid in pending_ids) is expected
result = db.session.execute(
sa.update(SentWebmention)
- .where(SentWebmention.pending)
+ .where(SentWebmention.awaiting_processing)
.values(attempt_count=1)
)
assert result.rowcount == 3
@@ -156,7 +161,7 @@ def test_uuid7_to_datetime() -> None:
id="received-webmention",
),
pytest.param(
- lambda identifier: Source(
+ lambda identifier: SourceDocument(
uuid=identifier,
path="example/index.html",
url="https://dennisfink.me/blog/example/",
@@ -176,7 +181,9 @@ def test_uuid7_to_datetime() -> None:
],
)
def test_created_at_comes_from_uuid7_timestamp(
- factory: Callable[[uuid.UUID], ReceivedWebmention | Source | SentWebmention],
+ factory: Callable[
+ [uuid.UUID], ReceivedWebmention | SourceDocument | SentWebmention
+ ],
) -> None:
identifier = uuid.uuid7()
model = factory(identifier)
@@ -197,7 +204,7 @@ def test_received_webmention_repr() -> None:
def test_source_repr() -> None:
- source = Source(
+ source = SourceDocument(
path="example/index.html",
url="https://dennisfink.me/blog/example/",
content_hash="0" * 32,
@@ -205,7 +212,7 @@ def test_source_repr() -> None:
last_seen_at=datetime.now(UTC),
revised_at=datetime.now(UTC),
)
- assert repr(source) == "<Source 'https://dennisfink.me/blog/example/'>"
+ assert repr(source) == "<SourceDocument 'https://dennisfink.me/blog/example/'>"
def test_sent_webmention_repr() -> None:
@@ -233,9 +240,9 @@ def test_received_status_uses_non_native_enum() -> None:
status_type = ReceivedWebmention.__table__.c.status.type
assert isinstance(status_type, sa.Enum)
- assert status_type.enum_class is ReceivedStatus
+ assert status_type.enum_class is ReceivedWebmentionStatus
assert status_type.native_enum is False
- assert status_type.enums == [status.value for status in ReceivedStatus]
+ assert status_type.enums == [status.value for status in ReceivedWebmentionStatus]
def test_received_status_round_trips_as_enum(app: Flask) -> None:
@@ -245,7 +252,7 @@ def test_received_status_round_trips_as_enum(app: Flask) -> None:
uuid=identifier,
source="https://source.example/post",
target="https://dennisfink.me/blog/example/",
- status=ReceivedStatus.VERIFIED,
+ status=ReceivedWebmentionStatus.VERIFIED,
)
db.session.add(mention)
db.session.commit()
@@ -261,22 +268,22 @@ def test_received_status_round_trips_as_enum(app: Flask) -> None:
db.session.expunge_all()
loaded = db.session.get(ReceivedWebmention, identifier)
assert loaded is not None
- assert loaded.status is ReceivedStatus.VERIFIED
+ assert loaded.status is ReceivedWebmentionStatus.VERIFIED
def test_received_verification_reset_is_reusable_for_atomic_updates() -> None:
- from webmentions_ssg.models import ReceivedStatus
+ from webmentions_ssg.models import ReceivedWebmentionStatus
mention = ReceivedWebmention(
uuid=uuid.uuid7(),
source="https://source.example/post",
target="https://dennisfink.me/post",
- status=ReceivedStatus.FAILED,
+ status=ReceivedWebmentionStatus.FAILED,
failure_reason="Old error",
recovery_attempts=3,
)
- assert mention.reset_for_verification() is None
- assert mention.status == ReceivedStatus.RECEIVED
+ assert mention.reopen_verification() is None
+ assert mention.status == ReceivedWebmentionStatus.RECEIVED
assert mention.failure_reason is None
assert mention.recovery_attempts == 0
assert mention.updated_at is not None
@@ -288,7 +295,7 @@ def test_reopen_preserves_delivery_history() -> None:
sent_at = datetime.now(UTC)
mention = SentWebmention(
target="https://example.com/post",
- active=True,
+ linked=True,
desired_revision=2,
processed_revision=2,
sent_revision=2,
@@ -297,9 +304,9 @@ def test_reopen_preserves_delivery_history() -> None:
next_retry_at=sent_at,
last_sent_at=sent_at,
)
- assert mention.reopen(3, False) is None
+ assert mention.reset_for_revision(3, False) is None
assert mention.desired_revision == 3
- assert mention.active is False
+ assert mention.linked is False
assert mention.attempt_count == 0
assert mention.next_retry_at is None
assert mention.status == SentWebmentionStatus.SENT
@@ -312,31 +319,31 @@ def test_resend_requeues_current_revision_without_losing_send_history() -> None:
sent_at = datetime.now(UTC)
mention = SentWebmention(
target="https://example.com/post",
- active=True,
+ linked=True,
desired_revision=3,
processed_revision=3,
sent_revision=2,
status=SentWebmentionStatus.FAILED,
failure_reason="Previous failure",
- endpoint="https://example.com/webmention",
- response_status=HTTPStatus.SERVICE_UNAVAILABLE,
+ webmention_endpoint="https://example.com/webmention",
+ endpoint_response_status=HTTPStatus.SERVICE_UNAVAILABLE,
status_url="https://example.com/status",
attempt_count=3,
next_retry_at=sent_at,
last_attempted_at=sent_at,
last_sent_at=sent_at,
)
- assert not mention.pending
+ assert not mention.awaiting_processing
- assert mention.resend() is None
+ assert mention.clear_result_for_resend() is None
assert mention.desired_revision == 3
- assert mention.active is True
- assert mention.pending
+ assert mention.linked is True
+ assert mention.awaiting_processing
assert mention.processed_revision is None
assert mention.status is None
assert mention.failure_reason is None
- assert mention.endpoint is None
- assert mention.response_status is None
+ assert mention.webmention_endpoint is None
+ assert mention.endpoint_response_status is None
assert mention.status_url is None
assert mention.attempt_count == 0
assert mention.next_retry_at is None
@@ -346,8 +353,8 @@ def test_resend_requeues_current_revision_without_losing_send_history() -> None:
def test_received_pair_fingerprint_is_unambiguous() -> None:
- assert received_url_digest("a", "bc") != received_url_digest("ab", "c")
- assert received_url_digest("a", "b") != received_url_digest("b", "a")
+ assert source_target_digest("a", "bc") != source_target_digest("ab", "c")
+ assert source_target_digest("a", "b") != source_target_digest("b", "a")
def test_models_hash_url_fields_when_created_or_changed() -> None:
@@ -356,16 +363,22 @@ def test_models_hash_url_fields_when_created_or_changed() -> None:
source="https://source.example/a",
target="https://site.example/b",
)
- assert received.url_digest == received_url_digest(received.source, received.target)
+ assert received.source_target_digest == source_target_digest(
+ received.source, received.target
+ )
received.source = "https://source.example/c"
- assert received.url_digest == received_url_digest(received.source, received.target)
+ assert received.source_target_digest == source_target_digest(
+ received.source, received.target
+ )
received.target = "https://site.example/d"
- assert received.url_digest == received_url_digest(received.source, received.target)
+ assert received.source_target_digest == source_target_digest(
+ received.source, received.target
+ )
sent = SentWebmention(target="https://site.example/a", desired_revision=1)
- assert sent.target_digest == sent_target_digest(sent.target)
+ assert sent.target_digest == target_digest(sent.target)
sent.target = "https://site.example/b"
- assert sent.target_digest == sent_target_digest(sent.target)
+ assert sent.target_digest == target_digest(sent.target)
def test_long_received_pair_can_be_stored_with_unique_digest(app: Flask) -> None:
@@ -380,8 +393,8 @@ def test_long_received_pair_can_be_stored_with_unique_digest(app: Flask) -> None
db.session.commit()
match = db.session.scalar(
sa.select(ReceivedWebmention).where(
- ReceivedWebmention.url_digest
- == received_url_digest(long_source, long_target)
+ ReceivedWebmention.source_target_digest
+ == source_target_digest(long_source, long_target)
)
)
assert match is not None
@@ -403,7 +416,7 @@ def test_long_sent_targets_enforce_uniqueness_without_indexing_url_text(
now = datetime.now(UTC)
long_target = "https://destination.example/" + "a" * 4000
with app.app_context():
- source = Source(
+ source = SourceDocument(
path="long/index.html",
url="https://example.com/long",
content_hash="0" * 32,
@@ -416,9 +429,7 @@ def test_long_sent_targets_enforce_uniqueness_without_indexing_url_text(
)
db.session.add(source)
db.session.commit()
- assert source.sent_webmentions[0].target_digest == sent_target_digest(
- long_target
- )
+ assert source.sent_webmentions[0].target_digest == target_digest(long_target)
source.sent_webmentions.append(
SentWebmention(target=long_target, desired_revision=1)
diff --git a/tests/test_net.py b/tests/test_net.py
index c7c65ba..24785ee 100644
--- a/tests/test_net.py
+++ b/tests/test_net.py
@@ -338,9 +338,9 @@ def test_public_addresses_rejects_empty_dns_result() -> None:
)
def test_is_retryable_status(app: Flask, status: int, expected: bool) -> None:
_ = app
- from webmentions_ssg.tasks import discovery
+ from webmentions_ssg.tasks import endpoint_discovery
- assert discovery.is_retryable_status(status) is expected
+ assert endpoint_discovery.is_retryable_status(status) is expected
@pytest.mark.parametrize(
diff --git a/tests/views/helpers.py b/tests/views/helpers.py
index 2da2ace..3c74a1b 100644
--- a/tests/views/helpers.py
+++ b/tests/views/helpers.py
@@ -17,7 +17,7 @@ from webmentions_ssg.models import (
ReceivedWebmention,
SentWebmention,
SentWebmentionStatus,
- Source,
+ SourceDocument,
User,
)
@@ -64,7 +64,7 @@ def create_sent_source(app: Flask) -> uuid.UUID:
now = datetime.now(UTC)
with app.app_context():
- source = Source(
+ source = SourceDocument(
path="blog/example/index.html",
url="https://dennisfink.me/blog/example/",
content_hash="0" * 32,
@@ -77,24 +77,24 @@ def create_sent_source(app: Flask) -> uuid.UUID:
[
SentWebmention(
target="https://example.com/b",
- active=True,
+ linked=True,
desired_revision=2,
processed_revision=2,
sent_revision=2,
status=SentWebmentionStatus.SENT,
- endpoint="https://example.com/webmention",
- response_status=HTTPStatus.ACCEPTED,
+ webmention_endpoint="https://example.com/webmention",
+ endpoint_response_status=HTTPStatus.ACCEPTED,
),
SentWebmention(
target="https://example.com/a",
- active=True,
+ linked=True,
desired_revision=2,
processed_revision=2,
sent_revision=1,
status=SentWebmentionStatus.FAILED,
failure_reason="Webmention endpoint returned HTTP 400",
- endpoint="https://example.com/webmention",
- response_status=HTTPStatus.BAD_REQUEST,
+ webmention_endpoint="https://example.com/webmention",
+ endpoint_response_status=HTTPStatus.BAD_REQUEST,
),
]
)
@@ -161,7 +161,7 @@ def create_resendable_sent_webmention(app: Flask) -> tuple[uuid.UUID, uuid.UUID]
now = datetime.now(UTC)
with app.app_context():
- source = Source(
+ source = SourceDocument(
path="blog/resend/index.html",
url="https://dennisfink.me/blog/resend/",
content_hash="1" * 32,
@@ -171,14 +171,14 @@ def create_resendable_sent_webmention(app: Flask) -> tuple[uuid.UUID, uuid.UUID]
)
webmention = SentWebmention(
target="https://example.com/resend",
- active=True,
+ linked=True,
desired_revision=3,
processed_revision=3,
sent_revision=2,
status=SentWebmentionStatus.FAILED,
failure_reason="Previous failure",
- endpoint="https://example.com/webmention",
- response_status=HTTPStatus.INTERNAL_SERVER_ERROR,
+ webmention_endpoint="https://example.com/webmention",
+ endpoint_response_status=HTTPStatus.INTERNAL_SERVER_ERROR,
status_url="https://example.com/webmention/status/123",
)
source.sent_webmentions.append(webmention)
@@ -194,7 +194,7 @@ def create_outgoing(
) -> tuple[uuid.UUID, uuid.UUID]:
now = datetime.now(UTC)
with app.app_context():
- source = Source(
+ source = SourceDocument(
path="blog/post/index.html",
url="https://source.example/blog/post",
content_hash="0" * 32,
@@ -204,10 +204,12 @@ def create_outgoing(
)
mention = SentWebmention(
target="https://example.com/article",
- active=True,
+ linked=True,
desired_revision=1,
status_url=status_url,
- response_status=HTTPStatus.CREATED if status_url is not None else None,
+ endpoint_response_status=(
+ HTTPStatus.CREATED if status_url is not None else None
+ ),
)
source.sent_webmentions.append(mention)
db.session.add(source)
diff --git a/tests/views/test_admin.py b/tests/views/test_admin.py
index 90d406b..fa5575b 100644
--- a/tests/views/test_admin.py
+++ b/tests/views/test_admin.py
@@ -331,8 +331,8 @@ def test_resend_sent_webmention_reopens_current_revision(
assert webmention.sent_revision == 2
assert webmention.status is None
assert webmention.failure_reason is None
- assert webmention.endpoint is None
- assert webmention.response_status is None
+ assert webmention.webmention_endpoint is None
+ assert webmention.endpoint_response_status is None
assert webmention.status_url is None
send_webmention.assert_called_once_with(webmention_identifier)
diff --git a/tests/views/test_endpoint.py b/tests/views/test_endpoint.py
index 52ef77d..88b665f 100644
--- a/tests/views/test_endpoint.py
+++ b/tests/views/test_endpoint.py
@@ -253,11 +253,11 @@ def test_endpoint_rejects_digest_collision(
)
db.session.add(existing)
db.session.commit()
- digest = existing.url_digest
+ digest = existing.source_target_digest
form.source.data = "https://source.example/different"
monkeypatch.setattr(
- views_module, "received_url_digest", lambda source, target: digest
+ views_module, "source_target_digest", lambda source, target: digest
)
response = client.post("/endpoint")
diff --git a/webmentions_ssg/config.py b/webmentions_ssg/config.py
index 7d09e7e..15667ab 100644
--- a/webmentions_ssg/config.py
+++ b/webmentions_ssg/config.py
@@ -36,7 +36,7 @@ class DefaultConfig:
MAX_CONTENT_LENGTH = 64 * 1024
# Independent UTF-8 byte limit for each submitted source/target URL.
MAX_WEBMENTION_URL_BYTES = 8192
- # Purge terminal failed/deleted received Webmentions after 30 days.
+ # Purge terminal failed/source-removed received Webmentions after 30 days.
RECEIVED_RETENTION_DAYS = 30
RECEIVED_RETENTION_SCHEDULE = "0 3 * * *"
MAX_REDIRECTS = 20
diff --git a/webmentions_ssg/extensions.py b/webmentions_ssg/extensions.py
index c1cf396..d515d24 100644
--- a/webmentions_ssg/extensions.py
+++ b/webmentions_ssg/extensions.py
@@ -13,7 +13,7 @@ from flask_sqlalchemy import SQLAlchemy
from flask_wtf.csrf import CSRFProtect
from sqlalchemy.orm import DeclarativeBase
-from .tasks.extension import Huey
+from .tasks.extension import FlaskHuey
class Base(DeclarativeBase):
@@ -24,6 +24,6 @@ csrf = CSRFProtect()
bootstrap = Bootstrap5()
db = SQLAlchemy(model_class=Base)
migrate = Migrate()
-huey = Huey()
+huey = FlaskHuey()
mail = Mail()
limiter = Limiter(key_func=get_remote_address)
diff --git a/webmentions_ssg/forms.py b/webmentions_ssg/forms.py
index c8ad0ba..1ce591d 100644
--- a/webmentions_ssg/forms.py
+++ b/webmentions_ssg/forms.py
@@ -104,7 +104,7 @@ class AllowedTargetHostname:
raise ValidationError(self.message or field.gettext("Invalid input."))
-class PublicIPLiteral:
+class RejectNonPublicIPLiteral:
"""Reject non-public IP literals without performing DNS in the web worker."""
def __call__(self, form: BaseForm, field: Field) -> None:
@@ -138,7 +138,12 @@ class WebmentionSubmissionForm(FlaskForm):
source = StringField(
"source",
- validators=[InputRequired(), MaxURLBytes(), StrictHTTPURL(), PublicIPLiteral()],
+ validators=[
+ InputRequired(),
+ MaxURLBytes(),
+ StrictHTTPURL(),
+ RejectNonPublicIPLiteral(),
+ ],
)
target = StringField(
"target",
diff --git a/webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py b/webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py
new file mode 100644
index 0000000..23ff56a
--- /dev/null
+++ b/webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py
@@ -0,0 +1,178 @@
+# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+"""Clarify source-document and Webmention lifecycle names.
+
+Revision ID: 9a4e0c8211d6
+Revises: 7c38bb1a935e
+"""
+
+import sqlalchemy as sa
+from alembic import op
+
+revision = "9a4e0c8211d6"
+down_revision = "7c38bb1a935e"
+branch_labels = None
+depends_on = None
+
+
+_OLD_RECEIVED_STATUS = sa.Enum(
+ "received",
+ "verifying",
+ "verified",
+ "failed",
+ "deleted",
+ name="received_webmention_status",
+ native_enum=False,
+)
+_NEW_RECEIVED_STATUS = sa.Enum(
+ "received",
+ "verifying",
+ "verified",
+ "failed",
+ "source_removed",
+ name="received_webmention_status",
+ native_enum=False,
+)
+
+
+def upgrade() -> None:
+ # RENAME TABLE retains existing source UUIDs and updates referencing FKs.
+ op.rename_table("sources", "source_documents")
+
+ with op.batch_alter_table("received_webmentions") as batch:
+ batch.drop_constraint("uq_webmention_url_digest", type_="unique")
+ batch.alter_column(
+ "url_digest",
+ new_column_name="source_target_digest",
+ existing_type=sa.String(64),
+ existing_nullable=False,
+ )
+ # The new enum string is 14 characters, not the old VARCHAR(9).
+ batch.alter_column(
+ "status",
+ existing_type=_OLD_RECEIVED_STATUS,
+ type_=_NEW_RECEIVED_STATUS,
+ existing_nullable=False,
+ )
+
+ with op.batch_alter_table("received_webmentions") as batch:
+ batch.create_unique_constraint(
+ "uq_webmention_source_target_digest", ["source_target_digest"]
+ )
+
+ with op.batch_alter_table("sent_webmentions") as batch:
+ batch.drop_index("ix_sent_webmentions_source_id")
+ batch.drop_constraint("uq_sent_webmention_source_target_digest", type_="unique")
+ batch.alter_column(
+ "source_id",
+ new_column_name="source_uuid",
+ existing_type=sa.Uuid(),
+ existing_nullable=False,
+ )
+ batch.alter_column(
+ "active",
+ new_column_name="linked",
+ existing_type=sa.Boolean(),
+ existing_nullable=False,
+ )
+ batch.alter_column(
+ "endpoint",
+ new_column_name="webmention_endpoint",
+ existing_type=sa.Text(),
+ existing_nullable=True,
+ )
+ batch.alter_column(
+ "response_status",
+ new_column_name="endpoint_response_status",
+ existing_type=sa.Integer(),
+ existing_nullable=True,
+ )
+
+ with op.batch_alter_table("sent_webmentions") as batch:
+ batch.create_unique_constraint(
+ "uq_sent_webmention_source_uuid_target_digest",
+ ["source_uuid", "target_digest"],
+ )
+
+ op.create_index(
+ "ix_sent_webmentions_source_uuid", "sent_webmentions", ["source_uuid"]
+ )
+
+ op.execute(
+ "UPDATE received_webmentions SET status = 'source_removed' "
+ "WHERE status = 'deleted'"
+ )
+ op.execute(
+ "UPDATE sent_webmentions SET status = 'no_endpoint' "
+ "WHERE status = 'unsupported'"
+ )
+
+
+def downgrade() -> None:
+ op.execute(
+ "UPDATE received_webmentions SET status = 'deleted' "
+ "WHERE status = 'source_removed'"
+ )
+ op.execute(
+ "UPDATE sent_webmentions SET status = 'unsupported' "
+ "WHERE status = 'no_endpoint'"
+ )
+
+ with op.batch_alter_table("sent_webmentions") as batch:
+ batch.drop_index("ix_sent_webmentions_source_uuid")
+ batch.drop_constraint(
+ "uq_sent_webmention_source_uuid_target_digest", type_="unique"
+ )
+ batch.alter_column(
+ "source_uuid",
+ new_column_name="source_id",
+ existing_type=sa.Uuid(),
+ existing_nullable=False,
+ )
+ batch.alter_column(
+ "linked",
+ new_column_name="active",
+ existing_type=sa.Boolean(),
+ existing_nullable=False,
+ )
+ batch.alter_column(
+ "webmention_endpoint",
+ new_column_name="endpoint",
+ existing_type=sa.Text(),
+ existing_nullable=True,
+ )
+ batch.alter_column(
+ "endpoint_response_status",
+ new_column_name="response_status",
+ existing_type=sa.Integer(),
+ existing_nullable=True,
+ )
+
+ with op.batch_alter_table("sent_webmentions") as batch:
+ batch.create_unique_constraint(
+ "uq_sent_webmention_source_target_digest", ["source_id", "target_digest"]
+ )
+
+ op.create_index("ix_sent_webmentions_source_id", "sent_webmentions", ["source_id"])
+
+ with op.batch_alter_table("received_webmentions") as batch:
+ batch.drop_constraint("uq_webmention_source_target_digest", type_="unique")
+ batch.alter_column(
+ "source_target_digest",
+ new_column_name="url_digest",
+ existing_type=sa.String(64),
+ existing_nullable=False,
+ )
+ batch.alter_column(
+ "status",
+ existing_type=_NEW_RECEIVED_STATUS,
+ type_=_OLD_RECEIVED_STATUS,
+ existing_nullable=False,
+ )
+
+ with op.batch_alter_table("received_webmentions") as batch:
+ batch.create_unique_constraint("uq_webmention_url_digest", ["url_digest"])
+
+ op.rename_table("source_documents", "sources")
diff --git a/webmentions_ssg/migrations/versions/d845aa7fbc19_portable_url_fingerprints.py b/webmentions_ssg/migrations/versions/d845aa7fbc19_portable_url_fingerprints.py
index 41c5376..8518b15 100644
--- a/webmentions_ssg/migrations/versions/d845aa7fbc19_portable_url_fingerprints.py
+++ b/webmentions_ssg/migrations/versions/d845aa7fbc19_portable_url_fingerprints.py
@@ -11,7 +11,8 @@ Revises: c0272f25ce17
import sqlalchemy as sa
from alembic import op
-from webmentions_ssg.models import received_url_digest, sent_target_digest
+from webmentions_ssg.models import source_target_digest as received_url_digest
+from webmentions_ssg.models import target_digest as sent_target_digest
revision = "d845aa7fbc19"
down_revision = "c0272f25ce17"
diff --git a/webmentions_ssg/models.py b/webmentions_ssg/models.py
index 33f27d1..2b375dd 100644
--- a/webmentions_ssg/models.py
+++ b/webmentions_ssg/models.py
@@ -32,21 +32,21 @@ from werkzeug.security import check_password_hash, generate_password_hash
from .extensions import Base
-class ReceivedStatus(StrEnum):
+class ReceivedWebmentionStatus(StrEnum):
"""Persisted lifecycle state of an incoming Webmention."""
RECEIVED = "received"
VERIFYING = "verifying"
VERIFIED = "verified"
FAILED = "failed"
- DELETED = "deleted"
+ SOURCE_REMOVED = "source_removed"
class SentWebmentionStatus(StrEnum):
"""Represent the outcome of a Webmention send attempt."""
SENT = "sent"
- UNSUPPORTED = "unsupported"
+ NO_ENDPOINT = "no_endpoint"
FAILED = "failed"
@@ -110,25 +110,25 @@ class ReceivedWebmention(Base):
source: Mapped[str] = mapped_column(Text(), nullable=False)
target: Mapped[str] = mapped_column(Text(), nullable=False)
- url_digest: Mapped[str] = mapped_column(String(64), nullable=False)
+ source_target_digest: Mapped[str] = mapped_column(String(64), nullable=False)
@validates("source", "target")
- def _update_url_digest(self, key: str, value: str) -> str:
+ def _refresh_url_digest(self, key: str, value: str) -> str:
source = value if key == "source" else self.__dict__.get("source")
target = value if key == "target" else self.__dict__.get("target")
if source is not None and target is not None:
- self.url_digest = received_url_digest(source, target)
+ self.source_target_digest = source_target_digest(source, target)
return value
- status: Mapped[ReceivedStatus] = mapped_column(
+ status: Mapped[ReceivedWebmentionStatus] = mapped_column(
Enum(
- ReceivedStatus,
+ ReceivedWebmentionStatus,
name="received_webmention_status",
values_callable=lambda enum_type: [member.value for member in enum_type],
native_enum=False,
),
nullable=False,
- default=ReceivedStatus.RECEIVED,
+ default=ReceivedWebmentionStatus.RECEIVED,
)
# Counts stale-row requeues, not Huey's bounded in-task retries. A fresh
# explicit submission resets this counter.
@@ -151,7 +151,9 @@ class ReceivedWebmention(Base):
)
__table_args__ = (
- UniqueConstraint("url_digest", name="uq_webmention_url_digest"),
+ UniqueConstraint(
+ "source_target_digest", name="uq_webmention_source_target_digest"
+ ),
Index("ix_received_webmentions_status_updated_at", "status", "updated_at"),
)
@@ -160,35 +162,35 @@ class ReceivedWebmention(Base):
return f"<ReceivedWebmention {self.source!r} -> {self.target!r}>"
@staticmethod
- def verification_reset_values(
- *, at: datetime, recoveries: int = 0
+ def reopen_verification_values(
+ *, at: datetime, recovery_attempts: int = 0
) -> dict[str, object]:
"""Return the columns to reset when verification is explicitly reopened.
:param at: Timestamp to record for the newly opened verification.
- :param recoveries: Number of stale-lease recovery attempts to retain.
+ :param recovery_attempts: Number of stale-lease recovery attempts to retain.
:returns: Column values for resetting the verification state.
"""
return {
- "status": ReceivedStatus.RECEIVED,
+ "status": ReceivedWebmentionStatus.RECEIVED,
"failure_reason": None,
- "recovery_attempts": recoveries,
+ "recovery_attempts": recovery_attempts,
"updated_at": at,
}
- def reset_for_verification(self) -> None:
+ def reopen_verification(self) -> None:
"""Reopen an existing row for manual verification.
Clear the previous outcome and restore the received state with a fresh
timestamp.
"""
- for key, value in self.verification_reset_values(at=datetime.now(UTC)).items():
+ for key, value in self.reopen_verification_values(at=datetime.now(UTC)).items():
setattr(self, key, value)
@property
def verified(self) -> bool:
"""Return whether the Webmention has been successfully verified."""
- return self.status == ReceivedStatus.VERIFIED
+ return self.status == ReceivedWebmentionStatus.VERIFIED
@property
def created_at(self) -> datetime:
@@ -196,10 +198,10 @@ class ReceivedWebmention(Base):
return uuid7_to_datetime(self.uuid)
-class Source(Base):
+class SourceDocument(Base):
"""Represent a generated source document containing outgoing Webmentions."""
- __tablename__ = "sources"
+ __tablename__ = "source_documents"
uuid: Mapped[UUID] = mapped_column(
Uuid(as_uuid=True), primary_key=True, default=uuid7
@@ -227,7 +229,7 @@ class Source(Base):
def __repr__(self) -> str:
"""Represent the source by its public URL."""
- return f"<Source {self.url!r}>"
+ return f"<SourceDocument {self.url!r}>"
@property
def created_at(self) -> datetime:
@@ -244,9 +246,9 @@ class SentWebmention(Base):
Uuid(as_uuid=True), primary_key=True, default=uuid7
)
- source_id: Mapped[UUID] = mapped_column(
+ source_uuid: Mapped[UUID] = mapped_column(
Uuid(as_uuid=True),
- ForeignKey("sources.uuid", ondelete="CASCADE"),
+ ForeignKey("source_documents.uuid", ondelete="CASCADE"),
nullable=False,
index=True,
)
@@ -256,10 +258,10 @@ class SentWebmention(Base):
@validates("target")
def _update_target_digest(self, key: str, value: str) -> str:
- self.target_digest = sent_target_digest(value)
+ self.target_digest = target_digest(value)
return value
- active: Mapped[bool] = mapped_column(Boolean(), nullable=False, default=True)
+ linked: Mapped[bool] = mapped_column(Boolean(), nullable=False, default=True)
desired_revision: Mapped[int] = mapped_column(Integer(), nullable=False)
processed_revision: Mapped[int | None] = mapped_column(
@@ -284,8 +286,10 @@ class SentWebmention(Base):
Text(), nullable=True, default=None
)
- endpoint: Mapped[str | None] = mapped_column(Text(), nullable=True, default=None)
- response_status: Mapped[int | None] = mapped_column(
+ webmention_endpoint: Mapped[str | None] = mapped_column(
+ Text(), nullable=True, default=None
+ )
+ endpoint_response_status: Mapped[int | None] = mapped_column(
Integer(), nullable=True, default=None
)
status_url: Mapped[str | None] = mapped_column(Text(), nullable=True, default=None)
@@ -303,11 +307,13 @@ class SentWebmention(Base):
DateTime(timezone=True), nullable=True, default=None
)
- source: Mapped[Source] = relationship(back_populates="sent_webmentions")
+ source: Mapped[SourceDocument] = relationship(back_populates="sent_webmentions")
__table_args__ = (
UniqueConstraint(
- "source_id", "target_digest", name="uq_sent_webmention_source_target_digest"
+ "source_uuid",
+ "target_digest",
+ name="uq_sent_webmention_source_uuid_target_digest",
),
)
@@ -315,41 +321,41 @@ class SentWebmention(Base):
"""Represent the sent Webmention by its target URL."""
return f"<SentWebmention {self.target!r}>"
- def reopen(self, revision: int, active: bool) -> None:
+ def reset_for_revision(self, revision: int, linked: bool) -> None:
"""Reopen delivery for a revision while preserving send history.
:param revision: Source revision to make the desired delivery revision.
- :param active: Whether the target still appears in the current source.
+ :param linked: Whether the target still appears in the current source.
"""
self.desired_revision = revision
- self.active = active
+ self.linked = linked
self.attempt_count = 0
self.next_retry_at = None
- def resend(self) -> None:
+ def clear_result_for_resend(self) -> None:
"""Retry the current revision, clearing its previous delivery result.
Reset attempt and response state without changing the desired source revision.
"""
- self.reopen(self.desired_revision, self.active)
+ self.reset_for_revision(self.desired_revision, self.linked)
self.processed_revision = None
self.status = None
self.failure_reason = None
- self.endpoint = None
- self.response_status = None
+ self.webmention_endpoint = None
+ self.endpoint_response_status = None
self.status_url = None
@hybrid_property
- def pending(self) -> bool:
+ def awaiting_processing(self) -> bool:
"""Return whether the Webmention has an unprocessed source revision."""
return (
self.processed_revision is None
or self.processed_revision < self.desired_revision
)
- @pending.inplace.expression
+ @awaiting_processing.inplace.expression
@classmethod
- def _pending_expression(cls) -> sa.ColumnElement[bool]:
+ def _awaiting_processing_expression(cls) -> sa.ColumnElement[bool]:
"""Express pending-revision status in database queries.
:returns: SQLAlchemy expression selecting unprocessed source revisions.
@@ -374,7 +380,7 @@ def uuid7_to_datetime(identifier: UUID) -> datetime:
return datetime.fromtimestamp(identifier.time / 1000, tz=UTC)
-def received_url_digest(source: str, target: str) -> str:
+def source_target_digest(source: str, target: str) -> str:
"""Fingerprint an unambiguous, ordered source/target pair.
:param source: Webmention source URL.
@@ -387,7 +393,7 @@ def received_url_digest(source: str, target: str) -> str:
return sha256(encoded).hexdigest()
-def sent_target_digest(target: str) -> str:
+def target_digest(target: str) -> str:
"""Fingerprint an outgoing target (unique within each source ID).
:param target: Outgoing Webmention target URL.
diff --git a/webmentions_ssg/tasks/__init__.py b/webmentions_ssg/tasks/__init__.py
index c744b49..37ab4d2 100644
--- a/webmentions_ssg/tasks/__init__.py
+++ b/webmentions_ssg/tasks/__init__.py
@@ -4,6 +4,6 @@
"""Expose the background task queue integration."""
-from .extension import Huey
+from .extension import FlaskHuey
-__all__ = ["Huey"]
+__all__ = ["FlaskHuey"]
diff --git a/webmentions_ssg/tasks/consumer.py b/webmentions_ssg/tasks/consumer.py
index c24a883..7991b6a 100644
--- a/webmentions_ssg/tasks/consumer.py
+++ b/webmentions_ssg/tasks/consumer.py
@@ -8,11 +8,11 @@ from huey import Huey, crontab
from .. import create_app
from ..extensions import huey as queue
-from . import notifications, receiver, retention, scanner
+from . import notifications, retention, scanner, verification
-def create_consumer() -> Huey:
- """Create and configure the Huey consumer.
+def create_huey() -> Huey:
+ """Create and configure the Huey instance for the task worker.
The application is initialized and the periodic scanner, notification,
verification recovery and retention tasks are registered.
@@ -23,8 +23,8 @@ def create_consumer() -> Huey:
for config_key, task in (
("SOURCE_SCAN_SCHEDULE", scanner.scan_sources),
- ("VERIFICATION_RECOVERY_SCHEDULE", receiver.recover_stale_verifications),
- ("DIGEST_SCHEDULE", notifications.send_webmention_digest),
+ ("VERIFICATION_RECOVERY_SCHEDULE", verification.recover_stale_verifications),
+ ("DIGEST_SCHEDULE", notifications.email_verified_digest),
("RECEIVED_RETENTION_SCHEDULE", retention.purge_old_received_webmentions),
):
schedule = crontab(*app.config[config_key].split(), strict=True)
@@ -33,4 +33,4 @@ def create_consumer() -> Huey:
return queue.huey
-huey = create_consumer()
+huey = create_huey()
diff --git a/webmentions_ssg/tasks/discovery.py b/webmentions_ssg/tasks/endpoint_discovery.py
index c683cb0..c683cb0 100644
--- a/webmentions_ssg/tasks/discovery.py
+++ b/webmentions_ssg/tasks/endpoint_discovery.py
diff --git a/webmentions_ssg/tasks/extension.py b/webmentions_ssg/tasks/extension.py
index faed364..3f172f4 100644
--- a/webmentions_ssg/tasks/extension.py
+++ b/webmentions_ssg/tasks/extension.py
@@ -4,8 +4,6 @@
"""Integrate Huey tasks with Flask application contexts."""
-from __future__ import annotations
-
from collections.abc import Callable
from functools import update_wrapper, wraps
from typing import Any
@@ -100,7 +98,7 @@ class _DeferredTask:
def __init__(
self,
- extension: Huey,
+ extension: FlaskHuey,
func: Callable[..., Any],
args: tuple[Any, ...],
kwargs: dict[str, Any],
@@ -152,7 +150,7 @@ class _DeferredTask:
return getattr(self._bound_task(), name)
-class Huey:
+class FlaskHuey:
"""Provide Flask integration for a Huey instance.
The extension initializes a Huey backend from the Flask configuration and
diff --git a/webmentions_ssg/tasks/notifications.py b/webmentions_ssg/tasks/notifications.py
index eb540de..c503e1f 100644
--- a/webmentions_ssg/tasks/notifications.py
+++ b/webmentions_ssg/tasks/notifications.py
@@ -11,10 +11,10 @@ from flask import current_app
from flask_mail import Message
from ..extensions import db, huey, mail
-from ..models import ReceivedStatus, ReceivedWebmention
+from ..models import ReceivedWebmention, ReceivedWebmentionStatus
-def send_webmention_digest() -> None:
+def email_verified_digest() -> None:
"""Send one digest of verified, previously unreported Webmentions.
Acquire the digest lock before notifying recipients about previously unreported
@@ -38,7 +38,7 @@ def _send_digest_locked() -> None:
cutoff = datetime.now(UTC)
conditions = (
- ReceivedWebmention.status == ReceivedStatus.VERIFIED,
+ ReceivedWebmention.status == ReceivedWebmentionStatus.VERIFIED,
ReceivedWebmention.notification_sent_at.is_(None),
ReceivedWebmention.updated_at <= cutoff,
)
diff --git a/webmentions_ssg/tasks/retention.py b/webmentions_ssg/tasks/retention.py
index 2c35cc7..b882493 100644
--- a/webmentions_ssg/tasks/retention.py
+++ b/webmentions_ssg/tasks/retention.py
@@ -11,7 +11,7 @@ from flask import current_app
from ..db_helpers import rows_affected
from ..extensions import db
-from ..models import ReceivedStatus, ReceivedWebmention
+from ..models import ReceivedWebmention, ReceivedWebmentionStatus
def purge_old_received_webmentions() -> int:
@@ -33,7 +33,10 @@ def purge_old_received_webmentions() -> int:
result = db.session.execute(
sa.delete(ReceivedWebmention).where(
ReceivedWebmention.status.in_(
- (ReceivedStatus.FAILED, ReceivedStatus.DELETED)
+ (
+ ReceivedWebmentionStatus.FAILED,
+ ReceivedWebmentionStatus.SOURCE_REMOVED,
+ )
),
ReceivedWebmention.updated_at < cutoff,
)
diff --git a/webmentions_ssg/tasks/scanner.py b/webmentions_ssg/tasks/scanner.py
index 034b2cf..fb0c770 100644
--- a/webmentions_ssg/tasks/scanner.py
+++ b/webmentions_ssg/tasks/scanner.py
@@ -14,13 +14,13 @@ from huey.exceptions import RetryTask, TaskLockedException
from sqlalchemy.orm import selectinload
from ..extensions import db, huey
-from ..models import SentWebmention, Source
+from ..models import SentWebmention, SourceDocument
from ..net import is_http_url
from .sender import send_webmention
from .source_parser import ScannedSource, SourceScanError, scan_source_file
-def build_source(scanned: ScannedSource, scan_time: datetime) -> Source:
+def build_source(scanned: ScannedSource, scan_time: datetime) -> SourceDocument:
"""Build a source model from a newly discovered document.
A sent Webmention is built for each discovered target at the initial source
@@ -30,7 +30,7 @@ def build_source(scanned: ScannedSource, scan_time: datetime) -> Source:
:param scan_time: Time at which the source was discovered.
:returns: Newly built source model.
"""
- source = Source(
+ source = SourceDocument(
path=scanned.path,
url=scanned.url,
content_hash=scanned.content_hash,
@@ -42,15 +42,15 @@ def build_source(scanned: ScannedSource, scan_time: datetime) -> Source:
for target in scanned.targets:
source.sent_webmentions.append(
- SentWebmention(target=target, active=True, desired_revision=1)
+ SentWebmention(target=target, linked=True, desired_revision=1)
)
return source
def apply_scan_to_source(
- source: Source, scanned: ScannedSource, scan_time: datetime
-) -> Source:
+ source: SourceDocument, scanned: ScannedSource, scan_time: datetime
+) -> SourceDocument:
"""Update an existing source from newly scanned data.
A changed or previously deleted source receives a new revision. Existing sent
@@ -82,16 +82,18 @@ def apply_scan_to_source(
existing = {webmention.target: webmention for webmention in source.sent_webmentions}
for webmention in existing.values():
- webmention.reopen(source.revision, webmention.target in scanned.targets)
+ webmention.reset_for_revision(
+ source.revision, webmention.target in scanned.targets
+ )
- if not webmention.active and webmention.sent_revision is None:
+ if not webmention.linked and webmention.sent_revision is None:
webmention.processed_revision = source.revision
for target in scanned.targets:
if target not in existing:
source.sent_webmentions.append(
SentWebmention(
- target=target, active=True, desired_revision=source.revision
+ target=target, linked=True, desired_revision=source.revision
)
)
@@ -127,7 +129,7 @@ class TreeScanResult:
def reconcile_source_tree(
root: Path,
base_url: str | None,
- sources_by_path: dict[str, Source],
+ sources_by_path: dict[str, SourceDocument],
paths_by_url: dict[str, str],
scan_time: datetime,
) -> TreeScanResult:
@@ -197,14 +199,16 @@ def reconcile_source_tree(
def mark_missing_sources_deleted(
- sources_by_path: dict[str, Source], seen_paths: frozenset[str], scan_time: datetime
+ sources_by_path: dict[str, SourceDocument],
+ seen_paths: frozenset[str],
+ scan_time: datetime,
) -> int:
- """Mark absent, previously active sources deleted and return their count.
+ """Mark absent, previously present sources deleted and return their count.
:param sources_by_path: Known source records indexed by relative path.
:param seen_paths: Paths found during this scan, including failed parses.
:param scan_time: Timestamp to record for sources newly marked missing.
- :returns: Number of previously active sources marked as deleted.
+ :returns: Number of previously linked sources marked as deleted.
"""
marked = 0
for path, source in sources_by_path.items():
@@ -217,7 +221,7 @@ def mark_missing_sources_deleted(
marked += 1
for webmention in source.sent_webmentions:
- webmention.reopen(source.revision, False)
+ webmention.reset_for_revision(source.revision, False)
if webmention.sent_revision is None:
webmention.processed_revision = source.revision
@@ -235,7 +239,7 @@ def enqueue_due_sends(scan_time: datetime) -> int:
for identifier in db.session.scalars(
sa.select(SentWebmention.uuid)
.where(
- SentWebmention.pending,
+ SentWebmention.awaiting_processing,
sa.or_(
SentWebmention.next_retry_at.is_(None),
SentWebmention.next_retry_at <= scan_time,
@@ -273,7 +277,9 @@ def _scan_and_enqueue() -> None:
sources_by_path = {
source.path: source
for source in db.session.scalars(
- sa.select(Source).options(selectinload(Source.sent_webmentions))
+ sa.select(SourceDocument).options(
+ selectinload(SourceDocument.sent_webmentions)
+ )
)
}
diff --git a/webmentions_ssg/tasks/sender.py b/webmentions_ssg/tasks/sender.py
index c33cf06..3f64bed 100644
--- a/webmentions_ssg/tasks/sender.py
+++ b/webmentions_ssg/tasks/sender.py
@@ -24,7 +24,7 @@ from ..net import (
is_retryable_status,
)
from ..version import APP_NAME, VERSION
-from .discovery import (
+from .endpoint_discovery import (
PermanentDeliveryError,
RetryableDeliveryError,
discover_webmention_endpoint,
@@ -44,7 +44,7 @@ def revision_still_pending(webmention: SentWebmention, revision: int) -> bool:
"""
db.session.refresh(webmention)
- return webmention.desired_revision == revision and webmention.pending
+ return webmention.desired_revision == revision and webmention.awaiting_processing
def backoff_delay(attempt: int) -> timedelta:
@@ -99,8 +99,8 @@ class ClaimedSendAttempt:
class DeliveryResult:
"""HTTP outcome, with whether the failure is eligible for another attempt.
- ``terminal`` describes the failure type. The retry budget can also make a
- temporary failure terminal when its last allowed attempt has been used.
+ ``retryable`` describes the failure type; it does not account for the
+ remaining retry budget, which may already have been exhausted.
"""
status: SentWebmentionStatus
@@ -108,8 +108,7 @@ class DeliveryResult:
endpoint: str | None = None
response_status: int | None = None
status_url: str | None = None
- terminal: bool = True
- temporary_failure: bool = False
+ retryable: bool = False
def is_ready_to_send(webmention: SentWebmention, now: datetime) -> bool:
@@ -119,7 +118,7 @@ def is_ready_to_send(webmention: SentWebmention, now: datetime) -> bool:
:param now: Current timestamp against which the retry deadline is compared.
:returns: ``True`` if the Webmention is pending and its retry deadline has elapsed.
"""
- if not webmention.pending:
+ if not webmention.awaiting_processing:
return False
deadline = webmention.next_retry_at
@@ -154,7 +153,7 @@ def reserve_send_attempt(
SentWebmention.uuid == webmention.uuid,
SentWebmention.desired_revision == revision,
SentWebmention.attempt_count >= max_attempts,
- SentWebmention.pending,
+ SentWebmention.awaiting_processing,
sa.or_(
SentWebmention.next_retry_at.is_(None),
SentWebmention.next_retry_at <= now,
@@ -188,7 +187,7 @@ def reserve_send_attempt(
SentWebmention.uuid == attempt.webmention_uuid,
SentWebmention.desired_revision == revision,
SentWebmention.attempt_count == attempt.attempt_number - 1,
- SentWebmention.pending,
+ SentWebmention.awaiting_processing,
sa.or_(
SentWebmention.next_retry_at.is_(None),
SentWebmention.next_retry_at <= now,
@@ -198,8 +197,8 @@ def reserve_send_attempt(
attempt_count=attempt.attempt_number,
last_attempted_at=now,
next_retry_at=now + backoff_delay(attempt.attempt_number),
- endpoint=None,
- response_status=None,
+ webmention_endpoint=None,
+ endpoint_response_status=None,
status_url=None,
)
.execution_options(synchronize_session=False)
@@ -236,7 +235,7 @@ def attempt_delivery(
if endpoint is None:
return DeliveryResult(
- status=SentWebmentionStatus.UNSUPPORTED,
+ status=SentWebmentionStatus.NO_ENDPOINT,
reason="No Webmention endpoint discovered",
)
@@ -275,11 +274,10 @@ def attempt_delivery(
reason=str(exc) or "Webmention request failed",
endpoint=endpoint,
response_status=response_status,
- terminal=False,
- temporary_failure=True,
+ retryable=True,
)
except Exception as exc:
- # Unexpected errors should be terminal and keep their traceback.
+ # Unexpected errors should not be retried; keep their traceback.
current_app.logger.exception(
"Unexpected error sending SentWebmention %s", webmention_uuid
)
@@ -312,8 +310,8 @@ def record_delivery_outcome(
webmention.status = result.status
webmention.failure_reason = result.reason
- webmention.endpoint = result.endpoint
- webmention.response_status = result.response_status
+ webmention.webmention_endpoint = result.endpoint
+ webmention.endpoint_response_status = result.response_status
if terminal:
webmention.processed_revision = attempt.revision
@@ -355,19 +353,19 @@ def _process_send_locked(webmention_uuid: uuid.UUID) -> bool:
result = attempt_delivery(
attempt.source, attempt.target, webmention_uuid=webmention_uuid
)
- terminal = result.terminal or attempt.attempt_number >= attempt.max_attempts
+ terminal = not result.retryable or attempt.attempt_number >= attempt.max_attempts
if not record_delivery_outcome(webmention, attempt, result, terminal=terminal):
return False
- if result.temporary_failure and not terminal:
+ if result.retryable and not terminal:
# Huey does not retry: the scanner requeues after next_retry_at.
current_app.logger.info(
"Webmention %s send attempt %d failed; will retry",
webmention_uuid,
attempt.attempt_number,
)
- elif result.temporary_failure:
+ elif result.retryable:
current_app.logger.warning(
"Webmention %s exhausted %d send attempts: %s",
webmention_uuid,
diff --git a/webmentions_ssg/tasks/receiver.py b/webmentions_ssg/tasks/verification.py
index 313a8e4..a614815 100644
--- a/webmentions_ssg/tasks/receiver.py
+++ b/webmentions_ssg/tasks/verification.py
@@ -15,7 +15,7 @@ from flask import current_app
from ..db_helpers import rows_affected
from ..extensions import db, huey
-from ..models import ReceivedStatus, ReceivedWebmention
+from ..models import ReceivedWebmention, ReceivedWebmentionStatus
from ..net import (
AddressResolutionError,
ResponseTooLargeError,
@@ -149,11 +149,14 @@ def claim_for_verification(webmention_uuid: uuid.UUID) -> VerificationClaim | No
)
return None
- if webmention.status not in {ReceivedStatus.RECEIVED, ReceivedStatus.FAILED}:
+ if webmention.status not in {
+ ReceivedWebmentionStatus.RECEIVED,
+ ReceivedWebmentionStatus.FAILED,
+ }:
return None
if (
- webmention.status == ReceivedStatus.FAILED
+ webmention.status == ReceivedWebmentionStatus.FAILED
and webmention.failure_reason == RECOVERY_EXHAUSTED_REASON
):
return None
@@ -172,7 +175,7 @@ def claim_for_verification(webmention_uuid: uuid.UUID) -> VerificationClaim | No
ReceivedWebmention.updated_at == webmention.updated_at,
)
.values(
- status=ReceivedStatus.VERIFYING,
+ status=ReceivedWebmentionStatus.VERIFYING,
failure_reason=None,
updated_at=claim.lease_started_at,
)
@@ -188,7 +191,7 @@ def claim_for_verification(webmention_uuid: uuid.UUID) -> VerificationClaim | No
def determine_verification_outcome(
claim: VerificationClaim,
-) -> tuple[ReceivedStatus, str | None]:
+) -> tuple[ReceivedWebmentionStatus, str | None]:
"""Map verification results and permanent errors to a final status/reason.
:param claim: Claim containing the source and target URLs to verify.
@@ -200,9 +203,9 @@ def determine_verification_outcome(
try:
mentions_target = source_mentions_target(claim.source, claim.target)
except SourceGoneError as exc:
- return ReceivedStatus.DELETED, str(exc)
+ return ReceivedWebmentionStatus.SOURCE_REMOVED, str(exc)
except VerificationError as exc:
- return ReceivedStatus.FAILED, str(exc)
+ return ReceivedWebmentionStatus.FAILED, str(exc)
except RetryableFetchError, httpx.RequestError:
raise # These errors must be persisted and then retried by Huey.
except Exception as exc:
@@ -210,28 +213,28 @@ def determine_verification_outcome(
current_app.logger.exception(
"Unexpected error verifying ReceivedWebmention %s", claim.webmention_uuid
)
- return ReceivedStatus.FAILED, str(exc) or type(exc).__name__
+ return ReceivedWebmentionStatus.FAILED, str(exc) or type(exc).__name__
if mentions_target:
- return ReceivedStatus.VERIFIED, None
- return ReceivedStatus.DELETED, "Source does not mention target"
+ return ReceivedWebmentionStatus.VERIFIED, None
+ return ReceivedWebmentionStatus.SOURCE_REMOVED, "Source does not mention target"
-def release_claim(
- claim: VerificationClaim, status: ReceivedStatus, reason: str | None
+def store_verification_outcome(
+ claim: VerificationClaim, status: ReceivedWebmentionStatus, reason: str | None
) -> bool:
"""Persist an outcome only if this worker still owns the verification lease.
:param claim: Verification lease acquired by this worker.
:param status: Final status to persist for the claimed Webmention.
- :param reason: Optional explanation for a failed or deleted Webmention.
+ :param reason: Optional explanation for a failed or source-removed Webmention.
:returns: ``True`` if the worker still owned the lease and persisted the outcome.
"""
changed = db.session.execute(
sa.update(ReceivedWebmention)
.where(
ReceivedWebmention.uuid == claim.webmention_uuid,
- ReceivedWebmention.status == ReceivedStatus.VERIFYING,
+ ReceivedWebmention.status == ReceivedWebmentionStatus.VERIFYING,
ReceivedWebmention.updated_at == claim.lease_started_at,
)
.values(status=status, failure_reason=reason, updated_at=datetime.now(UTC))
@@ -259,12 +262,14 @@ def verify_webmention(webmention_uuid: uuid.UUID) -> None:
try:
status, reason = determine_verification_outcome(claim)
except (RetryableFetchError, httpx.RequestError) as exc:
- release_claim(
- claim, ReceivedStatus.FAILED, str(exc) or "Source could not be fetched"
+ store_verification_outcome(
+ claim,
+ ReceivedWebmentionStatus.FAILED,
+ str(exc) or "Source could not be fetched",
)
raise
- release_claim(claim, status, reason)
+ store_verification_outcome(claim, status, reason)
def recover_stale_verifications() -> int:
@@ -296,7 +301,7 @@ def recover_stale_verifications() -> int:
ReceivedWebmention.recovery_attempts,
).where(
ReceivedWebmention.status.in_(
- (ReceivedStatus.VERIFYING, ReceivedStatus.RECEIVED)
+ (ReceivedWebmentionStatus.VERIFYING, ReceivedWebmentionStatus.RECEIVED)
),
ReceivedWebmention.updated_at <= cutoff,
)
@@ -319,14 +324,14 @@ def recover_stale_verifications() -> int:
.values(
**(
{
- "status": ReceivedStatus.FAILED,
+ "status": ReceivedWebmentionStatus.FAILED,
"failure_reason": RECOVERY_EXHAUSTED_REASON,
"updated_at": now,
"recovery_attempts": recovery_attempts,
}
if at_limit
- else ReceivedWebmention.verification_reset_values(
- at=now, recoveries=recovery_attempts + 1
+ else ReceivedWebmention.reopen_verification_values(
+ at=now, recovery_attempts=recovery_attempts + 1
)
)
)
diff --git a/webmentions_ssg/templates/received.html b/webmentions_ssg/templates/received.html
index f00a5f9..f94d104 100644
--- a/webmentions_ssg/templates/received.html
+++ b/webmentions_ssg/templates/received.html
@@ -27,7 +27,7 @@ SPDX-License-Identifier: BSD-3-Clause
"badge_class": "text-bg-danger",
"label": "Declined"
},
- "deleted": {
+ "source_removed": {
"row_class": "table-danger",
"badge_class": "text-bg-danger",
"label": "Declined"
diff --git a/webmentions_ssg/templates/sent_source.html b/webmentions_ssg/templates/sent_source.html
index 31d5c81..2b7a377 100644
--- a/webmentions_ssg/templates/sent_source.html
+++ b/webmentions_ssg/templates/sent_source.html
@@ -12,7 +12,7 @@ SPDX-License-Identifier: BSD-3-Clause
"badge_class": "text-bg-success",
"label": "Sent"
},
- "unsupported": {
+ "no_endpoint": {
"row_class": "table-warning",
"badge_class": "text-bg-warning",
"label": "Unsupported"
@@ -114,7 +114,7 @@ SPDX-License-Identifier: BSD-3-Clause
{% endif %}
</td>
<td>
- {% if webmention.active %}
+ {% if webmention.linked %}
<span class="badge text-bg-success">Active</span>
{% else %}
<span class="badge text-bg-danger">Removed</span>
@@ -139,16 +139,16 @@ SPDX-License-Identifier: BSD-3-Clause
</div>
</td>
<td class="small">
- {% if webmention.endpoint is not none %}
+ {% if webmention.webmention_endpoint is not none %}
<div class="mb-1">
<strong>Endpoint:</strong>
- <a href="{{ webmention.endpoint }}" class="text-break">{{ webmention.endpoint }}</a>
+ <a href="{{ webmention.webmention_endpoint }}" class="text-break">{{ webmention.webmention_endpoint }}</a>
</div>
{% endif %}
- {% if webmention.response_status is not none %}
+ {% if webmention.endpoint_response_status is not none %}
<div class="mb-1">
<strong>HTTP:</strong>
- {{ webmention.response_status }}
+ {{ webmention.endpoint_response_status }}
</div>
{% endif %}
{% if webmention.status_url is not none %}
diff --git a/webmentions_ssg/templates/status.html b/webmentions_ssg/templates/status.html
index 2db2741..a9a39b4 100644
--- a/webmentions_ssg/templates/status.html
+++ b/webmentions_ssg/templates/status.html
@@ -16,7 +16,7 @@ SPDX-License-Identifier: BSD-3-Clause
{% elif webmention.status in ("received", "verifying") %}
<div class="text-warning mb-3">{{ render_icon("hourglass-split", size="5rem", title="Verification pending") }}</div>
<h1 class="h3">Webmention verification pending</h1>
- {% elif webmention.status == "deleted" %}
+ {% elif webmention.status == "source_removed" %}
<div class="text-danger mb-3">{{ render_icon("x-circle-fill", size="5rem", title="Not verified") }}</div>
<h1 class="h3">Webmention not verified</h1>
{% elif webmention.status == "failed" %}
diff --git a/webmentions_ssg/views/admin.py b/webmentions_ssg/views/admin.py
index 9b7c418..23abe65 100644
--- a/webmentions_ssg/views/admin.py
+++ b/webmentions_ssg/views/admin.py
@@ -15,10 +15,10 @@ from sqlalchemy.orm import selectinload
from .. import forms
from ..extensions import db
-from ..models import ReceivedWebmention, SentWebmention, Source
-from ..tasks.receiver import verify_webmention
+from ..models import ReceivedWebmention, SentWebmention, SourceDocument
from ..tasks.scanner import manual_scan_sources
from ..tasks.sender import send_webmention
+from ..tasks.verification import verify_webmention
from .blueprint import webmentions_bp
@@ -80,7 +80,7 @@ def reverify_received_webmention(webmention_uuid: uuid.UUID) -> ResponseReturnVa
webmention = db.get_or_404(ReceivedWebmention, webmention_uuid)
- webmention.reset_for_verification()
+ webmention.reopen_verification()
db.session.commit()
@@ -101,9 +101,9 @@ def source_list() -> ResponseReturnValue:
:returns: Rendered page containing the paginated source list.
"""
sources = db.paginate(
- sa.select(Source)
- .options(selectinload(Source.sent_webmentions))
- .order_by(Source.last_seen_at.desc()),
+ sa.select(SourceDocument)
+ .options(selectinload(SourceDocument.sent_webmentions))
+ .order_by(SourceDocument.last_seen_at.desc()),
per_page=25,
)
return render_template(
@@ -138,11 +138,11 @@ def source_detail(source_uuid: uuid.UUID) -> ResponseReturnValue:
:param source_uuid: UUID of the source to display.
:returns: Rendered source details page.
"""
- source = db.get_or_404(Source, source_uuid)
+ source = db.get_or_404(SourceDocument, source_uuid)
webmentions = db.paginate(
sa.select(SentWebmention)
- .where(SentWebmention.source_id == source.uuid)
+ .where(SentWebmention.source_uuid == source.uuid)
.order_by(SentWebmention.target, SentWebmention.uuid),
per_page=25,
)
@@ -177,13 +177,13 @@ def resend_webmention(
webmention = db.get_or_404(SentWebmention, webmention_uuid)
- if webmention.source_id != source_uuid:
+ if webmention.source_uuid != source_uuid:
abort(HTTPStatus.NOT_FOUND)
# Requeue the existing desired revision instead of inventing a new source
# revision. send_webmention() otherwise exits when this revision has already
# been processed.
- webmention.resend()
+ webmention.clear_result_for_resend()
db.session.commit()
diff --git a/webmentions_ssg/views/endpoint.py b/webmentions_ssg/views/endpoint.py
index be2a9ab..934ffad 100644
--- a/webmentions_ssg/views/endpoint.py
+++ b/webmentions_ssg/views/endpoint.py
@@ -17,8 +17,8 @@ from flask.typing import ResponseReturnValue
from .. import forms
from ..db_helpers import rows_affected
from ..extensions import csrf, db, limiter
-from ..models import ReceivedWebmention, received_url_digest
-from ..tasks.receiver import verify_webmention
+from ..models import ReceivedWebmention, source_target_digest
+from ..tasks.verification import verify_webmention
from .blueprint import webmentions_bp
@@ -37,7 +37,8 @@ def find_received_webmention(source: str, target: str) -> ReceivedWebmention | N
"""
webmention = db.session.execute(
sa.select(ReceivedWebmention).where(
- ReceivedWebmention.url_digest == received_url_digest(source, target)
+ ReceivedWebmention.source_target_digest
+ == source_target_digest(source, target)
)
).scalar_one_or_none()
@@ -92,7 +93,7 @@ def reopen_if_cooldown_elapsed(webmention: ReceivedWebmention) -> bool:
ReceivedWebmention.uuid == webmention.uuid,
ReceivedWebmention.updated_at <= cutoff,
)
- .values(ReceivedWebmention.verification_reset_values(at=now))
+ .values(ReceivedWebmention.reopen_verification_values(at=now))
.execution_options(synchronize_session=False)
)
db.session.commit()