fix(core,engine): 확장 번들 503 판정을 선언 축에서 소실 축으로 교체
빈 번들 503 을 "에셋을 선언한 활성 확장이 있는데 결과가 비었다" 로 판정해, 스타일 규칙이 아직 없는 0바이트 CSS 만 선언된 기본 구성이 통째로 503 이 됐다. file_get_contents 는 0바이트에서 false 가 아니라 '' 를 돌려주므로 읽기 실패 분기도 타지 않는다. 선언 축 게터는 전부 file_exists 게이트라 부재를 셀 수 없어, 존재 게이트가 없는 getDeclaredAssetAbsolutePaths 를 통로로 두고 503 의 근거를 소실 축(findMissingDeclaredAssets)으로 옮긴다. 존재하되 비었으면 빈 200 이다. 곁들여: 실패 배너 항목명을 내부 구분 키에서 사용자 어휘로(engine-v1.64.7), 봇 화면이 없는 템플릿 CSS 를 링크하지 않도록 실재 게이트, 매니페스트 자산 선언 드리프트 4건 정정.
This commit is contained in:
1 parent
482faf00be
commit
0833bd1f6a
42 files changed
+1207
-90
No files matched your search
@@ -4,6 +4,7 @@ namespace Tests\Feature\Api\Public;
|
||||
|
||||
use App\Services\ExtensionBundleService;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -40,24 +41,37 @@ class ExtensionBundleServingTest extends TestCase
|
||||
/**
|
||||
* 번들 서비스를 모킹합니다.
|
||||
*
|
||||
* `$memoryContent` / `$declaredCount` 는 빈 경로(`$returnPath === ''`)일 때의 분기를
|
||||
* 정한다 — 디스크 캐시 실패(메모리 폴백)인지, 선언 0개(정상 빈 번들)인지,
|
||||
* 선언은 있는데 결과가 0인지(장애)를 컨트롤러가 이 둘로 가른다.
|
||||
* `$memoryContent` / `$declaredCount` / `$missing` 은 빈 경로(`$returnPath === ''`)일 때의
|
||||
* 분기를 정한다 — 디스크 캐시 실패(메모리 폴백)인지, 병합 결과가 정당하게 비었는지
|
||||
* (선언 0 이거나 선언한 산출물이 전부 존재하되 비어 있음), 선언한 산출물이 소실됐는지
|
||||
* (장애)를 컨트롤러가 이 셋으로 가른다.
|
||||
*
|
||||
* 503 의 근거는 `$declaredCount` 가 아니라 `$missing` 이다. 선언만으로 판정하면
|
||||
* "스타일이 비어 있는 확장" 의 정당한 상태가 배포 장애와 구분되지 않는다.
|
||||
*
|
||||
* @param string $returnPath getBundleFilePath 반환값
|
||||
* @param string $memoryContent buildBundleContent 반환값
|
||||
* @param int $declaredCount countAssetDeclaringExtensions 반환값
|
||||
* @param list<string> $missing findMissingDeclaredAssets 반환값 (소실 산출물 절대 경로)
|
||||
*/
|
||||
private function bindBundleService(string $returnPath, string $memoryContent = '', int $declaredCount = 0): void
|
||||
{
|
||||
private function bindBundleService(
|
||||
string $returnPath,
|
||||
string $memoryContent = '',
|
||||
int $declaredCount = 0,
|
||||
array $missing = []
|
||||
): void {
|
||||
$mock = Mockery::mock(ExtensionBundleService::class);
|
||||
$mock->shouldReceive('getCurrentVersion')->andReturn(777);
|
||||
$mock->shouldReceive('getBundleFilePath')->andReturn($returnPath);
|
||||
$mock->shouldReceive('buildBundleContent')->andReturn($memoryContent);
|
||||
$mock->shouldReceive('countAssetDeclaringExtensions')->andReturn($declaredCount);
|
||||
$mock->shouldReceive('findMissingDeclaredAssets')->andReturn($missing);
|
||||
$this->app->instance(ExtensionBundleService::class, $mock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects bundle_endpoint_serves_with_etag_and_304
|
||||
*/
|
||||
public function test_module_bundle_js_serves_merged_file_with_etag(): void
|
||||
{
|
||||
$path = $this->fixtureDir.'/module.777.js';
|
||||
@@ -73,6 +87,9 @@ class ExtensionBundleServingTest extends TestCase
|
||||
$this->assertStringContainsString("\n;\n", $response->streamedContent() ?? $response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects bundle_endpoint_serves_with_etag_and_304
|
||||
*/
|
||||
public function test_bundle_returns_304_on_matching_etag(): void
|
||||
{
|
||||
$path = $this->fixtureDir.'/plugin.777.js';
|
||||
@@ -88,6 +105,9 @@ class ExtensionBundleServingTest extends TestCase
|
||||
$second->assertStatus(304);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects empty_bundle_returns_empty_path_and_empty_ok_response
|
||||
*/
|
||||
public function test_empty_bundle_returns_empty_ok_response(): void
|
||||
{
|
||||
// 에셋을 선언한 활성 확장이 0개 → 빈 번들이 정상이다 → 빈 200
|
||||
@@ -125,23 +145,90 @@ class ExtensionBundleServingTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* 선언은 있는데 병합 결과가 비면 503 이다 (E2).
|
||||
* 선언한 산출물이 소실됐는데 병합 결과가 비면 503 이다 (E2).
|
||||
*
|
||||
* 배포 중 `dist` 가 잠깐 비면 **모든 확장이 빠진 빈 번들**이 200 으로 나가고, 프론트는
|
||||
* 404 도 오류도 받지 못한 채 한참 뒤 "Unknown action handler" 로 죽는다 — 그 시점에는
|
||||
* 원인이 번들이라는 사실이 화면에도 로그에도 남아 있지 않다.
|
||||
*
|
||||
* @effects bundle_empty_with_declared_assets_returns_503
|
||||
* 판정 근거는 선언 축이 아니라 **소실 축**이다. 선언 축만 보면 스타일이 비어 있는
|
||||
* 확장(정당한 0바이트 산출물)까지 장애로 잡혀 기본 구성이 503 이 된다.
|
||||
*
|
||||
* // @scenario ext_type=module, asset_kind=js, active_combo=multiple, file_state=one_missing
|
||||
*
|
||||
* @effects bundle_empty_with_declared_assets_returns_503, empty_result_with_missing_declared_artifact_returns_503
|
||||
*/
|
||||
public function test_empty_bundle_with_declared_assets_returns_503(): void
|
||||
{
|
||||
$this->bindBundleService('', memoryContent: '', declaredCount: 3);
|
||||
$this->bindBundleService('', memoryContent: '', declaredCount: 3, missing: ['/x/dist/js/a.js']);
|
||||
|
||||
$response = $this->get('/api/modules/bundle.js?v=777');
|
||||
|
||||
$response->assertStatus(503);
|
||||
}
|
||||
|
||||
/**
|
||||
* 선언한 산출물이 **존재하되 비어 있으면** 정상 빈 200 이다 (이 이슈의 재현).
|
||||
*
|
||||
* 스타일 소스가 자리표시 주석뿐이라 0바이트 CSS 를 내보내는 확장은 정당한 상태다.
|
||||
* 종전 판정은 "선언 > 0 && 병합 결과 0" 을 곧 배포 장애로 등치해, 그런 확장만 설치된
|
||||
* 기본 구성의 사용자 화면마다 실패 안내가 떴다.
|
||||
*
|
||||
* // @scenario ext_type=module, asset_kind=css, active_combo=one, file_state=present_empty
|
||||
*
|
||||
* @effects empty_result_with_present_empty_artifacts_returns_200
|
||||
*/
|
||||
public function test_empty_result_with_present_empty_artifacts_returns_200(): void
|
||||
{
|
||||
$this->bindBundleService('', memoryContent: '', declaredCount: 1, missing: []);
|
||||
|
||||
$response = $this->get('/api/modules/bundle.css?v=777');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertStringStartsWith('text/css', $response->headers->get('Content-Type'));
|
||||
$this->assertSame('', $response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 플러그인 경로도 같은 판정을 쓴다 — 존재하되 비어 있으면 빈 200.
|
||||
*
|
||||
* // @scenario ext_type=plugin, asset_kind=css, active_combo=one, file_state=present_empty
|
||||
*
|
||||
* @effects bundle_decision_is_shared_across_extension_types, empty_result_with_present_empty_artifacts_returns_200
|
||||
*/
|
||||
public function test_plugin_bundle_returns_200_when_declared_artifacts_present_but_empty(): void
|
||||
{
|
||||
$this->bindBundleService('', memoryContent: '', declaredCount: 1, missing: []);
|
||||
|
||||
$response = $this->get('/api/plugins/bundle.css?v=777');
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertSame('', $response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 503 로그가 **어느 산출물이 없는지**를 싣는다.
|
||||
*
|
||||
* 경로가 없으면 운영자는 조치 대상을 짚을 수 없다 — 선언 수만으로는 어느 확장의
|
||||
* 어느 파일인지 알 수 없다.
|
||||
*
|
||||
* // @scenario ext_type=module, asset_kind=css, active_combo=one, file_state=one_missing
|
||||
*
|
||||
* @effects missing_artifact_paths_are_logged
|
||||
*/
|
||||
public function test_503_log_lists_missing_artifact_paths(): void
|
||||
{
|
||||
Log::spy();
|
||||
|
||||
$this->bindBundleService('', memoryContent: '', declaredCount: 1, missing: ['/x/dist/css/a.css']);
|
||||
|
||||
$this->get('/api/modules/bundle.css?v=777')->assertStatus(503);
|
||||
|
||||
Log::shouldHaveReceived('error')->withArgs(
|
||||
fn ($message, $context) => ($context['missing'] ?? null) === ['/x/dist/css/a.css']
|
||||
)->once();
|
||||
}
|
||||
|
||||
/**
|
||||
* 플러그인 경로도 같은 판정을 쓴다 — 두 컨트롤러가 갈라지지 않는다 (장애 쪽).
|
||||
*
|
||||
@@ -149,7 +236,7 @@ class ExtensionBundleServingTest extends TestCase
|
||||
*/
|
||||
public function test_plugin_bundle_returns_503_when_declared_but_empty(): void
|
||||
{
|
||||
$this->bindBundleService('', memoryContent: '', declaredCount: 1);
|
||||
$this->bindBundleService('', memoryContent: '', declaredCount: 1, missing: ['/x/dist/css/a.css']);
|
||||
|
||||
$this->get('/api/plugins/bundle.css?v=777')->assertStatus(503);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* E2E: 확장 프론트엔드 병합 번들 로딩 회귀 검증
|
||||
*
|
||||
* @scenario extension-bundle-loading
|
||||
* @effects bundle_js_requested_once_per_type, individual_iife_requests_absent,
|
||||
* gdpr_interceptor_still_active, extension_handlers_registered
|
||||
* @effects individual_iife_requests_absent_in_browser, bundle_url_same_origin_only,
|
||||
* gdpr_interceptor_still_active_after_merge, extension_handlers_registered_no_console_error
|
||||
*
|
||||
* 배경: 활성 모듈/플러그인 IIFE 를 서버측에서 종류별 1개 번들로 병합 서빙한다.
|
||||
* 실제 페이지 로드 시 (1) 개별 `*.iife.js` 요청이 사라지고 `bundle.js` 로 대체되는지,
|
||||
@@ -22,8 +22,8 @@ test.describe('확장 병합 번들 로딩', () => {
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle', { timeout: 30_000 });
|
||||
|
||||
const moduleBundle = requestedUrls.filter((u) => /\/api\/modules\/bundle\.js/.test(u));
|
||||
const pluginBundle = requestedUrls.filter((u) => /\/api\/plugins\/bundle\.js/.test(u));
|
||||
const moduleBundle = requestedUrls.filter((u) => /\/api\/modules\/bundle[./]js/.test(u));
|
||||
const pluginBundle = requestedUrls.filter((u) => /\/api\/plugins\/bundle[./]js/.test(u));
|
||||
|
||||
// 활성 확장이 있으면 번들이 요청되고, 종류별로 1건씩만 나가야 한다
|
||||
const individualIife = requestedUrls.filter((u) => /\/api\/(modules|plugins)\/assets\/.*\.iife\.js/.test(u));
|
||||
@@ -39,7 +39,7 @@ test.describe('확장 병합 번들 로딩', () => {
|
||||
test('@smoke 병합 번들 응답이 정상(200/304)이고 same-origin 이다', async ({ page }) => {
|
||||
const bundleResponses: { url: string; status: number }[] = [];
|
||||
page.on('response', (res) => {
|
||||
if (/\/api\/(modules|plugins)\/bundle\.(js|css)/.test(res.url())) {
|
||||
if (/\/api\/(modules|plugins)\/bundle[./](js|css)/.test(res.url())) {
|
||||
bundleResponses.push({ url: res.url(), status: res.status() });
|
||||
}
|
||||
});
|
||||
@@ -75,4 +75,51 @@ test.describe('확장 병합 번들 로딩', () => {
|
||||
);
|
||||
expect(parseErrors, `번들 실행 관련 콘솔 에러: ${parseErrors.join(' | ')}`).toHaveLength(0);
|
||||
});
|
||||
|
||||
/**
|
||||
* 정상 구성에서는 자산 실패 안내가 뜨지 않는다.
|
||||
*
|
||||
* 스타일이 비어 있는 확장(0바이트 CSS)만 설치된 기본 구성에서 번들 CSS 가 503 이 되어
|
||||
* 사용자 화면마다 안내 배너가 떴다. 서버가 그 상태를 정상 빈 200 으로 판정한 뒤로는
|
||||
* 배너가 없어야 한다.
|
||||
*
|
||||
* // @scenario ext_type=module, asset_kind=css, active_combo=one, file_state=present_empty
|
||||
*
|
||||
* @effects empty_result_with_present_empty_artifacts_returns_200
|
||||
*/
|
||||
test('@smoke 정상 로드 시 자산 실패 안내가 없다', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle', { timeout: 30_000 });
|
||||
|
||||
await expect(page.locator('#g7-asset-failure-notice')).toHaveCount(0);
|
||||
|
||||
const failures = await page.evaluate(
|
||||
() => (window as any).G7Core?.assets?.getFailures?.() ?? [],
|
||||
);
|
||||
expect(failures, `자산 실패가 남아있음: ${JSON.stringify(failures)}`).toHaveLength(0);
|
||||
});
|
||||
|
||||
/**
|
||||
* 진짜 소실(503)일 때의 안내 항목명은 사용자 어휘여야 한다.
|
||||
*
|
||||
* 종전에는 번들 구분 키가 그대로 나와 "module을(를) 불러오지 못했습니다" 로 보였다.
|
||||
*
|
||||
* // @scenario ext_type=module, asset_kind=css, active_combo=one, file_state=one_missing
|
||||
*
|
||||
* @effects bundle_css_failure_banner_uses_user_vocabulary
|
||||
*/
|
||||
test('번들 CSS 가 503 이면 안내 항목명이 사용자 어휘다', async ({ page }) => {
|
||||
await page.route(/\/api\/(modules|plugins)\/bundle[./]css/, (route) =>
|
||||
route.fulfill({ status: 503, contentType: 'text/css', body: '' }),
|
||||
);
|
||||
|
||||
await page.goto('/');
|
||||
|
||||
const notice = page.locator('#g7-asset-failure-notice');
|
||||
await expect(notice).toBeVisible({ timeout: 30_000 });
|
||||
|
||||
const text = (await notice.innerText()).replace(/\s+/g, ' ');
|
||||
expect(text, `배너 문구: ${text}`).toContain('모듈 스타일');
|
||||
expect(text, `내부 구분 키가 노출됨: ${text}`).not.toContain('module을(를)');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Extension;
|
||||
|
||||
use App\Extension\AbstractModule;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* AbstractModule::getDeclaredAssetAbsolutePaths() 단위 테스트
|
||||
*
|
||||
* 이 게터는 **선언 축**이다 — 매니페스트가 선언한 산출물의 절대 경로를 파일 존재와
|
||||
* 무관하게 돌려준다. `getBuiltAssetAbsolutePaths()` 는 `file_exists()` 게이트라
|
||||
* 소실된 산출물이 목록에서 사라져 "선언은 있는데 파일이 없다" 를 셀 수 없다.
|
||||
*/
|
||||
class AbstractModuleDeclaredAssetsTest extends TestCase
|
||||
{
|
||||
private string $moduleDir;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->moduleDir = storage_path('framework/testing/declared-assets-module/vendor-sample');
|
||||
File::ensureDirectoryExists($this->moduleDir);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
File::deleteDirectory(dirname($this->moduleDir));
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* 임시 디렉토리를 모듈 루트로 쓰는 익명 서브클래스를 만든다.
|
||||
*
|
||||
* @param array<string, mixed> $assets 매니페스트 assets 선언
|
||||
*/
|
||||
private function moduleWithAssets(array $assets): AbstractModule
|
||||
{
|
||||
File::put(
|
||||
$this->moduleDir.'/module.json',
|
||||
json_encode(['name' => 'sample', 'version' => '1.0.0', 'assets' => $assets], JSON_UNESCAPED_UNICODE)
|
||||
);
|
||||
|
||||
$root = $this->moduleDir;
|
||||
|
||||
return new class($root) extends AbstractModule
|
||||
{
|
||||
public function __construct(private readonly string $root) {}
|
||||
|
||||
protected function getModulePath(): string
|
||||
{
|
||||
return $this->root;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 산출물이 하나도 없어도 선언한 kind 마다 절대 경로가 나온다.
|
||||
*/
|
||||
public function test_returns_declared_paths_even_when_files_are_absent(): void
|
||||
{
|
||||
$module = $this->moduleWithAssets([
|
||||
'js' => ['output' => 'dist/js/module.iife.js'],
|
||||
'css' => ['output' => 'dist/css/module.css'],
|
||||
]);
|
||||
|
||||
$declared = $module->getDeclaredAssetAbsolutePaths();
|
||||
|
||||
$this->assertSame(
|
||||
[
|
||||
'js' => $this->moduleDir.'/dist/js/module.iife.js',
|
||||
'css' => $this->moduleDir.'/dist/css/module.css',
|
||||
],
|
||||
$declared
|
||||
);
|
||||
// 존재 게이트를 타는 게터는 같은 상태에서 비어 있다 — 두 축이 다르다
|
||||
$this->assertSame([], $module->getBuiltAssetAbsolutePaths());
|
||||
}
|
||||
|
||||
/**
|
||||
* 선언하지 않은 kind 는 키 자체가 없다.
|
||||
*/
|
||||
public function test_omits_undeclared_kinds(): void
|
||||
{
|
||||
$module = $this->moduleWithAssets(['js' => ['output' => 'dist/js/module.iife.js']]);
|
||||
|
||||
$declared = $module->getDeclaredAssetAbsolutePaths();
|
||||
|
||||
$this->assertArrayHasKey('js', $declared);
|
||||
$this->assertArrayNotHasKey('css', $declared);
|
||||
}
|
||||
|
||||
/**
|
||||
* `output` 이 비어 있으면 선언으로 보지 않는다 (빈 문자열·빈 배열).
|
||||
*/
|
||||
public function test_treats_empty_output_as_undeclared(): void
|
||||
{
|
||||
$module = $this->moduleWithAssets([
|
||||
'js' => ['output' => ''],
|
||||
'css' => [],
|
||||
]);
|
||||
|
||||
$this->assertSame([], $module->getDeclaredAssetAbsolutePaths());
|
||||
}
|
||||
|
||||
/**
|
||||
* 산출물이 존재하되 0바이트여도 경로는 그대로 나온다 — 존재 판정은 호출자 몫이다.
|
||||
*/
|
||||
public function test_returns_path_for_present_zero_byte_artifact(): void
|
||||
{
|
||||
$module = $this->moduleWithAssets(['css' => ['output' => 'dist/css/module.css']]);
|
||||
File::ensureDirectoryExists($this->moduleDir.'/dist/css');
|
||||
File::put($this->moduleDir.'/dist/css/module.css', '');
|
||||
|
||||
$path = $module->getDeclaredAssetAbsolutePaths()['css'];
|
||||
|
||||
$this->assertSame($this->moduleDir.'/dist/css/module.css', $path);
|
||||
$this->assertTrue(is_file($path));
|
||||
$this->assertSame(0, filesize($path));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Extension;
|
||||
|
||||
use App\Extension\AbstractPlugin;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* AbstractPlugin::getDeclaredAssetAbsolutePaths() 단위 테스트
|
||||
*
|
||||
* 모듈 축과 동형이다 — 한쪽만 고쳐지면 플러그인 번들의 소실 판정이 조용히 침묵한다.
|
||||
*
|
||||
* @see AbstractModuleDeclaredAssetsTest
|
||||
*/
|
||||
class AbstractPluginDeclaredAssetsTest extends TestCase
|
||||
{
|
||||
private string $pluginDir;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->pluginDir = storage_path('framework/testing/declared-assets-plugin/vendor-sample');
|
||||
File::ensureDirectoryExists($this->pluginDir);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
File::deleteDirectory(dirname($this->pluginDir));
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* 임시 디렉토리를 플러그인 루트로 쓰는 익명 서브클래스를 만든다.
|
||||
*
|
||||
* @param array<string, mixed> $assets 매니페스트 assets 선언
|
||||
*/
|
||||
private function pluginWithAssets(array $assets): AbstractPlugin
|
||||
{
|
||||
File::put(
|
||||
$this->pluginDir.'/plugin.json',
|
||||
json_encode(['name' => 'sample', 'version' => '1.0.0', 'assets' => $assets], JSON_UNESCAPED_UNICODE)
|
||||
);
|
||||
|
||||
$root = $this->pluginDir;
|
||||
|
||||
return new class($root) extends AbstractPlugin
|
||||
{
|
||||
public function __construct(private readonly string $root) {}
|
||||
|
||||
protected function getPluginPath(): string
|
||||
{
|
||||
return $this->root;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 산출물이 하나도 없어도 선언한 kind 마다 절대 경로가 나온다.
|
||||
*/
|
||||
public function test_returns_declared_paths_even_when_files_are_absent(): void
|
||||
{
|
||||
$plugin = $this->pluginWithAssets([
|
||||
'js' => ['output' => 'dist/js/plugin.iife.js'],
|
||||
'css' => ['output' => 'dist/css/plugin.css'],
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
[
|
||||
'js' => $this->pluginDir.'/dist/js/plugin.iife.js',
|
||||
'css' => $this->pluginDir.'/dist/css/plugin.css',
|
||||
],
|
||||
$plugin->getDeclaredAssetAbsolutePaths()
|
||||
);
|
||||
$this->assertSame([], $plugin->getBuiltAssetAbsolutePaths());
|
||||
}
|
||||
|
||||
/**
|
||||
* 선언하지 않은 kind 는 키 자체가 없다.
|
||||
*/
|
||||
public function test_omits_undeclared_kinds(): void
|
||||
{
|
||||
$plugin = $this->pluginWithAssets(['css' => ['output' => 'dist/css/plugin.css']]);
|
||||
|
||||
$declared = $plugin->getDeclaredAssetAbsolutePaths();
|
||||
|
||||
$this->assertArrayHasKey('css', $declared);
|
||||
$this->assertArrayNotHasKey('js', $declared);
|
||||
}
|
||||
|
||||
/**
|
||||
* `output` 이 비어 있으면 선언으로 보지 않는다.
|
||||
*/
|
||||
public function test_treats_empty_output_as_undeclared(): void
|
||||
{
|
||||
$plugin = $this->pluginWithAssets([
|
||||
'js' => ['output' => ''],
|
||||
'css' => [],
|
||||
]);
|
||||
|
||||
$this->assertSame([], $plugin->getDeclaredAssetAbsolutePaths());
|
||||
}
|
||||
|
||||
/**
|
||||
* 산출물이 존재하되 0바이트여도 경로는 그대로 나온다.
|
||||
*/
|
||||
public function test_returns_path_for_present_zero_byte_artifact(): void
|
||||
{
|
||||
$plugin = $this->pluginWithAssets(['css' => ['output' => 'dist/css/plugin.css']]);
|
||||
File::ensureDirectoryExists($this->pluginDir.'/dist/css');
|
||||
File::put($this->pluginDir.'/dist/css/plugin.css', '');
|
||||
|
||||
$path = $plugin->getDeclaredAssetAbsolutePaths()['css'];
|
||||
|
||||
$this->assertSame($this->pluginDir.'/dist/css/plugin.css', $path);
|
||||
$this->assertTrue(is_file($path));
|
||||
$this->assertSame(0, filesize($path));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Extension;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 번들 확장 매니페스트의 자산 선언 계약 테스트
|
||||
*
|
||||
* 매니페스트가 선언한 산출물 경로는 **디스크에 실재해야 한다**. 어긋나면 증상이
|
||||
* 종류마다 다르고 전부 조용하다:
|
||||
*
|
||||
* - 모듈/플러그인의 `assets.{js,css}` 가 배열형이면 어느 소비자도 읽지 못해
|
||||
* 그 확장의 스크립트·스타일이 영영 로드되지 않는다 (오류 없음).
|
||||
* - 템플릿의 `assets.css` 가 없는 파일을 가리키면 봇 화면(SeoRenderer)이 404 를
|
||||
* 가리키는 `<link>` 를 싣는다 — 일반 화면에는 흔적이 없다.
|
||||
*
|
||||
* 0바이트 산출물은 **정당한 상태**다(스타일이 비어 있는 확장). 이 테스트는 존재만
|
||||
* 본다 — 크기를 보면 그 확장이 다시 배포 장애로 오판된다.
|
||||
*
|
||||
* 모집단은 glob 으로 파생한다. 손으로 적은 목록은 확장이 늘어날 때 조용히 낡는다.
|
||||
*/
|
||||
class BundledManifestAssetDeclarationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 모듈·플러그인 매니페스트의 `assets.{js,css}` 는 객체이며 산출물이 실재해야 한다.
|
||||
*/
|
||||
public function test_module_and_plugin_asset_declarations_are_objects_pointing_to_existing_files(): void
|
||||
{
|
||||
$manifests = [];
|
||||
|
||||
foreach ([['module', 'modules/_bundled'], ['plugin', 'plugins/_bundled']] as [$type, $root]) {
|
||||
foreach (glob(base_path($root).'/*/'.$type.'.json') as $manifestPath) {
|
||||
$manifests[] = [$manifestPath, dirname($manifestPath)];
|
||||
}
|
||||
}
|
||||
|
||||
// 모집단 하한 가드 — glob 이 0건이면 이 테스트는 아무것도 잠그지 않는다
|
||||
$this->assertGreaterThanOrEqual(
|
||||
10,
|
||||
count($manifests),
|
||||
'번들 모듈/플러그인 매니페스트 모집단이 비었거나 지나치게 작다 — 경로 규약이 바뀐 것이 아닌지 확인하라'
|
||||
);
|
||||
|
||||
$violations = [];
|
||||
|
||||
foreach ($manifests as [$manifestPath, $extensionDir]) {
|
||||
$manifest = json_decode((string) file_get_contents($manifestPath), true) ?? [];
|
||||
$assets = $manifest['assets'] ?? null;
|
||||
|
||||
if ($assets === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertIsArray($assets, $manifestPath.': assets 는 객체여야 한다');
|
||||
|
||||
foreach (['js', 'css'] as $kind) {
|
||||
if (! array_key_exists($kind, $assets)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$declaration = $assets[$kind];
|
||||
$relative = base_path().DIRECTORY_SEPARATOR;
|
||||
$shortManifest = str_replace($relative, '', $manifestPath);
|
||||
|
||||
if (! is_array($declaration) || ! isset($declaration['output']) || ! is_string($declaration['output']) || $declaration['output'] === '') {
|
||||
$violations[] = sprintf(
|
||||
'%s: assets.%s 는 { "output": "..." } 객체여야 한다 (현재: %s)',
|
||||
$shortManifest,
|
||||
$kind,
|
||||
json_encode($declaration, JSON_UNESCAPED_UNICODE)
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$artifact = $extensionDir.'/'.$declaration['output'];
|
||||
|
||||
if (! is_file($artifact)) {
|
||||
$violations[] = sprintf(
|
||||
'%s: assets.%s.output 이 가리키는 산출물이 없다 — %s',
|
||||
$shortManifest,
|
||||
$kind,
|
||||
$declaration['output']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertSame([], $violations, "번들 확장 매니페스트 자산 선언 위반:\n".implode("\n", $violations));
|
||||
}
|
||||
|
||||
/**
|
||||
* 템플릿 매니페스트의 `assets` 경로도 실재해야 한다.
|
||||
*
|
||||
* `css`/`js` 는 파일, `fonts`/`images` 는 디렉토리로 본다. 빈 배열은 "선언 없음" 이라
|
||||
* 정상이다.
|
||||
*/
|
||||
public function test_template_asset_declarations_point_to_existing_files(): void
|
||||
{
|
||||
$manifests = glob(base_path('templates/_bundled').'/*/template.json');
|
||||
|
||||
$this->assertGreaterThanOrEqual(
|
||||
3,
|
||||
count($manifests),
|
||||
'번들 템플릿 매니페스트 모집단이 비었거나 지나치게 작다'
|
||||
);
|
||||
|
||||
$violations = [];
|
||||
$directoryKinds = ['fonts', 'images'];
|
||||
|
||||
foreach ($manifests as $manifestPath) {
|
||||
$manifest = json_decode((string) file_get_contents($manifestPath), true) ?? [];
|
||||
$templateDir = dirname($manifestPath);
|
||||
$shortManifest = str_replace(base_path().DIRECTORY_SEPARATOR, '', $manifestPath);
|
||||
|
||||
foreach (($manifest['assets'] ?? []) as $kind => $paths) {
|
||||
foreach ((array) $paths as $candidate) {
|
||||
$absolute = $templateDir.'/'.$candidate;
|
||||
$exists = in_array($kind, $directoryKinds, true)
|
||||
? is_dir($absolute)
|
||||
: is_file($absolute);
|
||||
|
||||
if (! $exists) {
|
||||
$violations[] = sprintf('%s: assets.%s 의 %s 가 없다', $shortManifest, $kind, $candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertSame([], $violations, "번들 템플릿 매니페스트 자산 선언 위반:\n".implode("\n", $violations));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Seo;
|
||||
|
||||
use App\Seo\SeoRenderer;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use ReflectionMethod;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* SeoRenderer 가 봇 화면에 싣는 템플릿 CSS 는 파일이 있을 때만 링크한다.
|
||||
*
|
||||
* `template.json` 의 `assets.css` 는 선언일 뿐이라 산출물이 없을 수 있다. 그 경로를
|
||||
* 그대로 `<link>` 로 실으면 봇 화면에서만 404 가 나고 일반 화면에는 흔적이 없다 —
|
||||
* 서버 로그에도 남지 않으므로 운영자가 알 방법이 없다.
|
||||
*/
|
||||
class SeoRendererTemplateCssGateTest extends TestCase
|
||||
{
|
||||
private string $templateRoot;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->templateRoot = storage_path('framework/testing/seo-template-css/vendor-sample');
|
||||
File::ensureDirectoryExists($this->templateRoot);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
File::deleteDirectory(dirname($this->templateRoot));
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* 임시 디렉토리를 템플릿 루트로 쓰는 익명 서브클래스를 만든다.
|
||||
*
|
||||
* @param list<string> $cssPaths template.json 의 assets.css 선언
|
||||
*/
|
||||
private function rendererWithTemplateCss(array $cssPaths): SeoRenderer
|
||||
{
|
||||
File::put(
|
||||
$this->templateRoot.'/template.json',
|
||||
json_encode(['name' => 'sample', 'assets' => ['css' => $cssPaths]], JSON_UNESCAPED_UNICODE)
|
||||
);
|
||||
|
||||
$root = $this->templateRoot;
|
||||
|
||||
// 부모 생성자(의존 12개)는 호출하지 않는다 — getTemplateCssUrls 는 그 의존을
|
||||
// 하나도 쓰지 않으므로 미초기화 프로퍼티에 닿지 않는다.
|
||||
return new class($root) extends SeoRenderer
|
||||
{
|
||||
public function __construct(private readonly string $root) {}
|
||||
|
||||
protected function templateRootPath(string $identifier): string
|
||||
{
|
||||
return $this->root;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $cssPaths
|
||||
* @return list<string>
|
||||
*/
|
||||
private function cssUrls(array $cssPaths): array
|
||||
{
|
||||
$renderer = $this->rendererWithTemplateCss($cssPaths);
|
||||
$method = new ReflectionMethod(SeoRenderer::class, 'getTemplateCssUrls');
|
||||
|
||||
return $method->invoke($renderer, 'vendor-sample');
|
||||
}
|
||||
|
||||
/**
|
||||
* 존재하는 CSS 만 URL 로 나온다 — 없는 경로는 조용히 빠진다.
|
||||
*/
|
||||
public function test_only_existing_css_paths_become_urls(): void
|
||||
{
|
||||
File::ensureDirectoryExists($this->templateRoot.'/dist/css');
|
||||
File::put($this->templateRoot.'/dist/css/components.css', '.a{color:red}');
|
||||
|
||||
$urls = $this->cssUrls(['dist/css/components.css', 'dist/css/absent.css']);
|
||||
|
||||
$this->assertCount(1, $urls);
|
||||
$this->assertStringContainsString('css/components.css', $urls[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 선언한 CSS 가 하나도 없으면 빈 배열이다 (404 링크를 만들지 않는다).
|
||||
*/
|
||||
public function test_absent_css_declaration_yields_no_urls(): void
|
||||
{
|
||||
$this->assertSame([], $this->cssUrls(['dist/css/components.css']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 0바이트 CSS 는 존재하므로 링크한다 — 존재 여부만 본다.
|
||||
*/
|
||||
public function test_present_zero_byte_css_is_still_linked(): void
|
||||
{
|
||||
File::ensureDirectoryExists($this->templateRoot.'/dist/css');
|
||||
File::put($this->templateRoot.'/dist/css/components.css', '');
|
||||
|
||||
$this->assertCount(1, $this->cssUrls(['dist/css/components.css']));
|
||||
}
|
||||
}
|
||||
@@ -110,16 +110,26 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
/**
|
||||
* 에셋 **매니페스트 선언**(`getAssets()`)을 노출하는 가짜 확장 인스턴스를 만든다.
|
||||
*
|
||||
* 산출물 경로(`getBuiltAssetAbsolutePaths`)는 존재하지 않는 파일을 가리킨다 —
|
||||
* 산출물 경로(`getBuiltAssetAbsolutePaths`)는 기본적으로 존재하지 않는 파일을 가리킨다 —
|
||||
* "선언은 있는데 산출물이 없다"(dist 소실) 상태를 그대로 재현하기 위해서다.
|
||||
*
|
||||
* 선언 축 게터(`getDeclaredAssetAbsolutePaths`)는 파일 존재와 무관하게 선언된 kind 마다
|
||||
* 경로를 돌려준다. `$declaredPaths` 로 그 경로를 지정하면 실제로 만들어 둔 fixture 파일을
|
||||
* 가리키게 해 "존재하되 비어 있음" 상태를 만들 수 있다.
|
||||
*
|
||||
* @param string $identifier 확장 식별자
|
||||
* @param int $priority 로딩 우선순위
|
||||
* @param array<string, mixed> $assets 매니페스트 assets 선언
|
||||
* @param string $strategy 로딩 전략
|
||||
* @param array<string, string>|null $declaredPaths kind => 절대 경로 (미지정 시 fixtureDir 의 부재 경로)
|
||||
*/
|
||||
private function fakeExtensionWithAssets(string $identifier, int $priority, array $assets, string $strategy = 'global'): object
|
||||
{
|
||||
private function fakeExtensionWithAssets(
|
||||
string $identifier,
|
||||
int $priority,
|
||||
array $assets,
|
||||
string $strategy = 'global',
|
||||
?array $declaredPaths = null
|
||||
): object {
|
||||
$ext = Mockery::mock();
|
||||
$ext->shouldReceive('hasAssets')->andReturn($assets !== []);
|
||||
$ext->shouldReceive('getIdentifier')->andReturn($identifier);
|
||||
@@ -136,6 +146,12 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
array_map(fn () => 'dist/css/module.css', $assets)
|
||||
);
|
||||
|
||||
$declared = $declaredPaths ?? array_combine(
|
||||
array_keys($assets),
|
||||
array_map(fn ($kind) => $this->fixtureDir.'/declared-'.$identifier.'.'.$kind, array_keys($assets))
|
||||
);
|
||||
$ext->shouldReceive('getDeclaredAssetAbsolutePaths')->andReturn($declared);
|
||||
|
||||
return $ext;
|
||||
}
|
||||
|
||||
@@ -174,10 +190,17 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertSame(1, $service->countAssetDeclaringExtensions('module', 'css'));
|
||||
|
||||
// 산출물은 하나도 존재하지 않는다 → 병합 결과는 빈 문자열.
|
||||
// "선언 > 0 && 결과 0" 이 곧 컨트롤러의 503 조건이다.
|
||||
// 이 값은 **선언 축**이다 — 컨트롤러의 503 판정은 소실 축(findMissingDeclaredAssets)이
|
||||
// 한다. 선언 > 0 그 자체는 장애 조건이 아니다(존재하되 비어 있으면 정상 빈 200).
|
||||
$this->assertSame('', $service->getBundleFilePath('module', 'js', 12345));
|
||||
}
|
||||
|
||||
/**
|
||||
* 실행 순서는 오직 manifest `loading.priority` 오름차순이다 — 확장 이름을 지목하는
|
||||
* 분기를 두지 않는다.
|
||||
*
|
||||
* @effects ordered_by_priority_ascending_only_no_name_hardcode
|
||||
*/
|
||||
public function test_orders_global_assets_by_priority_ascending(): void
|
||||
{
|
||||
$a = $this->writeFixture('a.js', '(function(){})()');
|
||||
@@ -195,6 +218,11 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertSame(['ext-a', 'ext-b', 'ext-c'], array_keys($ordered));
|
||||
}
|
||||
|
||||
/**
|
||||
* global 전략이 아닌 확장은 번들 모집단이 아니다 (레이아웃/지연 로딩이 따로 처리한다).
|
||||
*
|
||||
* @effects non_global_strategy_excluded_from_bundle
|
||||
*/
|
||||
public function test_skips_non_global_strategy(): void
|
||||
{
|
||||
$g = $this->writeFixture('g.js', '(function(){})()');
|
||||
@@ -211,6 +239,11 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertArrayNotHasKey('ext-layout', $ordered);
|
||||
}
|
||||
|
||||
/**
|
||||
* IIFE 사이는 `\n;\n` 로 잇는다 — 구분자가 없으면 ASI 경계가 깨져 번들 전체가 죽는다.
|
||||
*
|
||||
* @effects js_iife_joined_with_semicolon_newline_separator
|
||||
*/
|
||||
public function test_js_bundle_joins_iife_with_semicolon_newline_separator(): void
|
||||
{
|
||||
// 세미콜론 없이 끝나는 IIFE 2개 (ecommerce 형태)
|
||||
@@ -232,6 +265,9 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertLessThan(strpos($js, 'window.B=2'), strpos($js, 'window.A=1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects prod_strips_source_mapping_url
|
||||
*/
|
||||
public function test_prod_strips_source_mapping_url(): void
|
||||
{
|
||||
$this->app['env'] = 'production';
|
||||
@@ -248,6 +284,9 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertStringNotContainsString('sourceMappingURL', $js);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects dev_rewrites_source_mapping_url_to_asset_serving_path
|
||||
*/
|
||||
public function test_dev_rewrites_source_mapping_url_to_asset_serving_path(): void
|
||||
{
|
||||
// 자산 URL 표기(경로형 vs `?file=` 쿼리형)는 사이트 설정이 정한다. 이 테스트가 보려는
|
||||
@@ -300,6 +339,11 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertStringContainsString('sourceMappingURL', $bundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 한 확장의 읽기 실패가 번들 전체를 소실시키지 않는다 — 그 확장만 빠지고 나머지는 병합된다.
|
||||
*
|
||||
* @effects per_extension_fault_tolerance_skips_missing_file_keeps_rest
|
||||
*/
|
||||
public function test_per_extension_fault_tolerance_skips_missing_file(): void
|
||||
{
|
||||
$good = $this->writeFixture('good.js', '(function(){window.GOOD=1})()');
|
||||
@@ -323,6 +367,8 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
* 적었지만, 번들 URL 이 내려오면 프론트는 개별 로딩을 아예 타지 않는다
|
||||
* (TemplateApp.loadExtensionAssets). 즉 제외 = 그 확장 스타일이 하나도 적용되지 않음
|
||||
* 이었고, 오류도 로그 흔적도 화면 경고도 남지 않았다.
|
||||
*
|
||||
* @effects css_with_relative_url_rewritten_not_excluded
|
||||
*/
|
||||
public function test_css_with_relative_url_is_rewritten_not_excluded(): void
|
||||
{
|
||||
@@ -370,6 +416,9 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertStringContainsString('url(data:image/gif;base64,AA==)', $css);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects empty_bundle_returns_empty_path_and_empty_ok_response
|
||||
*/
|
||||
public function test_empty_bundle_returns_empty_path(): void
|
||||
{
|
||||
$this->moduleManager->shouldReceive('getActiveModules')->andReturn([]);
|
||||
@@ -379,6 +428,9 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertSame('', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects prod_writes_versioned_cache_file_and_reuses_on_same_version
|
||||
*/
|
||||
public function test_prod_writes_versioned_cache_file_and_reuses_it(): void
|
||||
{
|
||||
$this->app['env'] = 'production';
|
||||
@@ -402,6 +454,42 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertSame($path1, $path2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 비프로덕션은 같은 version 이어도 매 요청 다시 병합한다 (캐시 재사용 없음).
|
||||
*
|
||||
* 프로덕션은 같은 version 캐시가 있으면 그대로 재사용하지만, 비프로덕션에서 그러면
|
||||
* 개발 중 rebuild 가 반영되지 않는다. 소스를 바꿨는데 화면이 그대로인 상태는 오류도
|
||||
* 로그도 남지 않아 원인을 짚을 수 없다.
|
||||
*
|
||||
* @effects non_production_rebuilds_every_request_no_disk_cache
|
||||
*/
|
||||
public function test_non_production_rebuilds_every_request_without_cache_reuse(): void
|
||||
{
|
||||
$this->assertFalse(app()->environment('production'));
|
||||
|
||||
$a = $this->writeFixture('nonprod.js', '(function(){window.A=1})()');
|
||||
$this->moduleManager->shouldReceive('getActiveModules')->andReturn([
|
||||
'ext-a' => $this->fakeExtension('ext-a', 10, $a, null),
|
||||
]);
|
||||
|
||||
$svc = $this->service();
|
||||
|
||||
$path1 = $svc->getBundleFilePath('module', 'js', 4242);
|
||||
$this->assertStringContainsString('window.A=1', (string) file_get_contents($path1));
|
||||
|
||||
// 소스를 바꾸고 **같은 version** 으로 다시 요청 → 재병합되어야 한다
|
||||
File::put($a, '(function(){window.A=2})()');
|
||||
$path2 = $svc->getBundleFilePath('module', 'js', 4242);
|
||||
|
||||
$this->assertSame($path1, $path2);
|
||||
$this->assertStringContainsString('window.A=2', (string) file_get_contents($path2));
|
||||
|
||||
@unlink($path1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects cleanup_removes_stale_version_bundles_only
|
||||
*/
|
||||
public function test_cleanup_removes_stale_version_bundles_only(): void
|
||||
{
|
||||
$bundleDir = storage_path('app/ext-bundles');
|
||||
@@ -421,6 +509,9 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$this->assertFileDoesNotExist($bundleDir.'/plugin.100.css');
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects clear_bundles_by_type_scopes_to_prefix
|
||||
*/
|
||||
public function test_clear_bundles_by_type(): void
|
||||
{
|
||||
$bundleDir = storage_path('app/ext-bundles');
|
||||
@@ -498,6 +589,9 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects plugin_bundle_gdpr_first_when_priority_lowest
|
||||
*/
|
||||
public function test_plugin_bundle_orders_by_priority_gdpr_first_when_lowest(): void
|
||||
{
|
||||
// gdpr 가 priority 50 으로 최상단(제약 1 회귀 가드) — 이름 하드코딩 아닌 선언 결과
|
||||
@@ -516,4 +610,105 @@ class ExtensionBundleServiceTest extends TestCase
|
||||
$js = $this->service()->buildJsBundle('plugin');
|
||||
$this->assertLessThan(strpos($js, 'window.OTHER=1'), strpos($js, 'window.GDPR=1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 선언한 산출물이 **존재하되 0바이트**면 소실 목록에 넣지 않는다.
|
||||
*
|
||||
* 스타일 소스가 자리표시 주석뿐인 확장은 0바이트 CSS 를 내보내는 정당한 상태다.
|
||||
* 이것을 소실로 세면 그 확장만 설치된 기본 구성이 통째로 503 이 된다.
|
||||
*
|
||||
* @effects empty_result_with_present_empty_artifacts_returns_200
|
||||
*/
|
||||
public function test_find_missing_declared_assets_ignores_present_zero_byte_files(): void
|
||||
{
|
||||
$cssPath = $this->writeFixture('present-empty.css', '');
|
||||
|
||||
$this->moduleManager->shouldReceive('getActiveModules')->andReturn([
|
||||
'ext-empty-css' => $this->fakeExtensionWithAssets(
|
||||
'ext-empty-css',
|
||||
100,
|
||||
['css' => ['output' => 'dist/css/module.css']],
|
||||
'global',
|
||||
['css' => $cssPath]
|
||||
),
|
||||
]);
|
||||
|
||||
$service = $this->service();
|
||||
|
||||
$this->assertSame(0, filesize($cssPath));
|
||||
$this->assertSame([], $service->findMissingDeclaredAssets('module', 'css'));
|
||||
// 선언 축은 그대로 1 — 두 축이 다른 것을 잰다
|
||||
$this->assertSame(1, $service->countAssetDeclaringExtensions('module', 'css'));
|
||||
// 병합 결과는 빈 문자열이지만 장애가 아니다
|
||||
$this->assertSame('', $service->buildCssBundle('module'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 선언한 산출물이 **없으면** 그 절대 경로를 소실 목록으로 돌려준다.
|
||||
*
|
||||
* non-global 전략 확장은 병합 모집단이 아니므로 소실 판정에서도 제외된다 —
|
||||
* 두 판정이 같은 모집단을 써야 한쪽만 장애로 보는 어긋남이 생기지 않는다.
|
||||
*
|
||||
* @effects empty_result_with_missing_declared_artifact_returns_503
|
||||
*/
|
||||
public function test_find_missing_declared_assets_lists_absent_files(): void
|
||||
{
|
||||
$absent = $this->fixtureDir.'/absent-module.css';
|
||||
$absentLayout = $this->fixtureDir.'/absent-layout.css';
|
||||
@unlink($absent);
|
||||
@unlink($absentLayout);
|
||||
|
||||
$this->moduleManager->shouldReceive('getActiveModules')->andReturn([
|
||||
'ext-gone' => $this->fakeExtensionWithAssets(
|
||||
'ext-gone',
|
||||
100,
|
||||
['css' => ['output' => 'dist/css/module.css']],
|
||||
'global',
|
||||
['css' => $absent]
|
||||
),
|
||||
'ext-layout' => $this->fakeExtensionWithAssets(
|
||||
'ext-layout',
|
||||
100,
|
||||
['css' => ['output' => 'dist/css/module.css']],
|
||||
'layout',
|
||||
['css' => $absentLayout]
|
||||
),
|
||||
]);
|
||||
|
||||
$missing = $this->service()->findMissingDeclaredAssets('module', 'css');
|
||||
|
||||
$this->assertSame([$absent], $missing);
|
||||
$this->assertNotContains($absentLayout, $missing);
|
||||
}
|
||||
|
||||
/**
|
||||
* 플러그인 축도 같은 판정을 쓴다 — 모집단만 다르다.
|
||||
*
|
||||
* @effects bundle_decision_is_shared_across_extension_types
|
||||
*/
|
||||
public function test_find_missing_declared_assets_covers_plugins(): void
|
||||
{
|
||||
$absent = $this->fixtureDir.'/absent-plugin.js';
|
||||
@unlink($absent);
|
||||
$present = $this->writeFixture('present-plugin.js', '');
|
||||
|
||||
$this->pluginManager->shouldReceive('getActivePlugins')->andReturn([
|
||||
'plg-gone' => $this->fakeExtensionWithAssets(
|
||||
'plg-gone',
|
||||
100,
|
||||
['js' => ['output' => 'dist/js/plugin.iife.js']],
|
||||
'global',
|
||||
['js' => $absent]
|
||||
),
|
||||
'plg-empty' => $this->fakeExtensionWithAssets(
|
||||
'plg-empty',
|
||||
100,
|
||||
['js' => ['output' => 'dist/js/plugin.iife.js']],
|
||||
'global',
|
||||
['js' => $present]
|
||||
),
|
||||
]);
|
||||
|
||||
$this->assertSame([$absent], $this->service()->findMissingDeclaredAssets('plugin', 'js'));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
# audit:allow test-scenario-coverage reason: 서버측 확장 번들 병합 도입 회귀 가드. 입력 axis(활성 조합·환경·에셋 종류)의 cross-product 는 test_files 의 Unit/Feature 가 cover 하고, effects 는 병합 계약(순서/구분자/소스맵/캐시/폴백)과 브라우저 실측(요청수/gdpr race)을 enumerate.
|
||||
# audit:allow test-scenario-coverage[cross_product] reason: 입력 axis 의 완전 cross-product(11축)는 조합 폭발이라 대표 조합만 마킹한다. effects 축은 면제하지 않는다 — 모든 effect 가 테스트 마킹으로 도달해야 한다.
|
||||
|
||||
feature: 확장(모듈/플러그인) 프론트엔드 IIFE/CSS 서버측 번들 병합
|
||||
|
||||
@@ -24,7 +24,7 @@ axes:
|
||||
version_state: [first_request, cache_hit, version_bumped]
|
||||
source_map_state: [present, absent]
|
||||
css_url_state: [no_url, absolute_url, relative_url]
|
||||
file_state: [all_present, one_missing]
|
||||
file_state: [all_present, present_empty, one_missing]
|
||||
priority_order: [ascending, gdpr_lowest]
|
||||
bundle_urls_present: [present, absent_fallback]
|
||||
|
||||
@@ -39,7 +39,7 @@ effects:
|
||||
- prod_strips_source_mapping_url
|
||||
- dev_rewrites_source_mapping_url_to_asset_serving_path
|
||||
- per_extension_fault_tolerance_skips_missing_file_keeps_rest
|
||||
- css_with_relative_url_excluded_from_bundle
|
||||
- css_with_relative_url_rewritten_not_excluded
|
||||
- empty_bundle_returns_empty_path_and_empty_ok_response
|
||||
- prod_writes_versioned_cache_file_and_reuses_on_same_version
|
||||
- non_production_rebuilds_every_request_no_disk_cache
|
||||
@@ -56,9 +56,21 @@ effects:
|
||||
- individual_iife_requests_absent_in_browser
|
||||
- gdpr_interceptor_still_active_after_merge
|
||||
- extension_handlers_registered_no_console_error
|
||||
- bundle_empty_with_declared_assets_returns_503
|
||||
- asset_declaration_count_reads_manifest_not_built_files
|
||||
- bundle_decision_is_shared_across_extension_types
|
||||
- bundle_disk_write_failure_falls_back_to_memory
|
||||
- bundle_script_static_miss_falls_back_to_api
|
||||
- empty_result_with_present_empty_artifacts_returns_200
|
||||
- empty_result_with_missing_declared_artifact_returns_503
|
||||
- missing_artifact_paths_are_logged
|
||||
- bundle_css_failure_banner_uses_user_vocabulary
|
||||
|
||||
test_files:
|
||||
- tests/Unit/Services/ExtensionBundleServiceTest.php
|
||||
- tests/Unit/Extension/AbstractModuleDeclaredAssetsTest.php
|
||||
- tests/Unit/Extension/AbstractPluginDeclaredAssetsTest.php
|
||||
- tests/Unit/Extension/BundledManifestAssetDeclarationTest.php
|
||||
- tests/Feature/Api/Public/ExtensionBundleServingTest.php
|
||||
- resources/js/core/modules/__tests__/ModuleAssetLoader.test.ts
|
||||
- tests/Playwright/specs/extension-bundle-loading.spec.ts
|
||||
|
||||
Reference in new issue
Block a user