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

This commit is contained in:
Paulo Castellano 2026-06-17 17:56:52 -03:00
parent 799a151321
commit 24d9653f6e
7 changed files with 21 additions and 35 deletions

View file

@ -43,14 +43,6 @@ public function promptView(): string;
*/
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.
*

View file

@ -4,15 +4,12 @@
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 @@ public function schema(JsonSchema $schema, TemplateContext $context): array
];
}
public function humanizableFields(): array
{
return ['caption' => 'caption'];
}
/**
* @param array<string, mixed> $structured
*/

View file

@ -62,15 +62,6 @@ public function schema(JsonSchema $schema, TemplateContext $context): array
];
}
public function humanizableFields(): array
{
return [
'content' => 'content',
'image_title' => 'image_title',
'image_body' => 'image_body',
];
}
/**
* @param array<string, mixed> $structured
*/

View file

@ -63,12 +63,6 @@ public function schema(JsonSchema $schema, TemplateContext $context): array
];
}
/** @return array<string, string> */
public function humanizableFields(): array
{
return ['tweet_text' => 'tweet_text'];
}
/**
* @param array<string, mixed> $structured
*/

View file

@ -590,8 +590,6 @@ public function renderTweetCard(Workspace $workspace, SocialAccount $socialAccou
$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) {

View file

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

View file

@ -102,7 +102,7 @@ function runStreamPostCreation(string $format, SocialAccount $account, int $imag
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 @@ function runStreamPostCreation(string $format, SocialAccount $account, int $imag
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 () {