fix(core,admin_basic): 정적 게시 재게시 누락 3건 수정 + 관리자 수동 복구 UI + sudo core:update 소유권 정합

- 템플릿 update 는 레이아웃 변경 여부와 무관하게 캐시 버전을 올리고(실패 복원 뒤에도), 자산 주소 방식 전환 3경로도 bump 한다
- config:cache 가 컨테이너 인스턴스를 덮어 이후 terminating 재게시가 사라지던 결함을 복원 헬퍼로 차단
- custom/ 변경 감지와 게시가 같은 열거자(재귀·크기 포함)를 쓰고, 서명은 호스트별로 저장
- 캐시 버전·서명 키를 만료시키지 않는다(기본 TTL 24h 로 매일 전체 재생성되던 문제)
- 관리자 > 환경설정 > 일반 「초기 화면 정적 파일」 카드: 상태 조회 + 지금 다시 만들기(확인 모달), 대시보드 알림 버튼 연결, CLI 와 같은 statusReport 소비
- sudo core:update 경로의 root 소유 잔존(설정 디렉토리·임시 폴더·로그·업그레이드 마이그레이션 산출물) 상속·정합화, ext-static 명령 root 경고와 sudo -u 힌트
- 안내·문서·트러블슈팅 4건·audit 룰 ext-cache-version-raw-read·ja 언어팩 동기
This commit is contained in:
HeuJung committed 2026-09-06 15:22:52 +09:00
1 parent d263f74cae
commit de18159986
105 files changed
+4055 -208

No files matched your search

