From d73dd0a5b01063ba7307d7defe2a98423ee1631d Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 3 Nov 2026 12:42:19 -0700 Subject: [PATCH] fix: Fetch reply contexts again (v2.10.2) fetch_source returns (content, content_type, final_url) since v2.7.0, but fetch_reply_context unpacked two values, so every new reply/like/repost context was stored as an error. Parse with the final URL so relative links resolve. Adds a test that runs the real fetch path. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 +++ docs/design/INDEX.md | 6 ++- .../v2.10.2/2026-11-03-reply-context-fetch.md | 22 ++++++++ docs/projectplan/INDEX.md | 1 + docs/projectplan/v2.10.2/RELEASE.md | 13 +++++ starpunk/__init__.py | 4 +- starpunk/reply_context.py | 6 ++- tests/test_reply_context_fetch.py | 50 +++++++++++++++++++ 8 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 docs/design/v2.10.2/2026-11-03-reply-context-fetch.md create mode 100644 docs/projectplan/v2.10.2/RELEASE.md create mode 100644 tests/test_reply_context_fetch.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 78b2456..2df7f16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.10.2] - 2026-11-03 + +### Fixed + +- The context shown above replies, likes and reposts (the post being replied to: its title, author and text) was never fetched since v2.7.0: a change to the shared fetcher wasn't carried over, so every new context was saved as an error and the note showed only the bare link. Relative links on the other page now also resolve against its address after redirects + ## [2.10.1] - 2026-11-03 WebSub fixes from an adversarial review of v2.10.0 against the [W3C Recommendation](https://www.w3.org/TR/websub/) (details in ADR-071, Amendments). diff --git a/docs/design/INDEX.md b/docs/design/INDEX.md index 72c4b91..33d9c55 100644 --- a/docs/design/INDEX.md +++ b/docs/design/INDEX.md @@ -21,7 +21,7 @@ is in `../architecture/`; decisions are in `../decisions/` (ADRs). ## Contents -[v1.0.0](#v100) · [v1.1.1](#v111) · [v1.1.2](#v112) · [v1.2.0](#v120) · [v1.3.0](#v130) · [v1.3.1](#v131) · [v1.4.0](#v140) · [v1.4.1](#v141) · [v1.4.2](#v142) · [v1.5.0](#v150) · [v1.6.0](#v160) · [v2.0.0](#v200) · [v2.0.1](#v201) · [v2.0.2](#v202) · [v2.1.0](#v210) · [v2.2.0](#v220) · [v2.3.0](#v230) · [v2.3.1](#v231) · [v2.3.2](#v232) · [v2.3.3](#v233) · [v2.4.0](#v240) · [v2.5.0](#v250) · [v2.6.0](#v260) · [v2.6.1](#v261) · [v2.6.2](#v262) · [v2.6.3](#v263) · [v2.6.4](#v264) · [v2.6.5](#v265) · [v2.6.6](#v266) · [v2.6.7](#v267) · [v2.6.8](#v268) · [v2.6.9](#v269) · [v2.7.0](#v270) · [v2.7.1](#v271) · [v2.7.2](#v272) · [v2.8.0](#v280) · [v2.8.1](#v281) · [v2.9.0](#v290) · [v2.10.0](#v2100) · [v2.10.1](#v2101) · [hotfix](#hotfix) +[v1.0.0](#v100) · [v1.1.1](#v111) · [v1.1.2](#v112) · [v1.2.0](#v120) · [v1.3.0](#v130) · [v1.3.1](#v131) · [v1.4.0](#v140) · [v1.4.1](#v141) · [v1.4.2](#v142) · [v1.5.0](#v150) · [v1.6.0](#v160) · [v2.0.0](#v200) · [v2.0.1](#v201) · [v2.0.2](#v202) · [v2.1.0](#v210) · [v2.2.0](#v220) · [v2.3.0](#v230) · [v2.3.1](#v231) · [v2.3.2](#v232) · [v2.3.3](#v233) · [v2.4.0](#v240) · [v2.5.0](#v250) · [v2.6.0](#v260) · [v2.6.1](#v261) · [v2.6.2](#v262) · [v2.6.3](#v263) · [v2.6.4](#v264) · [v2.6.5](#v265) · [v2.6.6](#v266) · [v2.6.7](#v267) · [v2.6.8](#v268) · [v2.6.9](#v269) · [v2.7.0](#v270) · [v2.7.1](#v271) · [v2.7.2](#v272) · [v2.8.0](#v280) · [v2.8.1](#v281) · [v2.9.0](#v290) · [v2.10.0](#v2100) · [v2.10.1](#v2101) · [v2.10.2](#v2102) · [hotfix](#hotfix) ## v1.0.0 @@ -406,6 +406,10 @@ OIDC admin login and built-in IndieAuth server. - [2026-11-03-websub-hardening.md](v2.10.1/2026-11-03-websub-hardening.md) — WebSub hardening (implementation report) *(reconstructed)* +## v2.10.2 + +- [2026-11-03-reply-context-fetch.md](v2.10.2/2026-11-03-reply-context-fetch.md) - Reply contexts fetched again (fetch_source returns three values since v2.7.0) + ## hotfix Not a release folder. diff --git a/docs/design/v2.10.2/2026-11-03-reply-context-fetch.md b/docs/design/v2.10.2/2026-11-03-reply-context-fetch.md new file mode 100644 index 0000000..72dad85 --- /dev/null +++ b/docs/design/v2.10.2/2026-11-03-reply-context-fetch.md @@ -0,0 +1,22 @@ +# v2.10.2: Reply context fetch + +## Summary + +`webmention_processor.fetch_source()` has returned +`(content, content_type, final_url)` since v2.7.0, but +`reply_context.fetch_reply_context()` still unpacked two values. The +`ValueError` was caught by its generic handler, so every new reply, like and +repost context was stored with `fetch_status='error'`. Found during the +documentation refresh (docs/design/v1.6.0/database-schema.md). Production had +no reply-context rows yet, so nothing needed repairing. + +## Changes + +- `starpunk/reply_context.py`: unpack three values; parse microformats with + the final URL so relative links (author URL, photos) resolve correctly. + +## Tests + +`tests/test_reply_context_fetch.py` runs `fetch_reply_context` through the +mocked network (other tests stub it out, which is why this went unnoticed). +It fails on v2.10.1. diff --git a/docs/projectplan/INDEX.md b/docs/projectplan/INDEX.md index 5606570..40abd19 100644 --- a/docs/projectplan/INDEX.md +++ b/docs/projectplan/INDEX.md @@ -46,3 +46,4 @@ Future work and per-release plans. See `../DOCUMENTATION.md` (PROJECTPLAN). - **[v2.9.0](v2.9.0/RELEASE.md)** - Micropub review (Released 2026-11-03) - **[v2.10.0](v2.10.0/RELEASE.md)** - WebSub (Released 2026-11-03) - **[v2.10.1](v2.10.1/RELEASE.md)** - WebSub hardening (Released 2026-11-03) +- **[v2.10.2](v2.10.2/RELEASE.md)** - Reply context fetch fix (Released 2026-11-03) diff --git a/docs/projectplan/v2.10.2/RELEASE.md b/docs/projectplan/v2.10.2/RELEASE.md new file mode 100644 index 0000000..3db8c5d --- /dev/null +++ b/docs/projectplan/v2.10.2/RELEASE.md @@ -0,0 +1,13 @@ +# v2.10.2 + +- **Date**: 2026-11-03 +- **Status**: Released + +## Bugs fixed + +- Reply, like and repost contexts were never fetched since v2.7.0 (stored as errors); fixed, with relative links resolved after redirects + +## Related + +- [CHANGELOG](../../../CHANGELOG.md) +- [Design note](../../design/v2.10.2/2026-11-03-reply-context-fetch.md) diff --git a/starpunk/__init__.py b/starpunk/__init__.py index 5fa0dc9..622a7df 100644 --- a/starpunk/__init__.py +++ b/starpunk/__init__.py @@ -470,5 +470,5 @@ def create_app(config=None): # Package version (Semantic Versioning 2.0.0) # See docs/standards/versioning-strategy.md for details -__version__ = "2.10.1" -__version_info__ = (2, 10, 1) +__version__ = "2.10.2" +__version_info__ = (2, 10, 2) diff --git a/starpunk/reply_context.py b/starpunk/reply_context.py index 8a61e2b..affbab4 100644 --- a/starpunk/reply_context.py +++ b/starpunk/reply_context.py @@ -76,14 +76,16 @@ def fetch_reply_context( # Fetch and parse context try: # Fetch URL content - content, content_type = fetch_source(reply_url, site_url) + # fetch_source also returns the URL after redirects (v2.7.0); relative + # links in the page resolve against it (v2.10.2) + content, content_type, final_url = fetch_source(reply_url, site_url) # Parse microformats (only for HTML) if 'html' not in content_type.lower(): # Not HTML - store minimal context return _store_minimal_context(db_path, reply_url, "Not HTML content") - parsed_mf2 = mf2py.parse(doc=content, url=reply_url) + parsed_mf2 = mf2py.parse(doc=content, url=final_url) # Extract h-entry data entry_data = _extract_entry_data(parsed_mf2) diff --git a/tests/test_reply_context_fetch.py b/tests/test_reply_context_fetch.py new file mode 100644 index 0000000..9e925d1 --- /dev/null +++ b/tests/test_reply_context_fetch.py @@ -0,0 +1,50 @@ +""" +Reply contexts are fetched for real (v2.10.2) + +v2.7.0 made fetch_source return (content, content_type, final_url) but +fetch_reply_context still unpacked two values, so every new reply, like and +repost stored fetch_status='error'. Other tests stub fetch_reply_context out; +this one runs it through the mocked network. +""" + +import sqlite3 + +import httpx + +from starpunk.reply_context import fetch_reply_context + +PUBLIC = [(2, 1, 6, "", ("93.184.216.34", 0))] + +PAGE = """Their site +
+

A post worth replying to

+ Ada Example + +

Some thoughts.

+
""" + + +def test_reply_context_is_fetched_and_stored(app, monkeypatch): + def site(request): + if request.url.path == "/old": + return httpx.Response(301, headers={"Location": "https://their.example/posts/1"}) + return httpx.Response(200, html=PAGE) + + monkeypatch.setattr("starpunk.webmention_ssrf.socket.getaddrinfo", lambda *a, **k: PUBLIC) + monkeypatch.setattr("starpunk.webmention_ssrf.TRANSPORT", httpx.MockTransport(site)) + + with app.app_context(): + context = fetch_reply_context(app.config["DATABASE_PATH"], "https://their.example/old", + app.config["SITE_URL"]) + + assert context["fetch_status"] == "fetched", context + assert context["title"] == "A post worth replying to" + assert context["author_name"] == "Ada Example" + # Relative links resolve against the URL after the redirect + assert context["author_url"] == "https://their.example/about" + assert "Some thoughts" in (context["content_snippet"] or "") + + row = sqlite3.connect(app.config["DATABASE_PATH"]).execute( + "SELECT fetch_status FROM reply_contexts WHERE url = ?", ("https://their.example/old",) + ).fetchone() + assert row == ("fetched",)