trypost/tests/Feature
Paulo Castellano 886fca3152 feat: use LLM to polish brand autofill when provider is configured
When config('trypost.ai.text_provider') points to a provider whose
API key is populated (services.gemini.api_key or
services.openai.api_key), the autofill action pipes the homepage
markdown through a BrandAnalyzer agent with structured output to
produce higher-quality values for:

- brand_description — 2-3 sentences summarizing the company based on
  the actual page content, not the raw meta description (which is
  often generic SEO boilerplate)
- brand_tone — classified into one of our seven enum values from the
  writing style on the page
- content_language — detected from the actual content (more reliable
  than <html lang> which is often wrong)
- brand_voice_notes — concrete writing guidelines inferred from the
  site's style, written in the detected language

When the LLM provider is NOT configured (open-source self-hosted
deploys without API keys), the action keeps the existing
deterministic meta-tag-only flow — no crash, no noise, no LLM cost.
When the LLM fails mid-request, we log a warning and fall back to
the meta-tag values so the user still gets something useful.

Stack additions:
- league/html-to-markdown ^5.1 converts the main body to clean
  markdown for the LLM input (truncated to 4000 chars).
- BrandAnalyzer agent (Agent + HasStructuredOutput) with schema
  enums matching our allowed tones and languages.
- resources/views/prompts/brand_analyzer.blade.php holds the
  instructions, including explicit enum lists and examples of good
  voice_notes.

Frontend: Brand.vue now also fills brand_tone and brand_voice_notes
from the response when present.

Tests (+3): LLM-configured happy path, no-credentials fallback
(asserts BrandAnalyzer is never prompted via preventStrayPrompts),
and LLM-exception fallback (meta tags win, brand_tone stays null).
2026-04-16 11:33:02 -03:00
..
Ai feat: use LLM to polish brand autofill when provider is configured 2026-04-16 11:33:02 -03:00
Api feat: add PostCommentCreated broadcast event 2026-04-15 20:11:36 -03:00
Auth chore: tracking, gtm and more 2026-03-30 21:32:43 -03:00
Commands feat: publishing hardening — content sanitization, validation, scopes, stuck recovery 2026-04-01 11:25:25 -03:00
Controllers feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
Jobs feat: add PostCommentCreated broadcast event 2026-04-15 20:11:36 -03:00
Listeners feat: redesign billing, onboarding, sidebar, and settings architecture 2026-04-15 00:33:38 -03:00
Mcp feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
Middleware feat: redesign billing, onboarding, sidebar, and settings architecture 2026-04-15 00:33:38 -03:00
Services/Social fix: overhaul social publishing — validation, uploads, token refresh 2026-03-31 19:25:19 -03:00
Settings feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
Social feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
AcceptInviteControllerTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
AccountControllerTest.php fix: self-host billing bypass, Facebook API metrics migration, X token refresh, and duplicate social accounts 2026-04-15 09:46:18 -03:00
AiUsageLogTest.php fix: update monthlyCount() callers to pass UsageType enum 2026-04-16 09:29:37 -03:00
ApiKeyControllerTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
AssetControllerTest.php feat: integrate Giphy support and add trending endpoints for media assets 2026-04-15 11:02:10 -03:00
BillingControllerTest.php fix: self-host billing bypass, Facebook API metrics migration, X token refresh, and duplicate social accounts 2026-04-15 09:46:18 -03:00
CreateUserActionTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
ExampleTest.php refactor: settings redesign, Spanish translations, language system, strict_types 2026-03-30 00:20:43 -03:00
GoogleAuthToggleTest.php fix: keep Google OAuth routes always registered and add tests 2026-04-14 14:28:17 -03:00
InstagramFacebookIntegrationTest.php feat: add PostCommentCreated broadcast event 2026-04-15 20:11:36 -03:00
LimitEnforcementTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
MediaControllerTest.php feat: add PostCommentCreated broadcast event 2026-04-15 20:11:36 -03:00
NotificationControllerTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
OnboardingControllerTest.php feat: add brand autofill from website URL in onboarding 2026-04-16 11:13:54 -03:00
PlanSeederTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
PlanTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
PostAssistantTest.php refactor: migrate PostAssistantController to SDK Agent + tools 2026-04-16 09:59:10 -03:00
PostCommentControllerTest.php test: add PostCommentController feature tests 2026-04-15 20:18:21 -03:00
PostControllerTest.php feat: add PostCommentCreated broadcast event 2026-04-15 20:11:36 -03:00
PostSearchTest.php feat: add PostCommentCreated broadcast event 2026-04-15 20:11:36 -03:00
SendPostHogEventTest.php chore: posthog, ui, features and more 2026-03-30 21:18:07 -03:00
SignupSuccessControllerTest.php refactor: code review fixes — policies, enums, data_get, tests 2026-03-31 00:40:18 -03:00
SocialAccountToggleTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
SocialControllerTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
SocialLoginControllerTest.php chore: tracking, gtm and more 2026-03-30 21:32:43 -03:00
StripeEventListenerTest.php feat: redesign billing, onboarding, sidebar, and settings architecture 2026-04-15 00:33:38 -03:00
UsageControllerTest.php fix: self-host billing bypass, Facebook API metrics migration, X token refresh, and duplicate social accounts 2026-04-15 09:46:18 -03:00
VerifyWorkspaceConnectionsTest.php fix: VerifyWorkspaceConnections uses TokenExpired/Disconnected escalation, eager load workspace 2026-04-01 11:52:03 -03:00
WorkspaceBillingTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
WorkspaceControllerTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
WorkspaceHashtagControllerTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
WorkspaceInviteControllerTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
WorkspaceLabelControllerTest.php feat: introduce Account entity as billing owner and refactor architecture 2026-04-14 22:22:04 -03:00
YouTubeAnalyticsTest.php refactor: optimize json parsing and add missing test coverage 2026-04-14 13:36:22 -03:00