Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

Address Copilot review: normalize endpoints, quieter logs, robust tests

Patrick Schrallb317b8dbb224
diff --git a/app/Services/Social/BlueskyPublisher.php b/app/Services/Social/BlueskyPublisher.php
index abc4a04e9..b3a7943ec 100644
--- a/app/Services/Social/BlueskyPublisher.php
+++ b/app/Services/Social/BlueskyPublisher.php
@@ -278,12 +278,18 @@ class BlueskyPublisher
*/
private function resolveHandleToDid(string $handle, ?string $service = null, ?SocialAccount $account = null): ?string
{
+ // Normalize so a trailing slash neither produces a double-slash URL nor
+ // breaks the `=== $service` check below (which decides authentication).
+ $service = $service !== null ? rtrim($service, '/') : null;
+
$endpoints = array_values(array_unique(array_filter([
$service,
'https://public.api.bsky.app',
'https://bsky.social',
])));
+ $lastError = null;
+ $lastEndpoint = null;
foreach ($endpoints as $endpoint) {
try {
$request = $this->socialHttp();
@@ -301,7 +307,12 @@ class BlueskyPublisher
return $did;
}
} catch (\Throwable $e) {
- Log::warning('Bluesky handle resolution failed', [
+ // Per-endpoint failures are expected during transient outages;
+ // keep them at debug to avoid noisy logs and surface a single
+ // warning below only when every endpoint has been exhausted.
+ $lastError = $e->getMessage();
+ $lastEndpoint = $endpoint;
+ Log::debug('Bluesky handle resolution attempt failed', [
'handle' => $handle,
'endpoint' => $endpoint,
'error' => $e->getMessage(),
@@ -309,6 +320,12 @@ class BlueskyPublisher
}
}
+ Log::warning('Bluesky handle resolution failed; mention will be sent as plain text', [
+ 'handle' => $handle,
+ 'endpoint' => $lastEndpoint,
+ 'error' => $lastError,
+ ]);
+
return null;
}
diff --git a/tests/Feature/Services/Social/BlueskyPublisherTest.php b/tests/Feature/Services/Social/BlueskyPublisherTest.php
index 71610c690..6ce6df4a5 100644
--- a/tests/Feature/Services/Social/BlueskyPublisherTest.php
+++ b/tests/Feature/Services/Social/BlueskyPublisherTest.php
@@ -105,7 +105,10 @@ test('bluesky publisher resolves mentions to DIDs as facets', function () {
$this->post->update(['content' => 'Shout out to @friend.bsky.social']);
Http::fake([
- 'https://bsky.social/xrpc/com.atproto.identity.resolveHandle*' => Http::response([
+ // Wildcard so the fake matches whichever endpoint resolveHandleToDid()
+ // tries first (the account PDS, public AppView, or bsky.social) and the
+ // test stays isolated from the configured service URL.
+ '*/xrpc/com.atproto.identity.resolveHandle*' => Http::response([
'did' => 'did:plc:friend456',
], 200),
'https://bsky.social/xrpc/com.atproto.repo.createRecord' => Http::response([
@@ -117,7 +120,7 @@ test('bluesky publisher resolves mentions to DIDs as facets', function () {
$this->publisher->publish($this->postPlatform);
Http::assertSent(function ($request) {
- $record = $request['record'] ?? null;
+ $record = $request->data()['record'] ?? null;
if (! $record || ! isset($record['facets'])) {
return false;
@@ -152,7 +155,7 @@ test('bluesky publisher skips mention facet when handle cannot be resolved', fun
expect($result['id'])->toBe('3abc123xyz');
Http::assertSent(function ($request) {
- $record = $request['record'] ?? null;
+ $record = $request->data()['record'] ?? null;
if (! $record) {
return false;