feat(core,extensions): 구동 에셋 자체 제공 · 자산 실패 폴백 · 운영자 추가 에셋(custom/)

공개 저장소 이슈 gnuboard/g7 (@bigmsg) 제보에서 출발한 작업이다.

브라우저가 화면을 그리려고 제3자 CDN 에 도달해야 하면, 그 도달 실패는 예외도 로그도
남기지 않고 화면 기능만 조용히 사라진다. 폐쇄망·방화벽·광고차단기에서 재현되는데
자체 서버 로그에는 흔적이 없어 운영자가 원인을 특정할 수 없다. 제보된 것은 편집기
하나였지만 같은 구조가 아이콘·글꼴·코드편집기·압축 라이브러리·설치 마법사·개발
대시보드에 똑같이 있었으므로, 번들 확장과 템플릿 전체를 자체 제공으로 옮겼다.
런타임에 외부로 나가는 것은 주소 검색 서비스 하나만 남았다.

자체 제공만으로는 부족하다 — 자기 서버에서 받는 파일도 실패할 수 있고, 종전에는 그
실패가 무음이었다. CSS 경로에 재시도 계층을 세우고(스크립트 경로와 동형), 서버가 HTML
에 직접 심는 externals 까지 실패를 붙잡아 안내 배너와 [다시 시도]로 표면화했다.
편집기·코드편집기는 확보 실패 시 평문 입력으로 내려앉되 저장 계약을 유지한다.

두 번째 축은 운영자가 CSS 를 덧붙일 자리가 없던 문제다(sir.kr 문의). 확장 디렉토리의
custom/ 을 운영자 소유로 정해, 확장 교체가 그 디렉토리만은 보존하게 했다. 출처에
의존하지 않는 서술자로 해석하므로 나중에 다른 출처가 붙어도 소비자는 바뀌지 않는다.
확장 자산과 같은 메커니즘으로 정적 게시되어 CSS 내부 상대 url 도 해석되고, 파일을
고치면 그 변경을 감지해 재게시까지 예약된다.

FTP 접근이 없는 운영자에게는 그 자리도 없는 것과 같으므로 레이아웃 편집기에서 직접
넣고 고칠 수 있게 했다. 모듈·플러그인·템플릿이 한 엔드포인트를 공유한다 — 타입별로
나누면 같은 검증이 세 벌로 갈리고 그중 약한 하나가 우회로가 된다. 여기서 올린
스크립트는 그 레이아웃 한 장이 아니라 사이트 전 화면에서 실행되므로 레이아웃 편집과
분리된 전용 권한으로 연다. 운영자 CSS 가 화면을 조작 불능으로 만들면 그것을 고칠
화면에도 같은 CSS 가 실려 스스로 갇히므로, 서버가 목록을 비우는 탈출구(?custom=off)를
함께 뒀다.

동봉 자산은 재생성 경로에 버전 대조 가드를 붙였다. 선언과 다른 버전을 버전 디렉토리에
써 넣는 조용한 거짓말은 배포된 뒤에는 드러나지 않는다.
This commit is contained in:
HeuJung committed 2026-08-27 16:47:14 +09:00
1 parent 72f2e94c1a
commit 3945b6f1b3
1042 files changed
+107435 -947

No files matched your search

