fix(core): 코어 업데이트 격리 디렉토리 잔존·root 소유권·완료 안내문 수정

7.0.9 → 7.0.10 sudo 업데이트 실측 후 점검에서 드러난 3건.

- 정리 단계가 소스 경로(core_{ts}/extracted/{루트}) 안쪽만 지워 껍데기가
 업데이트마다 남던 것을 격리 디렉토리 루트째 삭제로 바꾼다. 부모는 구버전
 클래스로 돌아 다음 업데이트부터 효력이 있으므로, 신버전 코드로 도는 두 자식
 (execute-upgrade-steps / execute-bundled-updates)이 파일이 없는 core_* 만
 골라 치운다 — 구버전 부모에서 올라오는 업데이트도 껍데기 없이 끝난다.
- 항목별 소유권 스냅샷이 격리 디렉토리 생성 뒤에 찍혀 root 가 만든 추출본을
 원본으로 기록하고 복원이 다시 root 로 되돌리던 것을, 이번 실행의 격리
 디렉토리를 스냅샷에서 제외해 닫는다.
- 완료 안내문이 성공 경로에서는 동작하지 않는 hotfix:rollback-stale-files 를
 가리키던 것을 --prune 재실행 안내만 남기도록 정정한다(ko/en/ja).

부수: ExecuteUpgradeStepsStandaloneTest 가 앞선 core:update 실행이 남긴
프로세스 env 플래그에 따라 결과가 갈리던 순서 의존을 setUp/tearDown 에서 제거.
This commit is contained in:
HeuJung committed 2026-09-06 19:33:34 +09:00
1 parent 24f9df9de4
commit 033d2e6d9b
15 files changed
+527 -14

No files matched your search

