feat(core,admin_basic): 번들 비-ko 언어팩 자동 프로비저닝 + 미설치·드리프트 발견성

신규 설치/복구 시 비-ko/en 번들 언어팩(ja 등)이 자동으로 채워지지 않아
런타임에 오류 없이 조용히 ko 로 폴백하고, 운영자가 이를 알아채기 어려웠다.
두 결손을 함께 해소한다.

프로비저닝(SSoT):
- language-pack:provision 멱등 커맨드 신설. supported_locales ∖ {ko,en} 의
 미설치 번들 팩을 설치하고, 설치본 파일이 사라진 드리프트 팩(슬롯 점유로
 getUninstalledBundledPacks 가 못 잡는)도 복구 경로로 겸한다. 재실행 시 0건 수렴.

발견성:
- CLI language-pack:list 를 Service::list 경유로 전환해 미설치(uninstalled)와
 드리프트(active·파일 없음)를 함께 표면화.
- files_missing / bundled_source_available 파생 플래그를 Resource 에 노출.
- 관리자 언어팩 목록에 "파일 없음" 배지 + 원클릭 재설치(기존 install-bundled 모달
 재사용). 재설치 경로만 auto_activate 로 바인딩해 복구 후 active 를 유지한다.

회귀 방지:
- 정적 룰 lang-pack-supported-locale-has-bundle(선언 로케일 ↔ 번들 소스 부재) 신설,
 lang-pack-installed-version-drift 를 프로비저닝된 환경 한정으로 확장.
- 백엔드/레이아웃/E2E/시나리오 테스트 + 룰 fixture 추가.

부수 수정:
- 프로비저닝 작업 중 표면화된 ecommerce 언어팩 시더 테스트 격리결함 수정
 (modules 등록 행을 매 테스트가 직접 보장 — 프로세스당 1회 시딩 전제 붕괴 대응).
This commit is contained in:
HeuJung committed 2026-07-27 14:58:48 +09:00
1 parent 6b791679a6
commit 3d8890b118
23 files changed
+1574 -30

No files matched your search