@@ -2,8 +2,12 @@
namespace Tests\Feature\Services;
use App\Contracts\Repositories\ModuleRepositoryInterface;
use App\Contracts\Repositories\PluginRepositoryInterface;
use App\Contracts\Repositories\TemplateRepositoryInterface;
use App\Enums\ExtensionStatus;
use App\Models\Module;
use App\Models\Plugin;
use App\Models\Template;
use App\Services\ExtensionBundleService;
use App\Services\ExtensionStaticCacheService;
@@ -71,11 +75,73 @@ class ExtensionStaticCacheServiceTest extends TestCase
File::deleteDirectory(public_path('build/ext'));
}
/**
* 게시 실패 시 어느 분기에서 멈췄는지 보여 줍니다.
*
* `publishCurrent()` 는 여러 사유로 **조용히 false** 를 돌려준다(kill-switch·락 미획득·
* 게시 중 예외). 단언 메시지가 "false is true" 뿐이면 그중 무엇인지 알 수 없어, 간헐적
* 실패를 만났을 때 재현부터 다시 해야 한다.
*
* @param ExtensionStaticCacheService $svc 대상 서비스
* @return string 진단 문자열
*/
private function publishDiagnostics(ExtensionStaticCacheService $svc): string
{
$v = ExtensionStaticCacheService::getExtensionCacheVersion();
$lock = Cache::lock('ext-static.publish.'.$v, 1);
$free = $lock->get();
if ($free) {
$lock->release();
}
$store = config('cache.default');
return sprintf(
'enabled=%s version=%d expected=%d lockFree=%s store=%s published=%s baseDir=%s',
var_export($svc->isEnabled(), true), $v, self::VERSION, var_export($free, true),
$store, var_export($svc->isPublished($v), true), $svc->baseDir()
);
}
private function service(): ExtensionStaticCacheService
{
return app(ExtensionStaticCacheService::class);
}
/**
* 활성 모듈·플러그인 행을 만듭니다.
*
* 레포지토리를 모킹하지 않는다 — 게시에는 번들 서비스 등 같은 레포지토리를 쓰는 다른
* 소비자가 있어, 인터페이스를 통째로 대체하면 그쪽이 끊겨 게시 자체가 실패한다.
* `RefreshDatabase` 라 행은 테스트마다 비어 있으므로 실제 설치본에 좌우되지도 않는다.
*
* @param array<int, string> $modules 활성 모듈 식별자
* @param array<int, string> $plugins 활성 플러그인 식별자
*/
private function createActiveExtensions(array $modules, array $plugins): void
{
foreach ($modules as $identifier) {
Module::create([
'identifier' => $identifier,
'vendor' => explode('-', $identifier)[0],
'name' => ['ko' => '테스트 모듈', 'en' => 'Test Module'],
'version' => '1.0.0',
'status' => ExtensionStatus::Active->value,
'description' => ['ko' => '테스트', 'en' => 'Test'],
]);
}
foreach ($plugins as $identifier) {
Plugin::create([
'identifier' => $identifier,
'vendor' => explode('-', $identifier)[0],
'name' => ['ko' => '테스트 플러그인', 'en' => 'Test Plugin'],
'version' => '1.0.0',
'status' => ExtensionStatus::Active->value,
'description' => ['ko' => '테스트', 'en' => 'Test'],
]);
}
}
private function createActiveTemplate(string $identifier = 'sirsoft-admin_basic', string $type = 'admin'): Template
{
return Template::create([
@@ -98,7 +164,7 @@ class ExtensionStaticCacheServiceTest extends TestCase
{
$service = $this->service();
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$this->assertTrue($service->isPublished(self::VERSION));
$this->assertFileExists($service->versionDir(self::VERSION).'/manifest.json');
$this->assertFileExists($service->versionDir(self::VERSION).'/.htaccess');
@@ -114,7 +180,7 @@ class ExtensionStaticCacheServiceTest extends TestCase
$this->createActiveTemplate();
$service = $this->service();
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$publishedPath = $service->versionDir(self::VERSION).'/templates/sirsoft-admin_basic/lang/ko.json';
$this->assertFileExists($publishedPath);
@@ -140,7 +206,7 @@ class ExtensionStaticCacheServiceTest extends TestCase
$this->createActiveTemplate();
$service = $this->service();
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$publishedPath = $service->versionDir(self::VERSION).'/templates/sirsoft-admin_basic/routes.json';
$this->assertFileExists($publishedPath);
@@ -155,6 +221,89 @@ class ExtensionStaticCacheServiceTest extends TestCase
$this->assertSame($apiResponse->json('data'), $published['data']);
}
/**
* 활성 모듈·플러그인의 운영자 소유 디렉토리(`custom/`)도 게시된다.
*
* 모듈·플러그인 빌드 산출물은 **병합 번들**로만 게시되는데 `custom/` 은 그 번들에
* 들어가지 않는다. 게시하지 않으면 확장 자산 중 이것만 요청마다 PHP 를 거치고,
* CSS 내부 상대 `url()` 이 해석되지 않는다 — 이 축이 빠지면 같은 기능이 확장 타입에
* 따라 다르게 동작하고 그 이유가 화면에 드러나지 않는다.
*
* @effects custom_asset_published_for_all_extension_types
*/
public function test_publishes_active_module_and_plugin_custom_assets(): void
{
$this->createActiveTemplate();
$module = 'g7test-publish_module';
$plugin = 'g7test-publish_plugin';
$fixtures = [
base_path("modules/{$module}/custom") => 'modules/'.$module,
base_path("plugins/{$plugin}/custom") => 'plugins/'.$plugin,
];
foreach (array_keys($fixtures) as $dir) {
File::ensureDirectoryExists($dir.'/fonts');
File::put($dir.'/custom.css', "body { background-image: url('./fonts/x.woff2'); }");
File::put($dir.'/fonts/x.woff2', 'font');
File::put($dir.'/notes.txt', 'not an asset');
}
// 활성 목록은 레포지토리가 판정한다 — 실제 설치본에 의존하면 이 저장소 상태에 따라
// 단언이 공허하게 통과한다.
$this->createActiveExtensions([$module], [$plugin]);
try {
$service = $this->service();
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$versionDir = $service->versionDir(self::VERSION);
foreach ($fixtures as $root) {
$this->assertFileExists($versionDir."/{$root}/assets/custom/custom.css");
$this->assertFileExists($versionDir."/{$root}/assets/custom/fonts/x.woff2");
// 허용 확장자 화이트리스트는 타입과 무관하게 같아야 한다
$this->assertFileDoesNotExist($versionDir."/{$root}/assets/custom/notes.txt");
}
} finally {
File::deleteDirectory(base_path("modules/{$module}"));
File::deleteDirectory(base_path("plugins/{$plugin}"));
}
}
/**
* 비활성 확장의 custom 은 게시하지 않는다.
*
* 자산 서빙이 활성 확장에만 응답하므로, 게시해 봐야 아무도 참조하지 않는 사본이
* 버전 디렉토리마다 쌓인다.
*
* @effects custom_asset_published_for_all_extension_types
*/
public function test_inactive_module_custom_is_absent_from_published_tree(): void
{
$this->createActiveTemplate();
$module = 'g7test-inactive_module';
$dir = base_path("modules/{$module}/custom");
File::ensureDirectoryExists($dir);
File::put($dir.'/custom.css', '/* operator */');
// 활성 행을 만들지 않는다 — 비활성(미설치) 상태 그대로.
try {
$service = $this->service();
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$this->assertFileDoesNotExist(
$service->versionDir(self::VERSION)."/modules/{$module}/assets/custom/custom.css"
);
} finally {
File::deleteDirectory(base_path("modules/{$module}"));
}
}
/**
* components.json 사본과 dist 에셋이 게시되고 `*.map` 은 제외된다.
*
@@ -165,7 +314,7 @@ class ExtensionStaticCacheServiceTest extends TestCase
$this->createActiveTemplate();
$service = $this->service();
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$templateDir = $service->versionDir(self::VERSION).'/templates/sirsoft-admin_basic';
@@ -201,7 +350,7 @@ class ExtensionStaticCacheServiceTest extends TestCase
]);
$service = $this->service();
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$this->assertDirectoryExists($service->versionDir(self::VERSION).'/templates/sirsoft-admin_basic');
$this->assertDirectoryDoesNotExist($service->versionDir(self::VERSION).'/templates/sirsoft-basic');
@@ -228,7 +377,7 @@ class ExtensionStaticCacheServiceTest extends TestCase
]);
$service = $this->service();
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$templatesDir = $service->versionDir(self::VERSION).'/templates';
$this->assertDirectoryExists($templatesDir.'/sirsoft-admin_basic');
@@ -246,13 +395,13 @@ class ExtensionStaticCacheServiceTest extends TestCase
public function test_publish_is_idempotent_and_force_republishes(): void
{
$service = $this->service();
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
// 게시 후 심은 마커가 skip 재호출에서 살아남으면 재게시가 없었다는 증거
$marker = $service->versionDir(self::VERSION).'/idempotency-marker';
File::put($marker, 'x');
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$this->assertFileExists($marker);
// force 재게시는 디렉토리를 새로 만든다 → 마커 소실
@@ -281,6 +430,8 @@ class ExtensionStaticCacheServiceTest extends TestCase
$service = new ExtensionStaticCacheService(
$mock,
app(TemplateRepositoryInterface::class),
app(ModuleRepositoryInterface::class),
app(PluginRepositoryInterface::class),
app(ExtensionBundleService::class),
app(LanguagePackService::class),
);
@@ -303,7 +454,7 @@ class ExtensionStaticCacheServiceTest extends TestCase
public function test_cleanup_keeps_current_and_previous_only(): void
{
$service = $this->service();
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
// 과거 버전 3개 + 고아 tmp 시뮬레이션
foreach ([100, 200, 300] as $old) {
@@ -445,7 +596,7 @@ class ExtensionStaticCacheServiceTest extends TestCase
{
$service = $this->service();
$this->assertTrue($service->publishCurrent());
$this->assertTrue($service->publishCurrent(), $this->publishDiagnostics($service));
$htaccess = File::get($service->versionDir(self::VERSION).'/.htaccess');