fix(mcp): publish-post-tool blocks terminal states, not only Published

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.
This commit is contained in:
Paulo Castellano 2026-05-19 12:59:40 -03:00
parent 3f6032c152
commit 27f27b6683
2 changed files with 25 additions and 2 deletions

View file

@ -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 */

View file

@ -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,
]);