Harden BlueskyPublisher: link facets, conventions, NSID lexicon, tests - #94
Merged
Conversation
The URL regex captured trailing sentence punctuation and an unmatched closing
paren ("see https://x.com).") into the link facet, so Bluesky rendered the
punctuation as part of a malformed link. Trim it like the official atproto
tokenizer. Add tests for the trim and for byte-offset correctness after
multibyte characters (emoji/accents).
Import Exception instead of referencing it inline, read the blob via data_get, source the web-app host from config (new bluesky.web_app key) instead of hardcoding bsky.app, and drop the getUtf8ByteOffset no-op — the PREG /u offset is already in bytes, so the call sites use it directly.
The image tests only checked that createRecord was sent — the faked empty download meant no blob was ever attached, so they never verified the embed. Drive a real (mocked) optimize + upload and assert the createRecord record carries an app.bsky.embed.images embed, and that six images upload exactly four.
The Bluesky lexicon identifiers (createRecord, createSession, feed.post, facet types, etc.) were repeated as magic strings across BlueskyPublisher, BlueskyAnalytics, ConnectionVerifier and BlueskyController, where a typo fails silently at runtime as "Invalid request". Define them once as named constants so a typo is an undefined-constant error instead. Tests keep the literal NSIDs as the independent contract.
Add a unit test asserting each BlueskyLexicon constant equals its AT Protocol
NSID — a wrong value (not just a typo'd name) would otherwise fail silently at
runtime. Add a test that a URL with a matching '(' keeps its trailing ')'
(Wikipedia-style), covering the previously-untested keep branch of the trim.
Add a test that a network error during handle resolution degrades the mention to plain text instead of failing the post (exercises the resolveHandleToDid try/catch), and a test asserting the post URL is built from the configured web_app host (a revert to a hardcoded host would now fail).
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.
Follow-up to #93. Hardens
BlueskyPublisher(and the sibling Bluesky services) — one real bug, convention cleanup, a shared NSID lexicon, and stronger tests.Bug fix
see https://x.com).) into the link facet, so Bluesky rendered a malformed/over-long link. Now trimmed like the official atproto tokenizer.Conventions / cleanup
Exceptioninstead of inline\Exception.data_getinstead of direct array access.config('trypost.platforms.bluesky.web_app')key instead of hardcodingbsky.app.getUtf8ByteOffsetno-op —PREG_OFFSET_CAPTUREwith/ualready returns byte offsets, so call sites use them directly.BlueskyLexicon
createRecord,createSession,feed.post, facet types, etc.) intoApp\Services\Social\BlueskyLexicon. They were repeated as magic strings acrossBlueskyPublisher,BlueskyAnalytics,ConnectionVerifierandBlueskyController, where a typo fails silently at runtime as "Invalid request" (the same class of bug Fix: resolve Bluesky @mention handles to DIDs (mentions caused "Invalid post data") #93 fixed). A typo is now an undefined-constant error. Tests keep the literal NSIDs as the independent contract.Tests
app.bsky.embed.imagesembed is attached and that six images upload exactly four (they previously only checkedcreateRecordwas sent).Full suite green (1970 passed, 2 skipped).
Out of scope
alttext — theMediamodel has no alt field; needs a migration + UI (separate feature).