From dcbbfdb38d4e18e377d4e326d82f35341840c6cc Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 30 Oct 2026 19:23:17 +0100 Subject: fix(sender): stabilize source content fingerprints Hash normalized reader-facing content and outgoing targets instead of raw h-entry markup so generated attributes and relative timestamps do not trigger spurious source revisions or repeat Webmentions. Preserve meaningful changes such as image updates and reaction target changes while ignoring target ordering and other markup noise. --- tests/tasks/test_scanner.py | 167 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 2 deletions(-) (limited to 'tests/tasks') diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py index 21a13c6..7aefff4 100644 --- a/tests/tasks/test_scanner.py +++ b/tests/tasks/test_scanner.py @@ -508,6 +508,119 @@ def test_scan_source_uses_canonical_without_base_url( assert len(scanned.content_hash) == 32 +def test_scan_source_ignores_markup_noise_in_content( + scanner_module: ModuleType, tmp_path: Path +) -> None: + path = write_post( + tmp_path, + "example", + "
Hello world!
" + 'Target', + ) + first = scanner_module.scan_source_file(path, root=tmp_path, base_url=None) + + write_post( + tmp_path, + "example", + 'Hello world!
' + ' Target ', + ) + second = scanner_module.scan_source_file(path, root=tmp_path, base_url=None) + + assert first.targets == second.targets + assert first.content_hash == second.content_hash + + +def test_scan_source_uses_stable_time_value_inside_content( + scanner_module: ModuleType, tmp_path: Path +) -> None: + path = write_post( + tmp_path, + "example", + '', + ) + first = scanner_module.scan_source_file(path, root=tmp_path, base_url=None) + + path.write_text( + path.read_text(encoding="utf-8").replace("5 minutes ago", "6 minutes ago"), + encoding="utf-8", + ) + second = scanner_module.scan_source_file(path, root=tmp_path, base_url=None) + + assert first.content_hash == second.content_hash + + +def test_scan_source_hash_changes_when_image_changes( + scanner_module: ModuleType, tmp_path: Path +) -> None: + path = write_post(tmp_path, "example", '
')
+ first = scanner_module.scan_source_file(path, root=tmp_path, base_url=None)
+
+ path.write_text(
+ path.read_text(encoding="utf-8").replace("/images/a.jpg", "/images/b.jpg"),
+ encoding="utf-8",
+ )
+ second = scanner_module.scan_source_file(path, root=tmp_path, base_url=None)
+
+ assert first.content_hash != second.content_hash
+
+
+def test_scan_source_hash_includes_reaction_targets_outside_content(
+ scanner_module: ModuleType, tmp_path: Path
+) -> None:
+ path = write_post(tmp_path, "example", "Same content.
") + html = path.read_text(encoding="utf-8") + path.write_text( + html.replace( + 'Same content.
") + html = path.read_text(encoding="utf-8") + first_link = 'A' + second_link = 'B' + path.write_text( + html.replace( + '