1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
#
# SPDX-License-Identifier: BSD-3-Clause
import pytest
from webmentions_ssg.failure_guidance import (
describe_received_failure,
describe_sent_failure,
)
@pytest.mark.parametrize(
("reason", "expected_fragment", "local_step"),
[
("Source does not mention target", "link to the target URL", False),
("Source returned HTTP 410", "permanently gone", False),
("Source document is too large", "maximum response size", False),
("Source resolves to a non-public address", "non-public address", False),
("Source hostname could not be resolved", "DNS", False),
("Source could not be fetched", "could not fetch", False),
("Invalid source hostname", "valid hostname", False),
("Source domain is blocked", "blocklist", True),
("Source domain is not allowlisted", "allowed source-domain", True),
("Verification recovery limit reached", "automatic recovery stopped", True),
("Target hostname is not in ALLOWED_TARGET_HOSTNAMES", "target hostname", True),
(
"Target hostname is not in ALLOWED_TARGET_HOSTNAMES.",
"target hostname",
True,
),
("Source returned HTTP 404", "not found", False),
("Source returned HTTP 401", "denied access", False),
("Source returned HTTP 403", "denied access", False),
("Source returned HTTP 429", "limiting requests", False),
("Source returned HTTP 503", "server error", False),
("Source returned HTTP 400", "returned HTTP 400", False),
(
"Unsupported source content type: application/json",
"application/json",
False,
),
],
)
def test_only_receiver_controlled_failures_suggest_steps(
reason: str, expected_fragment: str, local_step: bool
) -> None:
guidance = describe_received_failure(reason)
assert guidance is not None
assert expected_fragment in guidance.explanation
assert bool(guidance.next_step) is local_step
@pytest.mark.parametrize("reason", ["unknown failure", "", "Source returned HTTP 999"])
def test_unknown_received_failures_are_not_misclassified(reason: str) -> None:
assert describe_received_failure(reason) is None
@pytest.mark.parametrize(
("reason", "expected_fragment", "operator_step"),
[
("No Webmention endpoint discovered", "does not advertise", False),
("Target returned HTTP 404", "not found", False),
("Target returned HTTP 410", "permanently gone", False),
("Target returned HTTP 403", "denied access", False),
("Target returned HTTP 429", "rate-limiting", True),
("Target returned HTTP 503", "server error", True),
("Target returned HTTP 400", "did not complete delivery", False),
("Webmention endpoint returned HTTP 302", "did not complete delivery", False),
("Webmention endpoint returned HTTP 400", "rejected the submission", True),
("Webmention endpoint returned HTTP 422", "rejected the submission", True),
("Webmention endpoint returned HTTP 404", "not found", False),
("Webmention endpoint returned HTTP 408", "timed out", True),
("Webmention endpoint returned HTTP 429", "rate-limiting", True),
("Webmention endpoint returned HTTP 500", "server error", True),
("Webmention endpoint returned HTTP 503.", "server error", True),
("Target document is too large", "response-size limit", True),
("Invalid target URL: 'ftp://example.com'", "valid HTTP", True),
("Invalid Webmention endpoint: 'ftp://example.com'", "malformed", False),
("Could not resolve hostname 'example.com'", "DNS resolution", True),
("Non-public network address for 'localhost'", "non-public", True),
("No public addresses available for 'example.com'", "public address", False),
("Retry limit reached (6 attempts)", "exhausted", True),
("Webmention request failed", "could not complete", True),
("timed out", "timed out", True),
("The read operation timed out", "read timeout", True),
("[Errno 111] Connection refused", "refused", True),
("All connection attempts failed", "could not establish", True),
("Server disconnected without sending a response", "closed", False),
],
)
def test_sent_failure_guidance(
reason: str, expected_fragment: str, operator_step: bool
) -> None:
guidance = describe_sent_failure(reason)
assert guidance is not None
assert expected_fragment in guidance.explanation
assert bool(guidance.next_step) is operator_step
@pytest.mark.parametrize(
"reason",
[
"",
"Unrecognized sender failure",
"Target returned HTTP 999",
"Retry limit reached",
],
)
def test_unknown_sent_failures_keep_raw_reason(reason: str) -> None:
assert describe_sent_failure(reason) is None
def test_received_and_sent_reasons_do_not_cross_classify() -> None:
assert describe_received_failure("No Webmention endpoint discovered") is None
assert describe_sent_failure("Source domain is blocked") is None
|