@@ -30,10 +30,23 @@ class ExecuteUpgradeStepsStandaloneTest extends TestCase
{
private array $createdPaths = [];
/**
* 테스트 진입 전의 spawn 플래그 상태 (없으면 false) — tearDown 에서 되돌린다.
*/
private string|false $originalSpawnFlag = false;
protected function setUp(): void
{
parent::setUp();
// 이 클래스의 절반은 "spawn 플래그가 없는 단독 실행" 을 전제한다. 그런데 같은 프로세스에서
// 앞서 돈 테스트가 `core:update`(CoreUpdateCommand::handle) 를 한 번이라도 거치면 그 플래그가
// 프로세스 env 에 남아 여기 도착한다 — 부모 커맨드는 "프로세스 종료와 함께 소멸" 을 전제로
// 정리하지 않기 때문이다. 실행 순서에 따라 결과가 갈리지 않도록 진입 시 비우고 종료 시 되돌린다.
$this->originalSpawnFlag = getenv('G7_UPDATE_IN_PROGRESS');
putenv('G7_UPDATE_IN_PROGRESS');
unset($_ENV['G7_UPDATE_IN_PROGRESS'], $_SERVER['G7_UPDATE_IN_PROGRESS']);
// 빈 upgrade step 디렉토리 보장 — 본 테스트는 step 자체가 아닌 사전/사후 단계만 검증.
// 임시 dummy step 파일을 작성해 from < to 비교가 ">=" 조건을 통과하도록 한다.
$this->writeNoopStep('0.9.1', 'standalone_noop');
@@ -50,6 +63,15 @@ class ExecuteUpgradeStepsStandaloneTest extends TestCase
Mockery::close();
if ($this->originalSpawnFlag === false) {
putenv('G7_UPDATE_IN_PROGRESS');
unset($_ENV['G7_UPDATE_IN_PROGRESS'], $_SERVER['G7_UPDATE_IN_PROGRESS']);
} else {
putenv('G7_UPDATE_IN_PROGRESS='.$this->originalSpawnFlag);
$_ENV['G7_UPDATE_IN_PROGRESS'] = $this->originalSpawnFlag;
$_SERVER['G7_UPDATE_IN_PROGRESS'] = $this->originalSpawnFlag;
}
parent::tearDown();
}
@@ -183,6 +205,34 @@ class ExecuteUpgradeStepsStandaloneTest extends TestCase
$this->assertSame(0, $exitCode);
}
/**
* 부모(구버전 코드)의 정리 단계가 남긴 빈 격리 디렉토리(`core_{ts}/extracted` 껍데기)는
* 신버전 코드로 도는 이 자식이 치운다. spawn 자식 모드에서도, 단독 실행에서도 호출된다 —
* 구버전 부모에서 올라오는 업데이트(7.0.9→7.0.10)를 덮는 유일한 자리이기 때문이다.
*
* @effects ExecuteUpgradeStepsCommand_sweeps_empty_staging_directories_left_by_parent
*/
public function test_스텝_완료_후_빈_격리_디렉토리를_청소한다(): void
{
[$service, $module, $plugin, $template, $langPack] = $this->bindMocks();
$service->shouldReceive('runUpgradeSteps')->once();
$service->shouldReceive('sweepEmptyStagingDirectories')->once()->andReturn(1);
putenv('G7_UPDATE_IN_PROGRESS=1');
$_ENV['G7_UPDATE_IN_PROGRESS'] = '1';
$_SERVER['G7_UPDATE_IN_PROGRESS'] = '1';
try {
$exitCode = $this->runCommand([]);
} finally {
putenv('G7_UPDATE_IN_PROGRESS');
unset($_ENV['G7_UPDATE_IN_PROGRESS'], $_SERVER['G7_UPDATE_IN_PROGRESS']);
}
$this->assertSame(0, $exitCode);
}
/**
* 자식이 이전 버전 config 캐시로 부팅했으면(구버전 부모는 spawn 전에 캐시를 비우지 않는다)
* `config('app.update.restore_ownership_group_writable')` 은 옛 목록이다. 이때는 디스크의
@@ -404,6 +454,9 @@ class ExecuteUpgradeStepsStandaloneTest extends TestCase
// 종료부의 root 산출물 소유권 정상화(#615 도입)는 모든 경로에서 호출되며 본 테스트의 관심사가
// 아니다 — 기본 허용으로 두어 각 케이스가 자기 단계만 단언하게 한다.
$service->shouldReceive('normalizeRuntimeOwnershipAfterRootRun')->andReturnNull()->byDefault();
// 종료부의 빈 격리 디렉토리 청소(7.0.10 도입)도 모든 경로에서 호출된다 — 전용 케이스가
// once() 로 단언하고, 나머지 케이스는 기본 허용.
$service->shouldReceive('sweepEmptyStagingDirectories')->andReturn(0)->byDefault();
$module = Mockery::mock(ModuleManager::class);
$plugin = Mockery::mock(PluginManager::class);
$template = Mockery::mock(TemplateManager::class);
@@ -85,4 +85,36 @@ class ExecuteBundledUpdatesCommandTest extends TestCase
$this->assertStringContainsString('"success":0', $output);
$this->assertStringContainsString('"failed":0', $output);
}
/**
* 이 자식은 부모의 정리 단계가 끝난 **뒤에** 돈다. 구버전 부모(7.0.0~7.0.9)의 정리는
* 소스 경로 안쪽만 지워 `core_{ts}/extracted` 껍데기를 남기므로, 그 껍데기를 여기서
* 치워야 구버전에서 올라오는 업데이트도 잔존물 없이 끝난다. 파일이 있는 격리
* 디렉토리는 건드리지 않는다.
*
* @effects execute_bundled_updates_child_sweeps_empty_staging_directories_left_by_parent
*/
public function test_빈_매니페스트_처리_후_부모가_남긴_빈_격리_디렉토리를_치운다(): void
{
$base = storage_path('framework/testing/bundled-sweep-'.uniqid());
File::ensureDirectoryExists($base.DIRECTORY_SEPARATOR.'core_20260906_095309'.DIRECTORY_SEPARATOR.'extracted');
$live = $base.DIRECTORY_SEPARATOR.'core_20260906_120000'.DIRECTORY_SEPARATOR.'extracted';
File::ensureDirectoryExists($live);
File::put($live.DIRECTORY_SEPARATOR.'composer.json', '{}');
config(['app.update.pending_path' => $base]);
$path = storage_path('app/test_bundled_manifest_'.uniqid().'.json');
File::put($path, json_encode(['modules' => [], 'plugins' => [], 'templates' => [], 'lang_packs' => []]));
$this->tempFiles[] = $path;
try {
$exit = Artisan::call('core:execute-bundled-updates', ['--manifest' => $path]);
$this->assertSame(0, $exit);
$this->assertDirectoryDoesNotExist($base.DIRECTORY_SEPARATOR.'core_20260906_095309', '빈 껍데기는 치운다');
$this->assertFileExists($live.DIRECTORY_SEPARATOR.'composer.json', '파일이 있는 격리 디렉토리는 남긴다');
} finally {
File::deleteDirectory($base);
}
}
}
@@ -0,0 +1,230 @@
<?php
namespace Tests\Unit\Services;
use App\Services\CoreUpdateService;
use Illuminate\Support\Facades\File;
use Tests\TestCase;
/**
* 코어 업데이트 격리 디렉토리(`{pending_path}/core_{ts}`) 정리 회귀 테스트.
*
* 실사례(2026-09-06, 7.0.9 → 7.0.10 sudo 업데이트): ZIP 추출은 `core_{ts}/extracted/{루트}/`
* 를 소스로 돌려주는데 정리 단계가 그 안쪽만 지워 `core_{ts}/extracted/` 껍데기가 남았고,
* 스냅샷이 그 껍데기를 root 소유로 기록해 복원이 root 로 되돌렸다. 같은 껍데기가
* 7.0.0 부터의 설치본마다 하나씩 남아 있었다.
*
* 세 층을 잠근다:
* 1. cleanupPending 이 소스 경로를 받아도 격리 디렉토리 루트를 지운다 (부모 정리)
* 2. 자식이 부르는 sweep 이 빈 껍데기만 치우고 파일이 있는 격리 디렉토리는 남긴다
* 3. 스냅샷이 이번 실행의 격리 디렉토리를 제외한다 (잔존물이 root 로 되돌아가지 않는다)
*/
class CoreUpdateServiceStagingCleanupTest extends TestCase
{
private string $base;
private string $outside;
private CoreUpdateService $service;
protected function setUp(): void
{
parent::setUp();
$this->base = storage_path('framework/testing/staging-cleanup-'.uniqid());
$this->outside = storage_path('framework/testing/staging-outside-'.uniqid());
File::ensureDirectoryExists($this->base);
File::ensureDirectoryExists($this->outside);
config(['app.update.pending_path' => $this->base]);
$this->service = app(CoreUpdateService::class);
}
protected function tearDown(): void
{
File::deleteDirectory($this->base);
File::deleteDirectory($this->outside);
parent::tearDown();
}
// ── 1. 격리 디렉토리 루트 해석 + 정리 ─────────────────────────────────
public function test_resolve_staging_root_은_안쪽_소스_경로에서_격리_디렉토리_루트를_돌려준다(): void
{
$inner = $this->base.DIRECTORY_SEPARATOR.'core_20260906_095309'
.DIRECTORY_SEPARATOR.'extracted'.DIRECTORY_SEPARATOR.'dev-g7-develop';
$this->assertSame(
$this->base.DIRECTORY_SEPARATOR.'core_20260906_095309',
$this->service->resolveStagingRoot($inner),
);
$this->assertSame(
$this->base.DIRECTORY_SEPARATOR.'core_20260906_095309',
$this->service->resolveStagingRoot($this->base.DIRECTORY_SEPARATOR.'core_20260906_095309'),
'격리 디렉토리 자체를 넘기면 그대로',
);
}
public function test_resolve_staging_root_은_pending_기준_밖_경로와_기준_자체는_건드리지_않는다(): void
{
$external = $this->outside.DIRECTORY_SEPARATOR.'src';
$this->assertSame($external, $this->service->resolveStagingRoot($external), '--source 외부 경로는 위로 올라가지 않는다');
$this->assertSame($this->base, $this->service->resolveStagingRoot($this->base), 'pending 기준 디렉토리 자체는 그대로');
$this->assertSame($this->base.DIRECTORY_SEPARATOR.'..', $this->service->resolveStagingRoot($this->base.DIRECTORY_SEPARATOR.'..'));
}
/**
* @effects cleanupPending_removes_whole_staging_root_when_given_inner_source_path
*/
public function test_cleanup_pending_은_소스_경로를_받아도_격리_디렉토리를_통째로_지운다(): void
{
$staging = $this->base.DIRECTORY_SEPARATOR.'core_20260906_095309';
$source = $staging.DIRECTORY_SEPARATOR.'extracted'.DIRECTORY_SEPARATOR.'dev-g7-develop';
File::ensureDirectoryExists($source.DIRECTORY_SEPARATOR.'app');
File::put($source.DIRECTORY_SEPARATOR.'composer.json', '{}');
File::put($staging.DIRECTORY_SEPARATOR.'core_update.zip', 'zip');
$this->service->cleanupPending($source);
$this->assertDirectoryDoesNotExist($staging, '껍데기(extracted)까지 남지 않아야 한다');
$this->assertDirectoryExists($this->base, 'pending 기준 디렉토리는 남는다');
}
public function test_cleanup_pending_은_pending_기준_밖_경로를_넘기면_그_경로만_지운다(): void
{
$external = $this->outside.DIRECTORY_SEPARATOR.'src';
File::ensureDirectoryExists($external);
File::put($external.DIRECTORY_SEPARATOR.'a.txt', 'a');
File::put($this->outside.DIRECTORY_SEPARATOR.'keep.txt', 'keep');
$this->service->cleanupPending($external);
$this->assertDirectoryDoesNotExist($external);
$this->assertFileExists($this->outside.DIRECTORY_SEPARATOR.'keep.txt', '형제 항목이 남아야 한다 — 위로 올라가 지우지 않는다');
}
// ── 2. 자식 청소 ────────────────────────────────────────────────────────
/**
* @effects sweepEmptyStagingDirectories_removes_empty_core_dirs_and_keeps_dirs_with_files
*/
public function test_sweep_은_빈_격리_디렉토리만_치우고_파일이_있는_것과_core_외_디렉토리는_남긴다(): void
{
$empty = $this->base.DIRECTORY_SEPARATOR.'core_20260713_065730';
File::ensureDirectoryExists($empty.DIRECTORY_SEPARATOR.'extracted');
$emptyDeep = $this->base.DIRECTORY_SEPARATOR.'core_20260710_111102';
File::ensureDirectoryExists($emptyDeep.DIRECTORY_SEPARATOR.'extracted'.DIRECTORY_SEPARATOR.'nested');
$live = $this->base.DIRECTORY_SEPARATOR.'core_20260906_120000';
File::ensureDirectoryExists($live.DIRECTORY_SEPARATOR.'extracted'.DIRECTORY_SEPARATOR.'root');
File::put($live.DIRECTORY_SEPARATOR.'extracted'.DIRECTORY_SEPARATOR.'root'.DIRECTORY_SEPARATOR.'composer.json', '{}');
$foreign = $this->base.DIRECTORY_SEPARATOR.'local_source';
File::ensureDirectoryExists($foreign);
File::put($this->base.DIRECTORY_SEPARATOR.'bundled-updates-manifest_x.json', '{}');
$swept = $this->service->sweepEmptyStagingDirectories();
$this->assertSame(2, $swept);
$this->assertDirectoryDoesNotExist($empty);
$this->assertDirectoryDoesNotExist($emptyDeep);
$this->assertFileExists($live.DIRECTORY_SEPARATOR.'extracted'.DIRECTORY_SEPARATOR.'root'.DIRECTORY_SEPARATOR.'composer.json', '부모가 쓰는 중인 격리 디렉토리는 남는다');
$this->assertDirectoryExists($foreign, 'core_ 접두사가 아닌 디렉토리는 대상이 아니다');
$this->assertFileExists($this->base.DIRECTORY_SEPARATOR.'bundled-updates-manifest_x.json');
}
public function test_sweep_은_pending_기준_디렉토리가_없으면_0_을_돌려준다(): void
{
config(['app.update.pending_path' => $this->base.DIRECTORY_SEPARATOR.'missing']);
$this->assertSame(0, $this->service->sweepEmptyStagingDirectories());
}
// ── 3. 스냅샷 제외 ──────────────────────────────────────────────────────
/**
* @effects snapshotOwnershipDetailed_excludes_current_run_staging_root
*/
public function test_snapshot_detailed_은_제외_경로와_그_하위를_기록하지_않는다(): void
{
$staging = $this->base.DIRECTORY_SEPARATOR.'core_20260906_095309';
File::ensureDirectoryExists($staging.DIRECTORY_SEPARATOR.'extracted');
File::put($staging.DIRECTORY_SEPARATOR.'extracted'.DIRECTORY_SEPARATOR.'composer.json', '{}');
$older = $this->base.DIRECTORY_SEPARATOR.'core_20260713_065730';
File::ensureDirectoryExists($older);
File::put($this->base.DIRECTORY_SEPARATOR.'.gitignore', '*');
$snapshot = $this->service->snapshotOwnershipDetailed([$this->base], excludes: [$staging]);
$keys = array_map(static fn (string $k): string => str_replace('\\', '/', $k), array_keys($snapshot));
$stagingNorm = str_replace('\\', '/', $staging);
$this->assertNotEmpty($snapshot, '기준 디렉토리·형제 항목은 기록된다');
$this->assertContains(str_replace('\\', '/', $older), $keys);
$this->assertContains(str_replace('\\', '/', $this->base.DIRECTORY_SEPARATOR.'.gitignore'), $keys);
foreach ($keys as $key) {
$this->assertFalse(
$key === $stagingNorm || str_starts_with($key, $stagingNorm.'/'),
"제외 경로 하위가 스냅샷에 실렸다: {$key}",
);
}
$without = $this->service->snapshotOwnershipDetailed([$this->base]);
$this->assertGreaterThan(count($snapshot), count($without), '제외 인자를 빼면 격리 디렉토리가 기록된다 (되돌리면 red)');
}
public function test_부모_커맨드는_이번_실행의_격리_디렉토리를_스냅샷에서_제외한다(): void
{
$src = File::get(base_path('app/Console/Commands/Core/CoreUpdateCommand.php'));
$this->assertMatchesRegularExpression(
'/snapshotOwnershipDetailed\(\[[^\]]*\'storage\/app\/core_pending\'[^\]]*\],\s*excludes:\s*\[\$service->resolveStagingRoot\(\$pendingPath\)\]\)/s',
$src,
'CoreUpdateCommand 의 스냅샷 호출이 격리 디렉토리 루트를 excludes 로 넘겨야 한다',
);
}
public function test_자식_두_커맨드가_모두_빈_격리_디렉토리_청소를_부른다(): void
{
foreach ([
'app/Console/Commands/Core/ExecuteUpgradeStepsCommand.php',
'app/Console/Commands/Core/ExecuteBundledUpdatesCommand.php',
] as $rel) {
$this->assertStringContainsString(
'sweepEmptyStagingDirectories()',
File::get(base_path($rel)),
"{$rel} 가 sweepEmptyStagingDirectories() 를 호출해야 한다 — 구버전 부모에서 올라오는 업데이트를 덮는 자리",
);
}
}
// ── 완료 안내문 ─────────────────────────────────────────────────────────
/**
* @effects apply_mode_incremental_prune_hint_does_not_reference_rollback_command
*/
public function test_완료_안내문은_성공_후_동작하지_않는_명령을_가리키지_않는다(): void
{
$files = [
'lang/ko/settings.php',
'lang/en/settings.php',
'lang-packs/_bundled/g7-core-ja/backend/ja/settings.php',
];
foreach ($files as $rel) {
$lang = require base_path($rel);
$hint = $lang['core_update']['apply_mode_incremental_prune_hint'] ?? null;
$this->assertIsString($hint, "{$rel} 에 안내문 키가 있어야 한다");
$this->assertStringContainsString('--prune', $hint, "{$rel}: --prune 재실행 안내는 남긴다");
$this->assertStringNotContainsString(
'hotfix:rollback-stale-files',
$hint,
"{$rel}: 성공 경로는 백업(manifest 포함)을 지우므로 이 명령은 '백업 없음' 으로 끝난다",
);
}
}
}
@@ -86,6 +86,7 @@ effects:
- ExecuteUpgradeStepsCommand_env_guard_dominates_over_force_flag_for_post_steps
- ExecuteUpgradeStepsCommand_standalone_invocation_without_env_runs_all_five_steps_intact
- execute_upgrade_steps_child_reads_update_config_from_disk_when_config_is_cached
- ExecuteUpgradeStepsCommand_sweeps_empty_staging_directories_left_by_parent
test_files:
- tests/Feature/Console/Commands/ExecuteUpgradeStepsStandaloneTest.php
@@ -49,6 +49,8 @@ axes:
upgrade_step_v_one_pattern: [app_service_call, app_manager_call, app_repository_call, local_only]
audit_allow_inline: [present, absent] # 면제 주석 적용 여부
symlink_target_state: [valid, broken, windows_no_privilege] # symlink 보존 분기 (§1 연동)
staging_source_shape: [inner_extracted_root, staging_root_itself, external_source_dir] # cleanupPending 이 받는 경로 형태 — ZIP·GitHub / --local·--source 복제 / --source 외부
staging_leftover_content: [empty_skeleton, has_files, non_core_dir] # 자식 청소 술어 — 빈 껍데기만 대상
resume_exec_context: [non_root, root_web_known, root_web_symmetric, root_web_unknown] # 핸드오프 재실행 권한 안내 분기 (실행 사용자 × 웹서버 계정 식별성)
exclusions:
@@ -105,6 +107,12 @@ effects:
- renderResumeGuidance_root_web_known_prefixes_sudo_u_and_warns_with_account_name
- renderResumeGuidance_root_web_symmetric_prints_command_verbatim
- renderResumeGuidance_root_web_unknown_uses_placeholder_and_generic_warning
# §9 격리 디렉토리 정리 3층 (부모 루트째 삭제 / 자식 빈 껍데기 청소 / 스냅샷 제외) + 완료 안내문
- cleanupPending_removes_whole_staging_root_when_given_inner_source_path
- sweepEmptyStagingDirectories_removes_empty_core_dirs_and_keeps_dirs_with_files
- snapshotOwnershipDetailed_excludes_current_run_staging_root
- execute_bundled_updates_child_sweeps_empty_staging_directories_left_by_parent
- apply_mode_incremental_prune_hint_does_not_reference_rollback_command
test_files:
- tests/Feature/Console/CoreUpdateCommandSpawnFailureTest.php
@@ -115,6 +123,8 @@ test_files:
- tests/Feature/Console/CoreUpdateResumeGuidanceTest.php
- tests/Feature/Upgrades/MultiVersionUpgradePathTest.php
- tests/Unit/Extension/Helpers/FilePermissionHelperSymlinkTest.php
- tests/Unit/Services/CoreUpdateServiceStagingCleanupTest.php
- tests/Feature/Console/ExecuteBundledUpdatesCommandTest.php
# 본 매니페스트의 axes cross product 는 800+ 케이스이나, 실제 회귀 가드는 test_files 의
# 통과 테스트들이 SSoT — 매니페스트는 매트릭스 SSoT 역할.