fix(rewrite): reserve canonical-URL headroom for short-form platforms - #3
Open
ktherage wants to merge 1 commit into
Open
fix(rewrite): reserve canonical-URL headroom for short-form platforms#3ktherage wants to merge 1 commit into
ktherage wants to merge 1 commit into
Conversation
Auto-rewrites are generated to exactly max_content_length characters, then _append_canonical_url() appends the canonical URL on top, pushing the final post past the platform limit and failing the content-length check. Bluesky (300 chars) always broke this way; Mastodon only worked due to slack in its 500-char limit. Add Platform.appends_canonical_url and Platform.rewrite_max_length(), which return a reduced budget (limit minus URL plus "\n\n" separator) for platforms that append the URL. Use it at every auto-rewrite call site (publish, publish --dry-run, audit, schedule, and publishing.prepare_publish). URL-appending platforms set appends_canonical_url: bluesky, mastodon, twitter, threads, linkedin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
For short-form platforms (Bluesky, Mastodon, Twitter, Threads, LinkedIn), auto-rewrites are generated to exactly
max_content_lengthcharacters, then_append_canonical_url()(base.py) appends the canonical URL on top. The final post exceeds the platform limit and the content-length check fails.Bluesky (300-char limit) breaks on every publish. Example: a 268-char rewrite + canonical URL = 358 chars > 300. Mastodon only works because its 500-char limit happens to have enough slack. The same latent bug exists for Twitter (280), Threads (500), and LinkedIn (3000).
Fix
Platform.appends_canonical_url: bool = Falseclass attribute.Platform.rewrite_max_length(article)which returnsmax_content_lengthminus the canonical URL (plus the"\n\n"separator) for platforms that append it, floored at 1. ReturnsNonefor platforms with no limit.appends_canonical_url = Trueon Bluesky, Mastodon, Twitter, Threads, LinkedIn.rewrite_max_length()at every auto-rewrite call site:crier publish,publish --dry-runpreview,crier auditupdate path,crier schedule run, andpublishing.prepare_publish.This leaves room for the URL so the final post fits exactly within the platform limit.
Tests
TestRewriteMaxLengthclass covering: no-limit platforms, non-appenders (full budget), URL-headroom subtraction (final post fits exactly), no-URL and URL-already-in-body cases, floor-at-1 for tiny limits, and flag verification on all 5 platforms.test_publishing.pymocks to the new method.1283 passed, 4 skipped(excludingtest_mcp.py, which fails to collect due to themcpdependency).Verified live: after applying the same change locally, a Bluesky auto-rewrite publish that previously failed (
Auto-rewrite failed ... 358 > 300) now succeeds.