Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ class PersonalityController extends Controller
private const MBTI64_V85_SECTION_PREFIX = 'v8_5_';

private const MBTI64_V85_DUPLICATE_LEGACY_SECTION_KEYS = [
'quick_answer',
'meaning',
'a_t_difference',
'core_traits',
'careers_work_style',
'relationships_communication',
'strengths_blind_spots',
'common_misreads',
'similar_types',
'faq',
];

private const MBTI64_V85_DUPLICATE_LEGACY_SECTION_PREFIXES = [
'career.',
'growth.',
'relationships.',
];

use RespondsWithNotFound;
Expand Down Expand Up @@ -1636,7 +1645,15 @@ private function publicSectionPayloads(PersonalityProfile $profile, ?Personality
}

if ($this->hasV85FirstClassSections($sections->keys()->all())) {
foreach (self::MBTI64_V85_DUPLICATE_LEGACY_SECTION_KEYS as $sectionKey) {
foreach ($sections->keys()->all() as $sectionKey) {
Comment on lines 1647 to +1648

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Filter V8.5 duplicates from projection sections too

When a V8.5 variant is requested, show() still returns $projection under personality_public_projection_v1/mbti_public_projection_v1, and that projection is built before this filter from all enabled variant sections via MbtiPersonalityProfileAuthoritySourceAdapter::overlayVariant(). This new suppression only removes duplicate keys from the top-level sections, so the same detail response still exposes the legacy career.*/growth.*/relationships.* paragraphs through *.sections for clients that render the projection. Apply the suppression to the projection as well, or build the projection from the filtered section set.

Useful? React with 👍 / 👎.

if (! is_string($sectionKey)) {
continue;
}

if (! $this->shouldSuppressV85DuplicateSection($sectionKey)) {
continue;
}

$sections->forget($sectionKey);
}
}
Expand Down Expand Up @@ -1664,6 +1681,21 @@ private function hasV85FirstClassSections(array $sectionKeys): bool
return false;
}

private function shouldSuppressV85DuplicateSection(string $sectionKey): bool
{
if (in_array($sectionKey, self::MBTI64_V85_DUPLICATE_LEGACY_SECTION_KEYS, true)) {
return true;
}

foreach (self::MBTI64_V85_DUPLICATE_LEGACY_SECTION_PREFIXES as $prefix) {
if (str_starts_with($sectionKey, $prefix)) {
return true;
}
}

return false;
}

private function sanitizeV85PublicBody(string $sectionKey, mixed $body): mixed
{
if (! str_starts_with($sectionKey, 'v8_5_module_') || ! is_string($body)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,19 @@ public function test_write_promotes_only_fixed_v8_5_v5_bilingual_sixty_four_subs
foreach ($this->expectedV85V5FirstClassSectionKeys() as $legacySectionKey) {
$this->assertNotContains($legacySectionKey, $sectionKeys, $legacySectionKey);
}
foreach ($this->expectedV85V5SuppressedPublicSectionKeys() as $legacySectionKey) {
$this->assertNotContains($legacySectionKey, $sectionKeys, $legacySectionKey);
}
foreach ($sectionKeys as $sectionKey) {
$this->assertFalse(str_starts_with($sectionKey, 'career.'), $sectionKey);
$this->assertFalse(str_starts_with($sectionKey, 'growth.'), $sectionKey);
$this->assertFalse(str_starts_with($sectionKey, 'relationships.'), $sectionKey);
}

$this->assertContains('related_content', $sectionKeys);
$this->assertContains('mbti64_promotion_metadata', $sectionKeys);
$this->assertNoExactDuplicateVisibleApiParagraphs((array) ($detail['sections'] ?? []));

$apiModule = collect((array) ($detail['sections'] ?? []))
->firstWhere('section_key', 'v8_5_module_01_core_reading');
$this->assertIsArray($apiModule);
Expand Down Expand Up @@ -2023,6 +2036,48 @@ private function expectedV85V5FirstClassSectionKeys(): array
];
}

/**
* @return list<string>
*/
private function expectedV85V5SuppressedPublicSectionKeys(): array
{
return [
'quick_answer',
'common_misreads',
'faq',
];
}

/**
* @param array<int,array<string,mixed>> $sections
*/
private function assertNoExactDuplicateVisibleApiParagraphs(array $sections): void
{
$seen = [];
foreach ($sections as $section) {
$sectionKey = (string) ($section['section_key'] ?? '');
$body = (string) ($section['body_md'] ?? '');
foreach (preg_split('/\R{2,}/u', $body) ?: [] as $index => $paragraph) {
$normalized = trim((string) preg_replace('/\s+/u', ' ', $paragraph));
if (mb_strlen($normalized) < 18) {
continue;
}

$this->assertArrayNotHasKey(
$normalized,
$seen,
sprintf(
'Duplicate visible API paragraph in %s[%d]; first seen at %s.',
$sectionKey,
$index,
$seen[$normalized] ?? 'unknown'
)
);
$seen[$normalized] = sprintf('%s[%d]', $sectionKey, $index);
}
}
}

/**
* @return list<string>
*/
Expand Down