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.

fix(ai-templates): real needsAccount + content_type test coverage; drop unwired humanizableFields; cleanup

Paulo Castellano24d9653f6ed6
diff --git a/app/Ai/Templates/AiContentTemplate.php b/app/Ai/Templates/AiContentTemplate.php
index 8ec3d62a3..2600d48f5 100644
--- a/app/Ai/Templates/AiContentTemplate.php
+++ b/app/Ai/Templates/AiContentTemplate.php
@@ -43,14 +43,6 @@ interface AiContentTemplate
*/
public function schema(JsonSchema $schema, TemplateContext $context): array;
- /**
- * Text fields (by structured-output key) the humanizer should rewrite.
- * Empty = skip humanization.
- *
- * @return array<string, string>
- */
- public function humanizableFields(): array;
-
/**
* Build the post from the (humanized) structured output.
*
diff --git a/app/Ai/Templates/CarouselTemplate.php b/app/Ai/Templates/CarouselTemplate.php
index 9bdf3fcf2..e28b8d27d 100644
--- a/app/Ai/Templates/CarouselTemplate.php
+++ b/app/Ai/Templates/CarouselTemplate.php
@@ -4,15 +4,12 @@ declare(strict_types=1);
namespace App\Ai\Templates;
-use App\Ai\Templates\Concerns\ResolvesContentType;
use App\Enums\PostPlatform\ContentType;
use App\Services\Image\PostImagePipeline;
use Illuminate\Contracts\JsonSchema\JsonSchema;
class CarouselTemplate implements AiContentTemplate
{
- use ResolvesContentType;
-
public function key(): string
{
return 'carousel';
@@ -76,11 +73,6 @@ class CarouselTemplate implements AiContentTemplate
];
}
- public function humanizableFields(): array
- {
- return ['caption' => 'caption'];
- }
-
/**
* @param array<string, mixed> $structured
*/
diff --git a/app/Ai/Templates/ImageCardTemplate.php b/app/Ai/Templates/ImageCardTemplate.php
index 4213a7392..15ffa976f 100644
--- a/app/Ai/Templates/ImageCardTemplate.php
+++ b/app/Ai/Templates/ImageCardTemplate.php
@@ -62,15 +62,6 @@ class ImageCardTemplate implements AiContentTemplate
];
}
- public function humanizableFields(): array
- {
- return [
- 'content' => 'content',
- 'image_title' => 'image_title',
- 'image_body' => 'image_body',
- ];
- }
-
/**
* @param array<string, mixed> $structured
*/
diff --git a/app/Ai/Templates/TweetCardTemplate.php b/app/Ai/Templates/TweetCardTemplate.php
index bcd08568f..dd7fcd79a 100644
--- a/app/Ai/Templates/TweetCardTemplate.php
+++ b/app/Ai/Templates/TweetCardTemplate.php
@@ -63,12 +63,6 @@ class TweetCardTemplate implements AiContentTemplate
];
}
- /** @return array<string, string> */
- public function humanizableFields(): array
- {
- return ['tweet_text' => 'tweet_text'];
- }
-
/**
* @param array<string, mixed> $structured
*/
diff --git a/app/Services/Image/TemplateImageGenerator.php b/app/Services/Image/TemplateImageGenerator.php
index be13923b0..dbd763223 100644
--- a/app/Services/Image/TemplateImageGenerator.php
+++ b/app/Services/Image/TemplateImageGenerator.php
@@ -590,8 +590,6 @@ class TemplateImageGenerator
$bodyLineHeight = 1.55;
$paragraphGap = (int) round($bodySize * $bodyLineHeight * 0.6);
- $textMaxWidth = $cardW - 2 * $cardPadding - $avatarSize - 24;
-
$paragraphs = array_filter(array_map('trim', explode("\n\n", $tweetText)), fn ($p) => $p !== '');
$allBodyLines = [];
foreach ($paragraphs as $i => $para) {
diff --git a/tests/Feature/Ai/PostAiCreateTest.php b/tests/Feature/Ai/PostAiCreateTest.php
index 90919810d..8f588452d 100644
--- a/tests/Feature/Ai/PostAiCreateTest.php
+++ b/tests/Feature/Ai/PostAiCreateTest.php
@@ -215,7 +215,7 @@ it('rejects an unknown template', function () {
->assertJsonValidationErrors(['template']);
});
-it('requires social_account_id when the template needsAccount', function () {
+it('allows image_card without a social account', function () {
Bus::fake();
$this->actingAs($this->user)
@@ -226,3 +226,18 @@ it('requires social_account_id when the template needsAccount', function () {
])
->assertAccepted();
});
+
+it('requires social_account_id when the template needsAccount', function () {
+ Bus::fake();
+
+ $this->actingAs($this->user)
+ ->postJson(route('app.posts.ai.create'), [
+ 'format' => 'x_post',
+ 'prompt' => 'a punchy take on productivity',
+ 'template' => 'tweet_card',
+ ])
+ ->assertUnprocessable()
+ ->assertJsonValidationErrors(['social_account_id']);
+
+ Bus::assertNotDispatched(StreamPostCreation::class);
+});
diff --git a/tests/Feature/Ai/StreamPostCreationTest.php b/tests/Feature/Ai/StreamPostCreationTest.php
index 8cd73f2ef..fa16a161c 100644
--- a/tests/Feature/Ai/StreamPostCreationTest.php
+++ b/tests/Feature/Ai/StreamPostCreationTest.php
@@ -102,7 +102,7 @@ test('tweet_card template stores the tweet_text as post content and attaches a m
userId: $this->user->id,
creationId: (string) Str::uuid(),
workspaceId: $this->workspace->id,
- format: 'x_twitter',
+ format: 'x_post',
socialAccountId: $this->account->id,
imageCount: 1,
prompt: 'A punchy take on productivity',
@@ -113,6 +113,10 @@ test('tweet_card template stores the tweet_text as post content and attaches a m
expect($post->content)->toBe('Hello world\n\nSecond para.')
->and($post->media)->toHaveCount(1);
+
+ $platform = PostPlatform::where('social_account_id', $this->account->id)->firstOrFail();
+
+ expect($platform->content_type)->toBe(ContentType::XPost);
});
test('the humanizer is given the same platform context as the generator so the rewrite honours the character cap', function () {