Fix Bluesky formatting for posts too long, or with a link
2 files changed, 18 insertions(+), 4 deletions(-)

M silorider/format.py
M tests/test_silos_bluesky.py
M silorider/format.py +5 -4
@@ 86,10 86,11 @@ def format_entry(entry, *,
     # stuff with it (for instance the Bluesky silo will remember the
     # byte offsets to insert a hyperlink).
     if do_add_url and url:
+        ctx.reportAddedText(1)  # for the space before the URL.
         url = _process_end_url(url, ctx)
+        url_len = ctx.url_flattener.measureUrl(url)
+        ctx.reportAddedText(url_len)
         card.text += ' ' + url
-        url_len = ctx.url_flattener.measureUrl(url)
-        ctx.reportAddedText(1 + url_len)
     return card
 
 

          
@@ 184,10 185,10 @@ class HtmlStrippingContext:
     def limit_reached(self):
         return self._limit_reached
 
-    def processText(self, txt, allow_shorten=True):
+    def processText(self, txt, allow_shorten=True, check_limit=True):
         added_len = len(txt)
         next_text_length = self._text_length + added_len
-        if self.limit <= 0 or next_text_length <= self.limit:
+        if (not check_limit) or (self.limit <= 0 or next_text_length <= self.limit):
             self._text_length = next_text_length
             self._byte_length += len(txt.encode())
             return txt

          
M tests/test_silos_bluesky.py +13 -0
@@ 143,6 143,19 @@ def test_one_micropost_with_links(cli, f
     assert post[2] == [facet]
 
 
+def test_one_micropost_too_long(cli, feedutil, bskymock):
+    cli.appendSiloConfig('test', 'bluesky')
+    bskymock.installCredentials(cli, 'test')
+
+    feed = cli.createTempFeed(feedutil.makeFeed(
+        """<p class="p-name">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum</p>
+        <a class="u-url" href="/01234.html">permalink</a>"""))
+
+    cli.setFeedConfig('feed', feed)
+    ctx, _ = cli.run('process')
+    post = ctx.silos[0].client.posts[0]
+    assert post[0] == "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate... /01234.html"
+
 def _make_link_facet(url, start, end):
     return atprotomodels.AppBskyRichtextFacet.Main(
         features=[atprotomodels.AppBskyRichtextFacet.Link(uri=url)],