fix(core,board,page,ecommerce,basic,pay): FULLTEXT 게이트·검색 실패 표면화와 페이지네이션/접두사 결함 정비
- 공개 : MATCH 는 커버 인덱스가 있을 때만 조립 — 부재 시 LIKE 폴백 + 1회 경고, 카테고리 검색 예외를 categories_failed/search_failed 로 표면화하고 basic 템플릿이 오류 안내 렌더 - 공개 동근원: paginate page 명시 전달 (언어팩 check-updates, 상품 문의 목록) - 공개 동근원: raw SQL 접두사/별칭 하드코딩 정리 (board 시더, 7.0.6 업그레이드 스텝, 결제 3플러그인 컨트롤러 51지점 모델 파생 전환) - audit 룰 3종 신설 + repository-raw-hardcoded-table 컨트롤러 확대, 확장 TestCase 오토로더 중복 선언 가드 16지점, ja 언어팩 동기
This commit is contained in:
1 parent
3ccfb24417
commit
7f457a05b3
77 files changed
+2578
-526
No files matched your search
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\Public;
|
||||
|
||||
use App\Enums\TotalRelation;
|
||||
use App\Extension\HookManager;
|
||||
use App\Search\SearchCategoryPayload;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 통합 검색 실패 표면화 계약 테스트 (공개 이슈 #103)
|
||||
*
|
||||
* 카테고리 검색이 예외로 실패하면 화면은 "검색 결과 없음" 과 구분되는 오류 안내를
|
||||
* 그려야 한다. 그 판정 근거인 `categories_failed` / `search_failed` 를 코어가
|
||||
* `counts_are_exact` 와 동형으로 **일괄 조립**하는 계약을 고정한다 — 모듈별 복사에
|
||||
* 맡기면 빠지는 카테고리가 생긴다.
|
||||
*
|
||||
* @scenario case=search_failure_flags
|
||||
*
|
||||
* @effects failed_flag_in_response,
|
||||
* failure_flags_default_to_false
|
||||
*/
|
||||
class PublicSearchControllerFailureFlagTest extends TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
HookManager::clearFilter('core.search.results');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* 실패한 카테고리가 categories_failed / search_failed 로 표면화되는지 확인
|
||||
*
|
||||
* @effects failed_flag_in_response
|
||||
*/
|
||||
public function test_failed_category_surfaces_in_response_flags(): void
|
||||
{
|
||||
// Given: 한 카테고리는 실패, 다른 하나는 정상인 검색 결과
|
||||
HookManager::addFilter('core.search.results', function (array $results): array {
|
||||
$results['alpha'] = SearchCategoryPayload::failed();
|
||||
$results['beta'] = [
|
||||
'total' => 3,
|
||||
'total_relation' => TotalRelation::Exact->value,
|
||||
'total_is_exact' => true,
|
||||
'items' => [],
|
||||
];
|
||||
|
||||
return $results;
|
||||
}, 5);
|
||||
|
||||
// When: 통합 검색을 호출
|
||||
$response = $this->getJson('/api/search?q=테스트');
|
||||
|
||||
// Then: HTTP 200 이되 실패가 응답 키로 구분된다
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('data.categories_failed.alpha', true);
|
||||
$response->assertJsonPath('data.categories_failed.beta', false);
|
||||
$response->assertJsonPath('data.search_failed', true);
|
||||
// 실패한 0건은 "정확한 0건" 이 아니다
|
||||
$response->assertJsonPath('data.counts_are_exact.alpha', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 실패가 없으면 두 키 모두 false 로 존재하는지 확인
|
||||
*
|
||||
* 키 자체가 없으면 화면이 "실패 정보 없음(구버전)" 과 "실패 없음" 을 구분하지 못한다.
|
||||
*
|
||||
* @effects failure_flags_default_to_false
|
||||
*/
|
||||
public function test_flags_default_to_false_when_no_failure(): void
|
||||
{
|
||||
// Given: 정상 카테고리만 있는 검색 결과
|
||||
HookManager::addFilter('core.search.results', function (array $results): array {
|
||||
$results['alpha'] = [
|
||||
'total' => 7,
|
||||
'total_relation' => TotalRelation::Exact->value,
|
||||
'total_is_exact' => true,
|
||||
'items' => [],
|
||||
];
|
||||
|
||||
return $results;
|
||||
}, 5);
|
||||
|
||||
// When: 통합 검색을 호출
|
||||
$response = $this->getJson('/api/search?q=테스트');
|
||||
|
||||
// Then: 실패 키는 존재하되 전부 false
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('data.categories_failed.alpha', false);
|
||||
$response->assertJsonPath('data.search_failed', false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Search;
|
||||
|
||||
use App\Search\Contracts\FulltextSearchable;
|
||||
use App\Search\Engines\DatabaseFulltextEngine;
|
||||
use App\Search\KeywordSearch;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Laravel\Scout\Builder;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* FULLTEXT 인덱스 부재 게이트 검증 (공개 이슈 #103)
|
||||
*
|
||||
* 회귀 배경: `applyFulltextPredicate()` / `performSearch()` 의 게이트가 드라이버명만
|
||||
* 검사해, MySQL 인데 대상 테이블에 FULLTEXT 인덱스가 없는 설치(부분 실패 설치 등)에서
|
||||
* `1191 Can't find FULLTEXT index` 가 발생했다. 그 오류는 리스너의 catch 에 삼켜져
|
||||
* 화면에는 "검색 결과 0건" 으로만 나타났다.
|
||||
*
|
||||
* 수정 후 계약: 드라이버가 지원해도 대상 테이블·컬럼 조합을 커버하는 FULLTEXT 인덱스가
|
||||
* 없으면 LIKE 로 내려가고, 그 사실을 조합당 프로세스 1회 경고로 남긴다.
|
||||
*/
|
||||
class DatabaseFulltextEngineIndexGateTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 프리픽스 미포함 테이블명 — FULLTEXT 인덱스를 만들지 않는 probe 테이블.
|
||||
*/
|
||||
private const TABLE = 'ft_gate_fixtures';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (! DatabaseFulltextEngine::supportsFulltext()) {
|
||||
$this->markTestSkipped('FULLTEXT 를 제공하지 않는 DBMS 입니다.');
|
||||
}
|
||||
|
||||
DatabaseFulltextEngine::forgetFulltextIndexCatalog();
|
||||
|
||||
Schema::dropIfExists(self::TABLE);
|
||||
Schema::create(self::TABLE, function ($table): void {
|
||||
$table->id();
|
||||
$table->string('title');
|
||||
$table->text('content');
|
||||
});
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Schema::dropIfExists(self::TABLE);
|
||||
DatabaseFulltextEngine::forgetFulltextIndexCatalog();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* T1-a: 인덱스가 없는 테이블은 MATCH 대신 LIKE 폴백으로 조립되어야 한다.
|
||||
*
|
||||
* 수정 전에는 드라이버만 검사해 MATCH 가 조립됐다 (실행 시 1191).
|
||||
*
|
||||
* @effects like_fallback_on_missing_index
|
||||
*/
|
||||
public function test_like_fallback_when_table_has_no_fulltext_index(): void
|
||||
{
|
||||
$query = FulltextGateFixture::query();
|
||||
|
||||
KeywordSearch::apply($query, ['title', 'content'], '문의');
|
||||
|
||||
$sql = strtolower($query->toSql());
|
||||
|
||||
$this->assertStringNotContainsString('match(', $sql, '인덱스 없는 테이블에 MATCH 가 조립되면 실행 시 1191 이 됩니다.');
|
||||
$this->assertStringContainsString('like', $sql, 'LIKE 폴백이 조립되어야 합니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* T1-b: 복합 인덱스는 단일 컬럼 MATCH 를 커버하지 못한다 (집합 동등 비교, 순서 무관).
|
||||
*/
|
||||
public function test_composite_index_does_not_cover_single_column(): void
|
||||
{
|
||||
DatabaseFulltextEngine::primeFulltextIndexCatalog([
|
||||
'board_posts' => [['title', 'content']],
|
||||
]);
|
||||
|
||||
$this->assertFalse(
|
||||
DatabaseFulltextEngine::fulltextIndexCoversColumns('board_posts', ['title']),
|
||||
'복합 (title,content) 인덱스는 MATCH(title) 단독을 커버하지 못합니다.'
|
||||
);
|
||||
$this->assertTrue(
|
||||
DatabaseFulltextEngine::fulltextIndexCoversColumns('board_posts', ['title', 'content']),
|
||||
'컬럼 집합이 정확히 일치하면 커버합니다.'
|
||||
);
|
||||
$this->assertTrue(
|
||||
DatabaseFulltextEngine::fulltextIndexCoversColumns('board_posts', ['content', 'title']),
|
||||
'집합 비교는 순서 무관이어야 합니다 — 깨지면 정상 경로가 LIKE 로 강등됩니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* T1-c: Scout 경로(performSearch)는 컬럼마다 단일 MATCH 를 만들므로,
|
||||
* 각 컬럼이 개별 인덱스로 커버되지 않으면 LIKE 로 내려가야 한다.
|
||||
*/
|
||||
public function test_scout_search_falls_back_when_columns_lack_individual_indexes(): void
|
||||
{
|
||||
// 복합 인덱스만 존재하는 상황을 시드 — per-column MATCH 는 커버되지 않는다.
|
||||
DatabaseFulltextEngine::primeFulltextIndexCatalog([
|
||||
self::TABLE => [['title', 'content']],
|
||||
]);
|
||||
|
||||
$engine = new DatabaseFulltextEngine;
|
||||
$results = $engine->paginate(new Builder(new FulltextGateFixture, '문의'), 10, 1);
|
||||
|
||||
$this->assertNotNull($results['query']);
|
||||
|
||||
$sql = strtolower($results['query']->toSql());
|
||||
|
||||
$this->assertStringNotContainsString('match(', $sql, 'per-column MATCH 는 복합 인덱스로 커버되지 않으므로 조립되면 안 됩니다.');
|
||||
$this->assertStringContainsString('like', $sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* T1-f: 두 게이트의 LIKE 폴백이 같은 술어를 만든다 — 검색어의 `%`/`_` 는
|
||||
* 와일드카드가 아니라 글자로 취급되어야 한다.
|
||||
*
|
||||
* 게이트 ①(applyFulltextPredicate)은 `KeywordSearch::applyLikeMatch()` 로 내려가
|
||||
* escape 를 거치는데, 게이트 ②(performSearch)가 LIKE 를 손으로 조립하면 같은
|
||||
* "부분일치" 인데도 `100%` 같은 검색어에서 결과가 갈린다. 게이트 ② 신설로
|
||||
* MySQL 트래픽이 처음 이 경로에 유입되므로 두 경로의 술어를 여기서 고정한다.
|
||||
*
|
||||
* @effects like_fallback_on_missing_index
|
||||
*/
|
||||
public function test_scout_like_fallback_escapes_wildcards_like_the_shared_path(): void
|
||||
{
|
||||
$keyword = '100%_할인';
|
||||
$expected = '%'.KeywordSearch::escapeLikeWildcards($keyword).'%';
|
||||
|
||||
// 게이트 ① — 공용 경로. 이 경로가 escape 된 패턴을 만든다는 것을 먼저 확정한다.
|
||||
$shared = FulltextGateFixture::query();
|
||||
KeywordSearch::apply($shared, ['title', 'content'], $keyword);
|
||||
|
||||
$this->assertContains(
|
||||
$expected,
|
||||
$shared->getBindings(),
|
||||
'공용 폴백 경로가 escape 된 패턴을 만들지 않으면 이 테스트의 기준값이 무의미합니다.'
|
||||
);
|
||||
|
||||
// 게이트 ② — Scout 경로. 복합 인덱스만 시드해 per-column MATCH 를 미커버로 만든다.
|
||||
DatabaseFulltextEngine::primeFulltextIndexCatalog([
|
||||
self::TABLE => [['title', 'content']],
|
||||
]);
|
||||
|
||||
$engine = new DatabaseFulltextEngine;
|
||||
$results = $engine->paginate(new Builder(new FulltextGateFixture, $keyword), 10, 1);
|
||||
|
||||
$this->assertNotNull($results['query']);
|
||||
|
||||
$this->assertContains(
|
||||
$expected,
|
||||
$results['query']->getBindings(),
|
||||
'Scout 폴백이 % 와 _ 를 escape 하지 않으면 검색어가 와일드카드로 해석되어 공용 경로와 결과가 갈립니다.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* T1-d: 인덱스 부재 폴백 경고는 테이블+컬럼 조합당 프로세스 1회만 남는다.
|
||||
*
|
||||
* @effects missing_index_fallback_logged_once
|
||||
*/
|
||||
public function test_missing_index_fallback_is_logged_once_per_table_and_columns(): void
|
||||
{
|
||||
Log::spy();
|
||||
|
||||
$apply = function (array $columns): void {
|
||||
$query = FulltextGateFixture::query();
|
||||
KeywordSearch::apply($query, $columns, '문의');
|
||||
};
|
||||
|
||||
$apply(['title', 'content']);
|
||||
$apply(['title', 'content']);
|
||||
|
||||
Log::shouldHaveReceived('warning')
|
||||
->withArgs(fn (string $message) => str_contains($message, 'FULLTEXT'))
|
||||
->once();
|
||||
|
||||
$apply(['title']);
|
||||
|
||||
Log::shouldHaveReceived('warning')
|
||||
->withArgs(fn (string $message) => str_contains($message, 'FULLTEXT'))
|
||||
->twice();
|
||||
}
|
||||
|
||||
/**
|
||||
* T1-e: addFulltextIndex 성공 직후 카탈로그가 무효화되어, 새 인덱스가
|
||||
* forget 호출 없이도 다음 판정에 반영되어야 한다.
|
||||
*/
|
||||
public function test_add_fulltext_index_invalidates_catalog(): void
|
||||
{
|
||||
$this->assertFalse(
|
||||
DatabaseFulltextEngine::fulltextIndexCoversColumns(self::TABLE, ['title']),
|
||||
'probe 테이블은 인덱스 없이 생성되므로 커버되지 않아야 합니다 (카탈로그 적재 확인).'
|
||||
);
|
||||
|
||||
DatabaseFulltextEngine::addFulltextIndex(self::TABLE, 'ft_'.self::TABLE.'_title', 'title');
|
||||
|
||||
$this->assertTrue(
|
||||
DatabaseFulltextEngine::fulltextIndexCoversColumns(self::TABLE, ['title']),
|
||||
'DDL 성공 직후 카탈로그가 무효화되어 새 인덱스가 반영되어야 합니다.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 인덱스 게이트 테스트 전용 픽스처 모델 (FULLTEXT 인덱스 없는 테이블).
|
||||
*/
|
||||
class FulltextGateFixture extends Model implements FulltextSearchable
|
||||
{
|
||||
use Searchable;
|
||||
|
||||
protected $table = 'ft_gate_fixtures';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function searchableColumns(): array
|
||||
{
|
||||
return ['title', 'content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function searchableWeights(): array
|
||||
{
|
||||
return ['title' => 3.0, 'content' => 1.0];
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,20 @@ class DatabaseFulltextEngineTest extends TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
$this->engine = new DatabaseFulltextEngine;
|
||||
|
||||
// 픽스처 테이블(test_table)은 실존하지 않으므로 인덱스 카탈로그를 시드해
|
||||
// MATCH 조립 경로를 검증한다 — 시드하지 않으면 인덱스 부재 게이트(#103)가
|
||||
// LIKE 로 내려 보내 조립 단언이 무의미해진다.
|
||||
DatabaseFulltextEngine::primeFulltextIndexCatalog([
|
||||
'test_table' => [['name']],
|
||||
]);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
DatabaseFulltextEngine::forgetFulltextIndexCatalog();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services;
|
||||
|
||||
use App\Contracts\Repositories\LanguagePackRepositoryInterface;
|
||||
use App\Models\LanguagePack;
|
||||
use App\Services\LanguagePackService;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 언어팩 업데이트 확인의 순회 범위 계약 테스트 (공개 이슈 #102 동형)
|
||||
*
|
||||
* 종전에는 `repository->paginate([], 1000)` 로 전량 순회를 의도했는데, page 인자를
|
||||
* 지정하지 않아 HTTP `page` 파라미터가 암묵 해석됐다. `?page=2` 상태로 업데이트 확인을
|
||||
* 호출하면 offset=1000 이 적용되어 `checked: 0` 의 조용한 오답이 됐다.
|
||||
*
|
||||
* 수정 후 계약: 업데이트 확인은 요청의 page 파라미터와 무관하게 설치된 전체 팩을 순회한다.
|
||||
*
|
||||
* @scenario case=update_check_scope
|
||||
*
|
||||
* @effects update_check_ignores_request_page
|
||||
*/
|
||||
class LanguagePackServiceUpdateCheckScopeTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* 요청에 page=2 가 실려 있어도 순회 대상이 설치된 전체 팩인지 확인
|
||||
*
|
||||
* 순회 계층에서 건수를 정확히 단언한다 — 서비스 `checked` 는 GitHub URL 도 번들
|
||||
* manifest 도 없는 팩을 설계상 건너뛰므로 설치본 수와 같지 않고, 그 판정을 테스트가
|
||||
* 재구현하면 규칙이 두 벌이 되어 한쪽만 바뀐다. 결함이 있던 자리는 순회 그 자체다.
|
||||
*/
|
||||
public function test_update_check_traverses_all_packs_regardless_of_request_page(): void
|
||||
{
|
||||
// Given: bundled manifest 가 실존하는 설치 팩 1건 (GitHub 미설정 → bundled 폴백, 네트워크 없음)
|
||||
LanguagePack::query()->firstOrCreate(
|
||||
['identifier' => 'g7-core-ja'],
|
||||
[
|
||||
'vendor' => 'g7',
|
||||
'scope' => 'core',
|
||||
'target_identifier' => 'core',
|
||||
'locale' => 'ja',
|
||||
'locale_name' => 'Japanese',
|
||||
'locale_native_name' => '日本語',
|
||||
'text_direction' => 'ltr',
|
||||
'version' => '0.0.1',
|
||||
'license' => 'MIT',
|
||||
'status' => 'active',
|
||||
'source_type' => 'bundled',
|
||||
'manifest' => ['identifier' => 'g7-core-ja', 'version' => '0.0.1'],
|
||||
]
|
||||
);
|
||||
|
||||
$installed = LanguagePack::query()->count();
|
||||
$this->assertGreaterThan(0, $installed, '설치된 팩이 없어 순회 범위를 측정할 수 없습니다.');
|
||||
|
||||
// 페이지네이터의 현재 페이지 암묵 해석이 읽는 자리 — #102 재현 조건
|
||||
request()->merge(['page' => 2]);
|
||||
|
||||
$traversed = app(LanguagePackRepositoryInterface::class)->allForUpdateCheck();
|
||||
|
||||
$this->assertCount(
|
||||
$installed,
|
||||
$traversed,
|
||||
"page=2 요청 상태에서 순회 대상이 {$traversed->count()} 건이었습니다 (설치 {$installed} 건) — 페이지네이션 암묵 page 해석(#102 동형)입니다."
|
||||
);
|
||||
|
||||
// 서비스 경로도 같은 순회를 타는지 — 종단에서 0건 오답이 재발하지 않음을 고정
|
||||
$result = app(LanguagePackService::class)->checkUpdates();
|
||||
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$result['checked'],
|
||||
'업데이트 확인이 0건 순회했습니다 — 순회는 정상인데 서비스가 다른 경로를 쓰고 있습니다.'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user