From 27f27b6683c872d419db5c157568fd46efaae277 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Tue, 19 May 2026 12:59:40 -0300 Subject: [PATCH] fix(mcp): publish-post-tool blocks terminal states, not only Published MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The earlier rename of UpdatePost's terminal short-circuit from AlreadyPublished → Finalized was applied to UpdatePostTool and Api/PostController but missed PublishPostTool. Result: calling publish-post-tool against a post in Published / PartiallyPublished / Failed / Publishing returned the unchanged post wrapped as a success response — the MCP client thought it had republished. The check now accepts both action enums so the existing string behavior (clear error) is preserved, and a Pest dataset covers all four terminal statuses. --- app/Mcp/Tools/Post/PublishPostTool.php | 4 ++-- tests/Feature/Mcp/PostPublishToolTest.php | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/Mcp/Tools/Post/PublishPostTool.php b/app/Mcp/Tools/Post/PublishPostTool.php index e27d9b39..d69904d9 100644 --- a/app/Mcp/Tools/Post/PublishPostTool.php +++ b/app/Mcp/Tools/Post/PublishPostTool.php @@ -47,8 +47,8 @@ public function handle(Request $request): Response|ResponseFactory 'scheduled_at' => $scheduledAt, ]); - if (data_get($result, 'action') === PostAction::AlreadyPublished) { - return Response::error('Post is already published.'); + if (in_array(data_get($result, 'action'), [PostAction::AlreadyPublished, PostAction::Finalized], true)) { + return Response::error('Post is already published or in a terminal state.'); } /** @var Post $updated */ diff --git a/tests/Feature/Mcp/PostPublishToolTest.php b/tests/Feature/Mcp/PostPublishToolTest.php index c3b29b90..7b269fdc 100644 --- a/tests/Feature/Mcp/PostPublishToolTest.php +++ b/tests/Feature/Mcp/PostPublishToolTest.php @@ -256,3 +256,26 @@ $response->assertHasErrors(['Post not found.']); }); + +test('publish post rejects posts already in a terminal state', function (PostStatus $status) { + $post = Post::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'user_id' => $this->user->id, + 'status' => $status, + ]); + + PostPlatform::factory()->linkedin()->create([ + 'post_id' => $post->id, + 'social_account_id' => $this->socialAccount->id, + ]); + + $response = TryPostServer::actingAs($this->user) + ->tool(PublishPostTool::class, ['post_id' => $post->id]); + + $response->assertHasErrors(['Post is already published or in a terminal state.']); +})->with([ + PostStatus::Published, + PostStatus::PartiallyPublished, + PostStatus::Failed, + PostStatus::Publishing, +]);