Switch Bridgy syndication from Micropub to webmention

Bridgy's Micropub endpoint required per-silo access tokens and posted
raw markdown content directly. Switch to Bridgy's webmention publish
endpoint instead: POST source/target to /publish/webmention and let
Bridgy re-fetch the note page, which now carries hidden verification
links for silos not yet syndicated. Removes the now-unused
config/bridgy.php and BRIDGY_MASTODON_TOKEN env var, and caps both
jobs to a single try since retries would send Bridgy a duplicate
publish webmention.
This commit is contained in:
Jonny Barnes 2026-07-14 17:36:25 +01:00
commit db09718a96
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
9 changed files with 167 additions and 94 deletions

View file

@ -21,11 +21,15 @@ class SyndicateNoteToBlueskyJobTest extends TestCase
#[Test]
public function we_syndicate_notes_to_bluesky(): void
{
config(['bridgy.bluesky_token' => 'test']);
$faker = Factory::create();
$randomNumber = $faker->randomNumber();
$blueskyUrl = 'https://bsky.app/profile/jonnybarnes.uk/'.$randomNumber;
$mock = new MockHandler([
new Response(201, ['Location' => 'https://bsky.app/profile/jonnybarnes.uk/'.$randomNumber]),
new Response(201, ['Content-Type' => 'application/json'], json_encode([
'url' => $blueskyUrl,
'id' => (string) $randomNumber,
'type' => ['h-entry'],
])),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
@ -35,21 +39,19 @@ class SyndicateNoteToBlueskyJobTest extends TestCase
$job->handle($client);
$this->assertDatabaseHas('notes', [
'bluesky_url' => 'https://bsky.app/profile/jonnybarnes.uk/'.$randomNumber,
'bluesky_url' => $blueskyUrl,
]);
}
#[Test]
public function we_syndicate_the_original_markdown_to_bluesky(): void
public function we_post_the_correct_source_and_target(): void
{
config(['bridgy.bluesky_token' => 'test']);
$faker = Factory::create();
$randomNumber = $faker->randomNumber();
$container = [];
$history = Middleware::history($container);
$mock = new MockHandler([
new Response(201, ['Location' => 'https://bsky.app/profile/jonnybarnes.uk/'.$randomNumber]),
new Response(201, ['Content-Type' => 'application/json'], json_encode([
'url' => 'https://bsky.app/profile/jonnybarnes.uk/1',
])),
]);
$handler = HandlerStack::create($mock);
$handler->push($history);
@ -59,12 +61,37 @@ class SyndicateNoteToBlueskyJobTest extends TestCase
$job = new SyndicateNoteToBluesky($note);
$job->handle($client);
$this->assertDatabaseHas('notes', [
'bluesky_url' => 'https://bsky.app/profile/jonnybarnes.uk/'.$randomNumber,
$request = $container[0]['request'];
$body = [];
parse_str((string) $request->getBody(), $body);
$this->assertSame('https://brid.gy/publish/webmention', (string) $request->getUri());
$this->assertSame($note->uri, $body['source']);
$this->assertSame('https://brid.gy/publish/bluesky', $body['target']);
}
#[Test]
public function a_bridgy_failure_throws_and_does_not_set_bluesky_url(): void
{
$mock = new MockHandler([
new Response(400, ['Content-Type' => 'application/json'], json_encode([
'error' => 'Could not find target link',
])),
]);
$client = new Client(['handler' => HandlerStack::create($mock)]);
$expectedRequestContent = '{"type":["h-entry"],"properties":{"content":["This is a **test**"]}}';
$note = Note::factory()->create();
$job = new SyndicateNoteToBluesky($note);
$this->assertEquals($expectedRequestContent, $container[0]['request']->getBody()->getContents());
$this->expectException(\RuntimeException::class);
try {
$job->handle($client);
} finally {
$this->assertDatabaseHas('notes', [
'id' => $note->id,
'bluesky_url' => null,
]);
}
}
}

View file

@ -21,11 +21,15 @@ class SyndicateNoteToMastodonJobTest extends TestCase
#[Test]
public function we_syndicate_notes_to_mastodon(): void
{
config(['bridgy.mastodon_token' => 'test']);
$faker = Factory::create();
$randomNumber = $faker->randomNumber();
$mastodonUrl = 'https://mastodon.example/@jonny/'.$randomNumber;
$mock = new MockHandler([
new Response(201, ['Location' => 'https://mastodon.example/@jonny/'.$randomNumber]),
new Response(201, ['Content-Type' => 'application/json'], json_encode([
'url' => $mastodonUrl,
'id' => (string) $randomNumber,
'type' => ['h-entry'],
])),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
@ -35,21 +39,19 @@ class SyndicateNoteToMastodonJobTest extends TestCase
$job->handle($client);
$this->assertDatabaseHas('notes', [
'mastodon_url' => 'https://mastodon.example/@jonny/'.$randomNumber,
'mastodon_url' => $mastodonUrl,
]);
}
#[Test]
public function we_syndicate_the_original_markdown(): void
public function we_post_the_correct_source_and_target(): void
{
config(['bridgy.mastodon_token' => 'test']);
$faker = Factory::create();
$randomNumber = $faker->randomNumber();
$container = [];
$history = Middleware::history($container);
$mock = new MockHandler([
new Response(201, ['Location' => 'https://mastodon.example/@jonny/'.$randomNumber]),
new Response(201, ['Content-Type' => 'application/json'], json_encode([
'url' => 'https://mastodon.example/@jonny/1',
])),
]);
$handler = HandlerStack::create($mock);
$handler->push($history);
@ -59,12 +61,37 @@ class SyndicateNoteToMastodonJobTest extends TestCase
$job = new SyndicateNoteToMastodon($note);
$job->handle($client);
$this->assertDatabaseHas('notes', [
'mastodon_url' => 'https://mastodon.example/@jonny/'.$randomNumber,
$request = $container[0]['request'];
$body = [];
parse_str((string) $request->getBody(), $body);
$this->assertSame('https://brid.gy/publish/webmention', (string) $request->getUri());
$this->assertSame($note->uri, $body['source']);
$this->assertSame('https://brid.gy/publish/mastodon', $body['target']);
}
#[Test]
public function a_bridgy_failure_throws_and_does_not_set_mastodon_url(): void
{
$mock = new MockHandler([
new Response(400, ['Content-Type' => 'application/json'], json_encode([
'error' => 'Could not find target link',
])),
]);
$client = new Client(['handler' => HandlerStack::create($mock)]);
$expectedRequestContent = '{"type":["h-entry"],"properties":{"content":["This is a **test**"]}}';
$note = Note::factory()->create();
$job = new SyndicateNoteToMastodon($note);
$this->assertEquals($expectedRequestContent, $container[0]['request']->getBody()->getContents());
$this->expectException(\RuntimeException::class);
try {
$job->handle($client);
} finally {
$this->assertDatabaseHas('notes', [
'id' => $note->id,
'mastodon_url' => null,
]);
}
}
}