@@ -28,6 +28,32 @@ class CoreUpdateRuntimeOwnershipTest extends TestCase
$this->assertTrue(true);
}
/**
* 정상화 타깃에 확장 업데이트 임시 폴더와 로그 디렉토리가 포함된다 (#651 B5).
*
* `storage/app/temp` 의 부모는 sudo 업데이트가 최초 생성자가 되면 root 로 굳어 이후 관리자 화면의
* 확장 업데이트가 임시 폴더를 만들지 못하고, `storage/logs` 는 restore_ownership 복원(Step 11)
* 뒤에 만들어지는 daily 롤오버·신규 로그 파일이 root 로 남는다.
*
* @effects runtime_ownership_targets_cover_temp_and_logs
*/
public function test_runtime_ownership_targets_include_temp_and_logs(): void
{
$method = new \ReflectionMethod(CoreUpdateService::class, 'normalizeRuntimeOwnershipAfterRootRun');
$lines = file($method->getFileName()) ?: [];
$body = implode('', array_slice($lines, $method->getStartLine() - 1, $method->getEndLine() - $method->getStartLine() + 1));
foreach ([
"storage_path('framework/cache')",
"base_path('bootstrap/cache')",
"storage_path('app/ext-bundles')",
"storage_path('app/temp')",
"storage_path('logs')",
] as $target) {
$this->assertStringContainsString($target, $body, "런타임 소유권 정상화 타깃에 {$target} 이 없다");
}
}
/**
* 부모(CoreUpdateCommand)·자식(ExecuteUpgradeStepsCommand) 흐름 종료부가
* 정상화를 호출한다 — 로그 소유권 정상화(restoreUpgradeLogOwnership)와
@@ -0,0 +1,88 @@
<?php
namespace Tests\Unit\Services;
use App\Exceptions\CustomAssetOperationException;
use App\Services\CustomAssetService;
use Illuminate\Support\Facades\File;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
/**
* `custom/` 디렉토리 생성 실패 안내 테스트 (#651 D6·C2).
*
* `custom/` 은 지연 생성이라 `deploy:deploy 0755` 로 배포된 확장 디렉토리에서 운영자의 첫 저장이
* 여기서 실패한다. 종전 문구는 경로만 적어 무엇을 고쳐야 하는지 알 수 없었다 — 사유·소유자·권한·
* 실행 계정·조치 예시를 함께 싣는다(정적 게시 프리플라이트와 같은 식).
*/
class CustomAssetServiceDirectoryFailureTest extends TestCase
{
/** 테스트용 가짜 플러그인 식별자 */
private const FAKE_PLUGIN = 'g7test-dirfail';
protected function tearDown(): void
{
File::deleteDirectory(base_path('plugins/'.self::FAKE_PLUGIN));
parent::tearDown();
}
/**
* 같은 이름의 **파일**이 `custom/` 자리를 차지하면 사유·조치가 실린 메시지로 실패한다.
*
* (POSIX 권한 거부는 Windows 에서 재현할 수 없어 파일 점유 사유로 실패 경로를 태운다 — 사유 코드는
* 공통 프리미티브가 돌려주므로 매핑 경로는 같다.)
*
* @scenario custom_source=convention_scan, custom_asset=css
*
* @effects custom_directory_failure_explains_reason_and_action
*/
#[Test]
public function 디렉토리_생성_실패는_사유와_조치를_함께_알린다(): void
{
$pluginDir = base_path('plugins/'.self::FAKE_PLUGIN);
File::ensureDirectoryExists($pluginDir);
// `custom` 자리를 파일로 점유 — mkdir 이 실패하는 결정적 조건
File::put($pluginDir.'/custom', 'not a directory');
try {
app(CustomAssetService::class)->save('plugins', self::FAKE_PLUGIN, 'custom.css', '/* x */');
$this->fail('디렉토리를 만들 수 없는데 예외가 나지 않았다');
} catch (CustomAssetOperationException $e) {
$this->assertSame('custom_assets.errors.directory_failed', $e->errorKey);
foreach (['path', 'reason', 'owner', 'perms', 'process_user', 'hint'] as $param) {
$this->assertArrayHasKey($param, $e->params, "실패 메시지 파라미터 {$param} 이 없다");
}
// 사유 코드가 번역된 문장으로 실려야 한다 (키 노출 금지)
$this->assertStringNotContainsString('custom_assets.', (string) $e->params['reason']);
$this->assertStringNotContainsString('custom_assets.', (string) $e->params['hint']);
$this->assertStringContainsString('chown', (string) $e->params['hint']);
// 최종 문장에 치환 자리가 남아 있지 않다
$this->assertStringNotContainsString(':reason', $e->getMessage());
$this->assertStringNotContainsString(':hint', $e->getMessage());
}
}
/**
* 사유 코드 4종은 ko/en 양쪽에 번역이 있다 — 없는 코드는 키 문자열이 화면에 나간다.
*
* @effects custom_directory_failure_explains_reason_and_action
*/
#[Test]
public function 사유_코드_4종은_양_로케일에_번역이_있다(): void
{
foreach (['ko', 'en'] as $locale) {
$messages = require base_path("lang/{$locale}/custom_assets.php");
foreach (['occupied_by_file', 'ancestor_not_writable', 'create_failed', 'not_writable'] as $code) {
$this->assertNotEmpty($messages['errors']['reason'][$code] ?? null, "{$locale}: reason.{$code} 번역이 없다");
}
$this->assertNotEmpty($messages['errors']['directory_failed_hint'] ?? null, "{$locale}: directory_failed_hint 가 없다");
$this->assertStringContainsString(':hint', $messages['errors']['directory_failed']);
}
}
}
@@ -5,9 +5,11 @@ namespace Tests\Unit\Services;
use App\Contracts\Extension\CacheInterface;
use App\Contracts\Repositories\AttachmentRepositoryInterface;
use App\Contracts\Repositories\ConfigRepositoryInterface;
use App\Extension\Traits\ClearsTemplateCaches;
use App\Seo\Contracts\SeoCacheManagerInterface;
use App\Services\SettingsService;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Tests\TestCase;
/**
@@ -144,6 +146,140 @@ class SettingsServiceSetSettingSideEffectsTest extends TestCase
$this->assertFalse($service->setSetting('drivers.queue_driver', 'redis'));
}
/**
* 자산 URL 방식을 단건으로 바꾸면 확장 캐시 버전이 오른다 — 실제 키 관측 (#651 F5).
*
* 병합 번들 CSS 에는 그 시점의 자산 URL 형태(확장자 / `?file=`)가 구워져 있고, 디스크 번들과
* 정적 게시본은 캐시 버전으로 키드된다. 버전이 오르지 않으면 모드를 바꿔도 옛 형태의
* `url()` 이 남아 글꼴·이미지가 404 가 된다.
*
* @effects asset_url_mode_change_bumps_extension_cache_version
*/
public function test_asset_url_mode_change_bumps_extension_cache_version(): void
{
$this->mock(SeoCacheManagerInterface::class)->shouldIgnoreMissing();
Artisan::shouldReceive('call')->zeroOrMoreTimes();
ClearsTemplateCaches::resetExtensionCacheStoreMemo();
Cache::put('g7:core:ext.cache_version', 1000);
$service = $this->makeService(existingValue: 'extensionless');
$this->assertTrue($service->setSetting('general.asset_url_mode', 'extension'));
$this->assertGreaterThan(
1000,
(int) Cache::get('g7:core:ext.cache_version'),
'자산 URL 방식 단건 변경이 확장 캐시 버전을 올리지 않았다 — 번들 CSS 의 옛 url() 형태가 남는다.'
);
}
/**
* 값이 그대로면 확장 캐시 버전도 그대로다.
*
* @effects asset_url_mode_change_bumps_extension_cache_version
*/
public function test_same_asset_url_mode_keeps_extension_cache_version(): void
{
$this->mock(SeoCacheManagerInterface::class)->shouldIgnoreMissing();
Artisan::shouldReceive('call')->zeroOrMoreTimes();
ClearsTemplateCaches::resetExtensionCacheStoreMemo();
Cache::put('g7:core:ext.cache_version', 1000);
$service = $this->makeService(existingValue: 'extension');
$this->assertTrue($service->setSetting('general.asset_url_mode', 'extension'));
$this->assertSame(1000, (int) Cache::get('g7:core:ext.cache_version'));
}
/**
* 벌크 저장(saveSettings) 경로도 같은 부수효과를 갖는다 — 화면 [저장] 버튼이 타는 경로다.
*
* @effects asset_url_mode_change_bumps_extension_cache_version
*/
public function test_bulk_save_asset_url_mode_change_bumps_extension_cache_version(): void
{
$this->mock(SeoCacheManagerInterface::class)->shouldIgnoreMissing();
Artisan::shouldReceive('call')->zeroOrMoreTimes();
$existing = ['asset_url_mode' => 'extensionless'];
$configRepository = $this->mock(ConfigRepositoryInterface::class)->shouldIgnoreMissing();
$configRepository->shouldReceive('getCategory')->with('general')->andReturnUsing(function () use (&$existing): array {
return $existing;
});
$configRepository->shouldReceive('saveCategory')->andReturn(true);
$this->mock(AttachmentRepositoryInterface::class)->shouldIgnoreMissing();
$this->mock(CacheInterface::class)->shouldIgnoreMissing();
ClearsTemplateCaches::resetExtensionCacheStoreMemo();
Cache::put('g7:core:ext.cache_version', 1000);
$service = app(SettingsService::class);
$this->assertTrue($service->saveSettings(['_tab' => 'general', 'general' => ['asset_url_mode' => 'extension']]));
$this->assertGreaterThan(1000, (int) Cache::get('g7:core:ext.cache_version'));
// 같은 값 재저장은 올리지 않는다
Cache::put('g7:core:ext.cache_version', 2000);
$existing = ['asset_url_mode' => 'extension'];
$this->assertTrue($service->saveSettings(['_tab' => 'general', 'general' => ['asset_url_mode' => 'extension']]));
$this->assertSame(2000, (int) Cache::get('g7:core:ext.cache_version'));
}
/**
* 설정 복원으로 자산 URL 방식이 바뀌면 SEO 캐시 삭제 + 확장 캐시 버전 bump 가 따른다.
*
* 복원은 설정 전체를 갈아엎는 쓰기라 두 저장 경로와 같은 부수효과를 받아야 한다 —
* 종전에는 변경 감지 자체가 없었다.
*
* @effects asset_url_mode_change_bumps_extension_cache_version
*/
public function test_restore_asset_url_mode_change_bumps_extension_cache_version(): void
{
$this->mock(SeoCacheManagerInterface::class)->shouldReceive('clearAll')->once();
Artisan::shouldReceive('call')->zeroOrMoreTimes();
$configRepository = $this->mock(ConfigRepositoryInterface::class)->shouldIgnoreMissing();
// 복원 전 / 복원 후 순서대로 읽힌다
$configRepository->shouldReceive('get')->with('general.asset_url_mode')->andReturn('extensionless', 'extension');
$configRepository->shouldReceive('restore')->andReturn(true);
$this->mock(AttachmentRepositoryInterface::class)->shouldIgnoreMissing();
$this->mock(CacheInterface::class)->shouldIgnoreMissing();
ClearsTemplateCaches::resetExtensionCacheStoreMemo();
Cache::put('g7:core:ext.cache_version', 1000);
$service = app(SettingsService::class);
$this->assertTrue($service->restoreSettings('/tmp/backup.json'));
$this->assertGreaterThan(1000, (int) Cache::get('g7:core:ext.cache_version'));
}
/**
* 복원 전후 값이 같으면 두 부수효과 모두 없다.
*
* @effects asset_url_mode_change_bumps_extension_cache_version
*/
public function test_restore_with_same_asset_url_mode_has_no_side_effects(): void
{
$this->mock(SeoCacheManagerInterface::class)->shouldReceive('clearAll')->never();
Artisan::shouldReceive('call')->zeroOrMoreTimes();
$configRepository = $this->mock(ConfigRepositoryInterface::class)->shouldIgnoreMissing();
$configRepository->shouldReceive('get')->with('general.asset_url_mode')->andReturn('extensionless');
$configRepository->shouldReceive('restore')->andReturn(true);
$this->mock(AttachmentRepositoryInterface::class)->shouldIgnoreMissing();
$this->mock(CacheInterface::class)->shouldIgnoreMissing();
ClearsTemplateCaches::resetExtensionCacheStoreMemo();
Cache::put('g7:core:ext.cache_version', 1000);
$service = app(SettingsService::class);
$this->assertTrue($service->restoreSettings('/tmp/backup.json'));
$this->assertSame(1000, (int) Cache::get('g7:core:ext.cache_version'));
}
/**
* 단건 저장은 받은 키를 변형 없이 저장소에 넘긴다. (벌크 위임 금지 — 계약 고정)
*