@@ -0,0 +1,87 @@
<?php
namespace Tests\Feature\LanguagePack;
use App\Enums\LanguagePackScope;
use App\Enums\LanguagePackStatus;
use App\Models\LanguagePack;
use App\Services\LanguagePackService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
/**
* LanguagePackService::list() 의 드리프트 파생 상태(files_missing) 검증 (이슈 #496 결손 2).
*
* DB 에 active 로 기록됐으나 설치본 디렉토리(lang-packs/{id})가 부재한 행은
* 런타임에 조용히 base locale 로 폴백한다. list() 가 이를 files_missing=true 로 표면화해야 한다.
*/
class ListDriftDetectionTest extends TestCase
{
use RefreshDatabase;
private LanguagePackService $service;
protected function setUp(): void
{
parent::setUp();
$this->service = app(LanguagePackService::class);
}
/**
* @effects active_row_with_missing_install_dir_flagged_files_missing,
* third_party_pack_without_bundle_source_not_offered_for_reinstall
*/
public function test_active_row_with_missing_install_dir_is_flagged(): void
{
// 설치본 디렉토리(lang-packs/{id})가 실재하지 않는 식별자로 active 행 생성 → 드리프트
$id = 'test-drift-missing-ja';
LanguagePack::query()->create([
'identifier' => $id,
'vendor' => 'test',
'scope' => LanguagePackScope::Core->value,
'target_identifier' => null,
'locale' => 'ja',
'locale_name' => 'Japanese',
'locale_native_name' => '日本語',
'text_direction' => 'ltr',
'version' => '1.0.0',
'status' => LanguagePackStatus::Active->value,
'is_protected' => false,
'manifest' => [],
'source_type' => 'zip',
]);
$paginator = $this->service->list([], 100);
$found = collect($paginator->items())->firstWhere('identifier', $id);
$this->assertNotNull($found, 'active 행이 목록에 나타나야 함');
$this->assertTrue(
(bool) $found->getAttribute('files_missing'),
'설치본 디렉토리가 없는 active 행은 files_missing=true 여야 함'
);
// 이 식별자는 lang-packs/_bundled/ 에 대응 소스가 없다 → 번들 재설치로 복구할 수 없다.
// 화면은 이 플래그로 재설치 버튼 노출을 가르므로, 복구 불가 팩에 버튼이 뜨면 안 된다.
$this->assertFalse(
(bool) $found->getAttribute('bundled_source_available'),
'번들 소스가 없는 팩은 bundled_source_available=false 여야 함'
);
}
/**
* @effects virtual_builtin_rows_not_flagged
*/
public function test_virtual_builtin_rows_are_not_flagged(): void
{
// 코어 ko/en 가상 보호 행은 lang/{locale}/ 로 항상 존재 → 드리프트 아님
$paginator = $this->service->list([], 100);
$koPack = collect($paginator->items())
->first(fn ($p) => $p->scope === LanguagePackScope::Core->value && $p->locale === 'ko');
$this->assertNotNull($koPack, '코어 ko 가상 행이 존재해야 함');
$this->assertFalse(
(bool) $koPack->getAttribute('files_missing'),
'가상 보호 행은 files_missing 대상이 아님'
);
}
}
@@ -0,0 +1,83 @@
<?php
namespace Tests\Feature\LanguagePack;
use App\Enums\LanguagePackScope;
use App\Enums\LanguagePackStatus;
use App\Models\LanguagePack;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
/**
* language-pack:list 커맨드 회귀 테스트 (이슈 #496 결손 2 — B1).
*
* 커맨드가 repository->paginate() 직접 호출에서 Service::list() 경유로 전환되어,
* 설치된 DB 행뿐 아니라 (1) 번들에 있으나 미설치(uninstalled) 및 (2) DB active 인데
* 설치본 파일 부재(드리프트)를 함께 표면화하는지 출력으로 검증한다.
*
* repository->paginate() 로 되돌리면 미설치/드리프트가 출력에서 사라져 이 테스트가 회귀를 잡는다.
*
* Symfony Table 출력은 PendingCommand::expectsOutputToContain 으로 신뢰성 있게 캡처되지 않으므로
* Artisan::call() + Artisan::output() 로 렌더된 원문을 직접 검사한다.
*/
class ListLanguagePackCommandTest extends TestCase
{
use RefreshDatabase;
/**
* @effects cli_list_surfaces_uninstalled_and_drift
*/
public function test_lists_drift_row_with_files_missing_marker(): void
{
// 설치본 디렉토리(lang-packs/{id})가 실재하지 않는 active 행 → 드리프트
$id = 'test-drift-missing-ja';
LanguagePack::query()->create([
'identifier' => $id,
'vendor' => 'test',
'scope' => LanguagePackScope::Core->value,
'target_identifier' => null,
'locale' => 'ja',
'locale_name' => 'Japanese',
'locale_native_name' => '日本語',
'text_direction' => 'ltr',
'version' => '1.0.0',
'status' => LanguagePackStatus::Active->value,
'is_protected' => false,
'manifest' => [],
'source_type' => 'zip',
]);
$exit = Artisan::call('language-pack:list');
$out = Artisan::output();
$this->assertSame(0, $exit);
$this->assertStringContainsString($id, $out, '드리프트 행이 목록에 나타나야 함');
$this->assertStringContainsString('파일 없음', $out, 'active + 설치본 부재는 "(파일 없음)" 으로 표기되어야 함');
}
/**
* @effects cli_list_surfaces_uninstalled_and_drift
*/
public function test_lists_uninstalled_bundle_pack(): void
{
// RefreshDatabase 상태 → 설치된 팩 없음. 번들 소스(g7-core-ja)는 uninstalled 가상행으로 노출.
$exit = Artisan::call('language-pack:list');
$out = Artisan::output();
$this->assertSame(0, $exit);
$this->assertStringContainsString('g7-core-ja', $out, '미설치 번들 팩이 목록에 나타나야 함');
$this->assertStringContainsString('uninstalled', $out, '미설치 번들은 uninstalled 상태로 표기되어야 함');
}
public function test_scope_filter_limits_output(): void
{
$exit = Artisan::call('language-pack:list', ['--scope' => 'core']);
$out = Artisan::output();
$this->assertSame(0, $exit);
// core 스코프만 → 모듈/플러그인/템플릿 팩은 제외
$this->assertStringContainsString('g7-core-ja', $out);
$this->assertStringNotContainsString('sirsoft-module-sirsoft-board', $out, 'core 스코프에 모듈 팩이 섞이면 안 됨');
}
}
@@ -0,0 +1,432 @@
<?php
namespace Tests\Feature\LanguagePack;
use App\Models\LanguagePack;
use App\Services\LanguagePackService;
use Illuminate\Support\Collection;
use Mockery;
use Mockery\MockInterface;
use Tests\TestCase;
/**
* `language-pack:provision` 커맨드 Feature 테스트.
*
* 파일시스템 설치를 피하기 위해 LanguagePackService 를 목킹하여 커맨드의
* 로케일/스코프 필터, 차단 사유 skip, 드리프트 복구, 멱등성(후보 없음 → 설치 0) 을 검증한다.
*
* 시나리오 매트릭스: tests/scenarios/language-pack-provision-and-drift.yaml
*/
class ProvisionLanguagePackCommandTest extends TestCase
{
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
/**
* 미설치 번들 가상 팩을 만든다.
*
* @param string $identifier 번들 식별자
* @param string $locale 로케일
* @param string $scope 스코프 (core/module/plugin/template)
* @param string|null $blockedReason 설치 차단 사유
* @return LanguagePack 미설치 가상 팩
*/
private function bundledPack(string $identifier, string $locale, string $scope = 'core', ?string $blockedReason = null): LanguagePack
{
$pack = new LanguagePack;
$pack->identifier = $identifier;
$pack->locale = $locale;
$pack->scope = $scope;
$pack->version = '1.0.0';
$pack->status = 'uninstalled';
$pack->setAttribute('bundled_identifier', $identifier);
$pack->setAttribute('install_blocked_reason', $blockedReason);
$pack->exists = false;
return $pack;
}
/**
* 드리프트(설치 행 존재 + 설치본 파일 부재) 팩을 만든다.
*
* @param string $identifier 식별자
* @param string $locale 로케일
* @param string $scope 스코프
* @return LanguagePack 드리프트 설치 행
*/
private function driftedPack(string $identifier, string $locale, string $scope = 'core'): LanguagePack
{
$pack = new LanguagePack;
$pack->identifier = $identifier;
$pack->locale = $locale;
$pack->scope = $scope;
$pack->version = '1.0.0';
$pack->status = 'active';
$pack->setAttribute('files_missing', true);
$pack->setAttribute('bundled_source_available', true);
$pack->exists = true;
return $pack;
}
/**
* installFromBundled 가 반환할 설치 완료 팩 스텁.
*
* @param string $identifier 식별자
* @param string $locale 로케일
* @return LanguagePack 설치 완료 팩
*/
private function installedResult(string $identifier, string $locale): LanguagePack
{
$pack = new LanguagePack;
$pack->identifier = $identifier;
$pack->locale = $locale;
$pack->version = '1.0.0';
$pack->status = 'active';
return $pack;
}
/**
* Service 목을 만들어 컨테이너에 바인딩한다.
*
* @param array<int, LanguagePack> $uninstalled 미설치 번들 후보
* @param array<int, LanguagePack> $drifted 드리프트 복구 후보
* @return MockInterface Service 목
*/
private function mockService(array $uninstalled = [], array $drifted = [])
{
$service = Mockery::mock(LanguagePackService::class);
$service->shouldReceive('getUninstalledBundledPacks')->andReturn(new Collection($uninstalled));
$service->shouldReceive('getDriftedInstalledPacks')->andReturn(new Collection($drifted));
$this->app->instance(LanguagePackService::class, $service);
return $service;
}
// ─── 미설치 → 신규 프로비저닝 ──────────────────────────────────────
/**
* @scenario target_locale_source=supported_locales_default, locale_membership=non_base_declared, pack_state=uninstalled, scope=core
*
* @effects provisions_only_supported_non_base_locales
*/
public function test_provisions_only_supported_non_base_locales(): void
{
config(['app.supported_locales' => ['ko', 'en', 'ja']]);
$service = $this->mockService([
$this->bundledPack('g7-core-ja', 'ja'),
$this->bundledPack('g7-core-fr', 'fr'), // supported_locales 에 없음 → 설치 대상 아님
]);
$service->shouldReceive('installFromBundled')
->with('g7-core-ja', true)
->once()
->andReturn($this->installedResult('g7-core-ja', 'ja'));
$service->shouldNotReceive('installFromBundled')->with('g7-core-fr', Mockery::any());
$this->artisan('language-pack:provision')->assertExitCode(0);
}
/**
* @scenario target_locale_source=supported_locales_default, locale_membership=non_base_declared, pack_state=uninstalled, scope=extension
*
* @effects provisions_only_supported_non_base_locales
*/
public function test_provisions_extension_scoped_bundled_pack(): void
{
config(['app.supported_locales' => ['ko', 'en', 'ja']]);
$service = $this->mockService([
$this->bundledPack('g7-module-sirsoft-board-ja', 'ja', 'module'),
]);
$service->shouldReceive('installFromBundled')
->with('g7-module-sirsoft-board-ja', true)
->once()
->andReturn($this->installedResult('g7-module-sirsoft-board-ja', 'ja'));
$this->artisan('language-pack:provision')->assertExitCode(0);
}
/**
* @scenario target_locale_source=explicit_locale_option, locale_membership=non_base_declared, pack_state=uninstalled, scope=core
*
* @effects explicit_locale_option_overrides_supported_locales
*/
public function test_explicit_locale_option_overrides_supported_locales(): void
{
config(['app.supported_locales' => ['ko']]); // supported 에 ja 없음
$service = $this->mockService([
$this->bundledPack('g7-core-ja', 'ja'),
]);
// --locale=ja 명시 시 supported 에 없어도 설치
$service->shouldReceive('installFromBundled')
->with('g7-core-ja', true)
->once()
->andReturn($this->installedResult('g7-core-ja', 'ja'));
$this->artisan('language-pack:provision', ['--locale' => ['ja']])->assertExitCode(0);
}
/**
* @scenario target_locale_source=explicit_locale_option, locale_membership=non_base_declared, pack_state=uninstalled, scope=extension
*
* @effects explicit_locale_option_overrides_supported_locales, scope_filter_limits_provision_targets
*/
public function test_scope_option_limits_explicit_locale_targets(): void
{
config(['app.supported_locales' => ['ko']]);
$service = $this->mockService([
$this->bundledPack('g7-core-ja', 'ja'),
$this->bundledPack('g7-module-sirsoft-board-ja', 'ja', 'module'),
]);
// --scope=module 이면 코어 팩은 대상에서 빠진다
$service->shouldReceive('installFromBundled')
->with('g7-module-sirsoft-board-ja', true)
->once()
->andReturn($this->installedResult('g7-module-sirsoft-board-ja', 'ja'));
$service->shouldNotReceive('installFromBundled')->with('g7-core-ja', Mockery::any());
$this->artisan('language-pack:provision', ['--locale' => ['ja'], '--scope' => ['module']])
->assertExitCode(0);
}
// ─── 이미 설치됨 → 멱등 ────────────────────────────────────────────
/**
* @scenario target_locale_source=supported_locales_default, locale_membership=non_base_declared, pack_state=installed_active, scope=core
*
* @effects is_idempotent_when_no_uninstalled_candidates
*/
public function test_is_idempotent_when_no_uninstalled_candidates(): void
{
config(['app.supported_locales' => ['ko', 'en', 'ja']]);
// 이미 전부 설치됨 → 미설치 후보 없음, 드리프트도 없음
$service = $this->mockService();
$service->shouldNotReceive('installFromBundled');
$this->artisan('language-pack:provision')->assertExitCode(0);
}
/**
* @scenario target_locale_source=supported_locales_default, locale_membership=non_base_declared, pack_state=installed_active, scope=extension
*
* @effects is_idempotent_when_no_uninstalled_candidates
*/
public function test_is_idempotent_for_installed_extension_packs(): void
{
config(['app.supported_locales' => ['ko', 'en', 'ja']]);
$service = $this->mockService();
$service->shouldNotReceive('installFromBundled');
$this->artisan('language-pack:provision', ['--scope' => ['module']])->assertExitCode(0);
}
/**
* @scenario target_locale_source=explicit_locale_option, locale_membership=non_base_declared, pack_state=installed_active, scope=core
*
* @effects is_idempotent_when_no_uninstalled_candidates
*/
public function test_explicit_locale_is_idempotent_for_installed_core_pack(): void
{
config(['app.supported_locales' => ['ko', 'en']]);
$service = $this->mockService();
$service->shouldNotReceive('installFromBundled');
$this->artisan('language-pack:provision', ['--locale' => ['ja']])->assertExitCode(0);
}
/**
* @scenario target_locale_source=explicit_locale_option, locale_membership=non_base_declared, pack_state=installed_active, scope=extension
*
* @effects is_idempotent_when_no_uninstalled_candidates
*/
public function test_explicit_locale_is_idempotent_for_installed_extension_pack(): void
{
config(['app.supported_locales' => ['ko', 'en']]);
$service = $this->mockService();
$service->shouldNotReceive('installFromBundled');
$this->artisan('language-pack:provision', ['--locale' => ['ja'], '--scope' => ['module']])
->assertExitCode(0);
}
// ─── 설치 차단 → best-effort skip ──────────────────────────────────
/**
* @scenario target_locale_source=supported_locales_default, locale_membership=non_base_declared, pack_state=install_blocked, scope=extension
*
* @effects skips_install_blocked_packs
*/
public function test_skips_blocked_packs(): void
{
config(['app.supported_locales' => ['ko', 'en', 'ja']]);
$service = $this->mockService([
$this->bundledPack('g7-module-board-ja', 'ja', 'module', 'target_not_installed'),
]);
// 차단 사유가 있으면 설치 시도 자체를 하지 않는다
$service->shouldNotReceive('installFromBundled');
$this->artisan('language-pack:provision')->assertExitCode(0);
}
/**
* @scenario target_locale_source=explicit_locale_option, locale_membership=non_base_declared, pack_state=install_blocked, scope=extension
*
* @effects skips_install_blocked_packs
*/
public function test_skips_blocked_packs_with_explicit_locale(): void
{
config(['app.supported_locales' => ['ko']]);
$service = $this->mockService([
$this->bundledPack('g7-plugin-gdpr-ja', 'ja', 'plugin', 'target_inactive'),
]);
$service->shouldNotReceive('installFromBundled');
$this->artisan('language-pack:provision', ['--locale' => ['ja']])->assertExitCode(0);
}
// ─── 드리프트 → 복구 ───────────────────────────────────────────────
/**
* @scenario target_locale_source=supported_locales_default, locale_membership=non_base_declared, pack_state=drifted_missing_files, scope=core
*
* @effects drifted_pack_repaired_by_provision
*/
public function test_repairs_drifted_core_pack(): void
{
config(['app.supported_locales' => ['ko', 'en', 'ja']]);
// 미설치 후보는 없지만 드리프트 행이 있다 — 슬롯이 점유돼 있어 미설치 목록엔 안 잡힌다
$service = $this->mockService([], [
$this->driftedPack('g7-core-ja', 'ja'),
]);
$service->shouldReceive('installFromBundled')
->with('g7-core-ja', true)
->once()
->andReturn($this->installedResult('g7-core-ja', 'ja'));
$this->artisan('language-pack:provision')->assertExitCode(0);
}
/**
* @scenario target_locale_source=supported_locales_default, locale_membership=non_base_declared, pack_state=drifted_missing_files, scope=extension
*
* @effects drifted_pack_repaired_by_provision
*/
public function test_repairs_drifted_extension_pack(): void
{
config(['app.supported_locales' => ['ko', 'en', 'ja']]);
$service = $this->mockService([], [
$this->driftedPack('g7-module-sirsoft-board-ja', 'ja', 'module'),
]);
$service->shouldReceive('installFromBundled')
->with('g7-module-sirsoft-board-ja', true)
->once()
->andReturn($this->installedResult('g7-module-sirsoft-board-ja', 'ja'));
$this->artisan('language-pack:provision')->assertExitCode(0);
}
/**
* @scenario target_locale_source=explicit_locale_option, locale_membership=non_base_declared, pack_state=drifted_missing_files, scope=core
*
* @effects drifted_pack_repaired_by_provision, explicit_locale_option_overrides_supported_locales
*/
public function test_repairs_drifted_core_pack_with_explicit_locale(): void
{
config(['app.supported_locales' => ['ko']]); // 선언에 없어도 명시하면 복구
$service = $this->mockService([], [
$this->driftedPack('g7-core-ja', 'ja'),
]);
$service->shouldReceive('installFromBundled')
->with('g7-core-ja', true)
->once()
->andReturn($this->installedResult('g7-core-ja', 'ja'));
$this->artisan('language-pack:provision', ['--locale' => ['ja']])->assertExitCode(0);
}
/**
* @scenario target_locale_source=explicit_locale_option, locale_membership=non_base_declared, pack_state=drifted_missing_files, scope=extension
*
* @effects drifted_pack_repaired_by_provision, scope_filter_limits_provision_targets
*/
public function test_repairs_drifted_extension_pack_within_scope_filter(): void
{
config(['app.supported_locales' => ['ko']]);
$service = $this->mockService([], [
$this->driftedPack('g7-core-ja', 'ja'),
$this->driftedPack('g7-module-sirsoft-board-ja', 'ja', 'module'),
]);
$service->shouldReceive('installFromBundled')
->with('g7-module-sirsoft-board-ja', true)
->once()
->andReturn($this->installedResult('g7-module-sirsoft-board-ja', 'ja'));
$service->shouldNotReceive('installFromBundled')->with('g7-core-ja', Mockery::any());
$this->artisan('language-pack:provision', ['--locale' => ['ja'], '--scope' => ['module']])
->assertExitCode(0);
}
// ─── base locale 만 선언 → 대상 없음 ───────────────────────────────
/**
* @scenario target_locale_source=supported_locales_default, locale_membership=base_only, pack_state=uninstalled, scope=core
*
* @effects does_nothing_when_no_non_base_locale_declared
*/
public function test_does_nothing_when_no_non_base_locale_declared(): void
{
config(['app.supported_locales' => ['ko', 'en']]);
$service = Mockery::mock(LanguagePackService::class);
// 대상 로케일이 없으므로 후보 조회조차 하지 않아야 한다
$service->shouldNotReceive('getUninstalledBundledPacks');
$service->shouldNotReceive('getDriftedInstalledPacks');
$service->shouldNotReceive('installFromBundled');
$this->app->instance(LanguagePackService::class, $service);
$this->artisan('language-pack:provision')->assertExitCode(0);
}
/**
* @scenario target_locale_source=supported_locales_default, locale_membership=base_only, pack_state=uninstalled, scope=extension
*
* @effects does_nothing_when_no_non_base_locale_declared
*/
public function test_does_nothing_for_extension_scope_when_base_only(): void
{
config(['app.supported_locales' => ['ko', 'en']]);
$service = Mockery::mock(LanguagePackService::class);
$service->shouldNotReceive('getUninstalledBundledPacks');
$service->shouldNotReceive('getDriftedInstalledPacks');
$service->shouldNotReceive('installFromBundled');
$this->app->instance(LanguagePackService::class, $service);
$this->artisan('language-pack:provision', ['--scope' => ['module']])->assertExitCode(0);
}
}
@@ -0,0 +1,124 @@
/**
* E2E: 관리자 언어팩 목록의 드리프트(설치본 파일 부재) 발견 + 원클릭 복구 — 이슈 #496 Part B3
*
* 배경: DB 에 active 로 기록됐지만 설치본 디렉토리(`lang-packs/{id}/`)가 사라진 팩은 런타임에
* 오류 없이 base locale(ko)로 조용히 폴백한다. 목록에는 정상(active)으로 보였기 때문에 운영자가
* "번역이 적용되지 않는다"는 증상만 보고 원인을 찾지 못했다(#483 실측). 화면에 `파일 없음` 배지와
* 재설치 버튼을 노출해 발견·복구가 한 화면에서 끝나게 한다.
*
* 계층 분담:
* - files_missing / bundled_source_available 파생 판정 → PHPUnit (ListDriftDetectionTest)
* - 배지/버튼 조건식 평가 → Vitest (admin-language-pack-drift.test.tsx, createLayoutTest)
* - 본 spec → 실제 브라우저에서 목록 화면이 뜨고 조건이 라이브 데이터에 걸리는지 최종 확증
*
* @scenario target_locale_source=supported_locales_default, locale_membership=non_base_declared,
* pack_state=drifted_missing_files, scope=core
* @effects admin_list_shows_drift_badge_and_reinstall,
* active_row_with_missing_install_dir_flagged_files_missing
*/
import { test, expect, issueToken, authenticatePage } from '../../fixtures/auth';
// 표시 문구는 로케일에 따라 바뀐다(테스트 브라우저는 en 으로 렌더될 수 있다).
// 로케일 무관하게 잠그기 위해 레이아웃의 data-testid 로 집는다.
/** 드리프트 배지 test id */
const DRIFT_BADGE = 'lp-drift-badge';
/** 재설치 버튼 test id */
const REINSTALL_BUTTON = 'lp-reinstall-button';
test.describe('관리자 언어팩 목록 — 드리프트 발견', () => {
test('배지·재설치 버튼 노출이 API 가 내려준 드리프트 상태와 일치한다', async ({ page }) => {
const token = issueToken('core.language_packs.read', 'core.language_packs.install');
await authenticatePage(page, token);
// 뷰포트가 좁으면 행 액션 버튼이 카드 우측에서 화면 밖으로 밀린다.
await page.setViewportSize({ width: 1600, height: 1000 });
const listResponse = page.waitForResponse(
(r) => r.url().includes('/api/admin/language-packs') && r.status() === 200,
{ timeout: 30_000 },
);
await page.goto('/admin/settings?tab=language_packs');
const rows = (await (await listResponse).json())?.data?.data ?? [];
// 목록이 비어 있으면 어떤 단언도 의미가 없다 — 화면/권한 회귀를 여기서 잡는다.
expect(rows.length).toBeGreaterThan(0);
// 화면에 떠야 할 배지/버튼 수를 응답에서 직접 계산한다.
// "0건이어야 한다" 만 단언하면 아직 안 그려진 상태에서도 통과해(vacuous) 실제 결손을 놓친다.
const expectedBadges = rows.filter((r: { files_missing?: boolean }) => r.files_missing === true).length;
const expectedButtons = rows.filter(
(r: { files_missing?: boolean; bundled_source_available?: boolean; abilities?: { can_install?: boolean } }) =>
r.files_missing === true && r.bundled_source_available === true && r.abilities?.can_install === true,
).length;
// 카드가 실제로 그려진 뒤에 세어야 한다. 앵커는 UI 문구가 아니라 응답 데이터(원어 언어명)라
// 표시 로케일이 ko 든 en 이든 동일하게 걸린다. 배지는 카드와 같은 렌더 패스에서 결정되므로,
// 카드가 보이는 시점에는 배지 노출 여부도 이미 확정돼 있다.
const nativeName = rows[0]?.locale_native_name ?? '';
if (nativeName) {
await expect(page.getByText(nativeName, { exact: false }).first()).toBeVisible({ timeout: 20_000 });
}
await expect
.poll(() => page.getByTestId(DRIFT_BADGE).count(), { timeout: 20_000 })
.toBe(expectedBadges);
await expect
.poll(() => page.getByTestId(REINSTALL_BUTTON).count(), { timeout: 20_000 })
.toBe(expectedButtons);
});
/**
* 드리프트 상태 주입에는 서버 파일시스템 조작(설치본 디렉토리 삭제)이 필요하다.
* 브라우저에서는 만들 수 없는 상태이므로, 아래는 드리프트를 주입한 환경에서만 활성화한다.
*
* 활성화 절차:
* 1. `php artisan language-pack:provision --locale=ja` 로 g7-core-ja 설치
* 2. `lang-packs/g7-core-ja/` 디렉토리 삭제 (DB active 행은 남김)
* 3. `test.describe.skip` → `test.describe` 로 전환
*
* 복구 확인 후에는 `php artisan language-pack:provision --locale=ja` 로 원상 복구된다.
*
* @scenario target_locale_source=explicit_locale_option, locale_membership=non_base_declared,
* pack_state=drifted_missing_files, scope=core
* @effects admin_list_shows_drift_badge_and_reinstall, drifted_pack_repaired_by_provision
*/
test.describe.skip('드리프트 주입 환경 (수동 활성화)', () => {
test('드리프트 행에 배지와 재설치 버튼이 뜨고, 재설치로 복구된다', async ({ page }) => {
const token = issueToken('core.language_packs.read', 'core.language_packs.install');
await authenticatePage(page, token);
// 행 액션 버튼은 카드 우측에 놓여 좁은 뷰포트에서 화면 밖으로 밀린다 — 넓게 잡는다.
await page.setViewportSize({ width: 1600, height: 1000 });
const listResponse = page.waitForResponse(
(r) => r.url().includes('/api/admin/language-packs') && r.status() === 200,
{ timeout: 30_000 },
);
await page.goto('/admin/settings?tab=language_packs');
await listResponse;
await expect(page.getByTestId(DRIFT_BADGE).first()).toBeVisible({
timeout: 20_000,
});
const reinstall = page.getByTestId(REINSTALL_BUTTON).first();
await expect(reinstall).toBeVisible();
await reinstall.click();
// 재설치는 번들 설치 모달(language_pack_install_bundled_modal)을 재사용한다
const confirm = page.locator('button:visible', { hasText: /^설치$/ }).last();
await expect(confirm).toBeEnabled({ timeout: 10_000 });
const install = page.waitForResponse(
(r) => r.url().includes('install-from-bundled') && r.request().method() === 'POST',
{ timeout: 30_000 },
);
await confirm.click();
expect((await install).status()).toBe(201);
// 복구 후에는 배지와 재설치 버튼이 사라진다
await expect(page.getByTestId(DRIFT_BADGE)).toHaveCount(0, { timeout: 20_000 });
});
});
});
@@ -0,0 +1,70 @@
feature: 번들 언어팩 멱등 프로비저닝 + 드리프트 발견 (이슈 #496)
description: |
비-base 로케일(ja 등) 번들 언어팩이 신규 설치/복구 시 자동으로 채워지지 않아 런타임에
오류 없이 ko 로 조용히 폴백하던 문제를, 멱등 프로비저닝 커맨드(SSoT) + 설치 후 발견성
(미설치/드리프트 표면화)으로 해소하는 시나리오.
배경:
- ko/en 은 가상 보호 행으로 항상 서빙되나, ja 등은 설치본 디렉토리(gitignore)로 등록돼야 서빙.
- language-pack:provision 은 supported_locales ∖ {ko,en} 의 미설치 번들 팩을 멱등 설치하고,
설치 행은 있으나 파일이 사라진 드리프트 팩도 함께 복구한다(수동 복구 경로 겸용).
- list()/Resource 는 파생 플래그 files_missing(active 인데 설치본 부재)과
bundled_source_available(번들 소스로 복구 가능)을 부여해 드리프트 표면화 + 복구 가능 여부를 구분한다.
- A2(인스톨러 기본 선택)는 admin_language 가 ko/en 한정이라 no-op → PO 결정으로 제외.
axes:
target_locale_source: [supported_locales_default, explicit_locale_option]
locale_membership: [non_base_declared, base_only]
pack_state: [uninstalled, installed_active, drifted_missing_files, install_blocked]
scope: [core, extension]
exclusions:
- { target_locale_source: explicit_locale_option, locale_membership: base_only, reason: "--locale 은 base 를 필터로 제외 — 명시 지정으로 base 가 대상이 되는 경로 자체가 없음" }
- { locale_membership: base_only, pack_state: installed_active, reason: "base 만 선언하면 비-base 팩이 후보에 오르지 않아 팩 상태가 결과를 바꾸지 않음 — uninstalled 대표 케이스로 수렴" }
- { locale_membership: base_only, pack_state: drifted_missing_files, reason: "동일 — base 선언 하에서는 드리프트 복구 대상도 산출되지 않음" }
- { locale_membership: base_only, pack_state: install_blocked, reason: "동일 — 차단 판정 이전에 대상 로케일이 비어 후보 조회조차 하지 않음" }
- { pack_state: install_blocked, scope: core, reason: "코어 팩은 대상 확장이 없어 install_blocked 사유(target_not_installed/target_inactive)가 발생하지 않음" }
effects:
- provisions_only_supported_non_base_locales
- is_idempotent_when_no_uninstalled_candidates
- skips_install_blocked_packs
- does_nothing_when_no_non_base_locale_declared
- explicit_locale_option_overrides_supported_locales
- scope_filter_limits_provision_targets
- drifted_pack_repaired_by_provision
- active_row_with_missing_install_dir_flagged_files_missing
- virtual_builtin_rows_not_flagged
- bundled_source_availability_flagged_independently_of_source_type
- cli_list_surfaces_uninstalled_and_drift
- admin_list_shows_drift_badge_and_reinstall
- third_party_pack_without_bundle_source_not_offered_for_reinstall
- supported_locale_without_bundle_source_is_statically_flagged
- declared_locale_without_installed_pack_is_statically_flagged
test_files:
- tests/Feature/LanguagePack/ProvisionLanguagePackCommandTest.php
- tests/Feature/LanguagePack/ListDriftDetectionTest.php
- tests/Feature/LanguagePack/ListLanguagePackCommandTest.php
- templates/_bundled/sirsoft-admin_basic/__tests__/layouts/admin-language-pack-drift.test.tsx
- .claude/scripts/audit/__tests__/rules.test.cjs
e2e_files:
- tests/Playwright/specs/admin/language-pack-drift-discovery.spec.ts
rules_layer_coverage:
- rule: service-direct-data-access
coverage: ProvisionLanguagePackCommand 은 LanguagePackService 만 주입 — Model/DB facade 직접 접근 없음
- rule: lang-pack-supported-locale-has-bundle
coverage: config/app.php supported_locales 비-base 로케일 ↔ g7-core-{locale} 번들 소스 정합 정적 검사
- rule: lang-pack-installed-version-drift
coverage: 선언 로케일의 설치본 부재(미설치 사각)를 프로비저닝된 환경에 한해 정적 검사
- rule: frontend-change-requires-e2e
coverage: 관리자 언어팩 목록 partial 변경에 동반하는 language-pack-drift-discovery.spec.ts (템플릿 도메인)
notes: |
드리프트 주입에는 서버 파일시스템 조작(설치본 디렉토리 삭제)이 필요해 브라우저에서 만들 수 없다.
따라서 E2E spec 은 (1) 목록 렌더 + 정상 환경에서 배지 0건(오탐 가드)을 라이브로 검증하고,
(2) 드리프트 주입 상태의 배지·재설치 흐름은 활성화 절차를 명시한 skip 블록으로 둔다.
파생 판정 자체는 PHPUnit, 조건식 평가는 Vitest(createLayoutTest)가 잠근다.