fix(core): 코어 업데이트가 특정 상황에서 중단되던 두 결함 수정
Windows JUNCTION 복사 실패: - public/storage 는 storage:link 가 Windows 에서 생성하는 JUNCTION 으로, PHP is_link/is_dir 이 모두 false 를 반환해 copyDirectory 가 파일로 오판 → copy(디렉토리) 예외로 코어 업데이트가 중단됐다. - isReparsePoint 로 junction 을 정확 감지(link/file/dir 모두 false + readlink 성공)하고, copyLink 가 symlink 실패 시 mklink /J 로 폴백 복원. removeOrphanItems 도 junction orphan 을 rmdir 로 링크만 제거해 target 재귀 삭제 사고를 차단. 실행할 스텝이 없는 업데이트를 실패로 오판: - spawn 자식이 exit=0 + step 0건으로 종료하면 부모 가드가 from<to 만으로 fail-fast 를 발동해, 스텝이 필요 없는 패치 릴리즈(예: 7.0.0→7.0.1)를 실패로 처리하고 확장 업데이트 단계까지 도달하지 못했다. - [STEPS_EXECUTED] 신호에 discovered(범위 내 발견된 스텝 파일 수)를 추가하고, handleSpawnExit 가 executed=0 && discovered=0 은 정상 통과, discovered>0 일 때만 fail-fast 하도록 구분. 구버전 자식(discovered 부재)은 레거시 판정 유지. 정상 통과 시 확장 일괄 업데이트 단계까지 진행된다. 테스트: FilePermissionHelperSymlinkTest / CoreUpdateCommandSpawnFailureTest / CoreUpdateCommandHandoffTest / MultiVersionUpgradePathTest 전부 green.
This commit is contained in:
1 parent
68d2a68062
commit
27901dd254
8 files changed
+371
-50
No files matched your search
@@ -96,31 +96,107 @@ class CoreUpdateCommandSpawnFailureTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function spawn_자식_silent_skip_시_abort_모드는_throw_한다(): void
|
||||
public function spawn_자식_범위내_스텝_파일이_없어_0건이면_정상_통과한다(): void
|
||||
{
|
||||
if (! function_exists('proc_open')) {
|
||||
$this->markTestSkipped('proc_open 미지원 환경');
|
||||
}
|
||||
|
||||
// upgrade 파일 없이 호출 → 자식은 [STEPS_EXECUTED] count=0 발행 + exit=0
|
||||
// from < to 인 상태에서 0건 실행은 비정상 → mode=abort 시 throw
|
||||
// upgrade 파일 없이 호출 → 자식은 [STEPS_EXECUTED] executed=0, discovered=0 발행 + exit=0
|
||||
// "범위 내 스텝 파일 자체가 없음" 은 정상 상황 (예: 스텝 불필요 릴리즈).
|
||||
// discovered=0 이면 fail-fast 를 발동하지 않고 정상 통과해야 한다 (케이스 B).
|
||||
config(['app.update.spawn_failure_mode' => 'abort']);
|
||||
|
||||
$command = $this->makeCommandWithDummyIo();
|
||||
$method = new \ReflectionMethod(CoreUpdateCommand::class, 'spawnUpgradeStepsProcess');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$logs = [];
|
||||
$log = function (string $msg) use (&$logs): void {
|
||||
$logs[] = $msg;
|
||||
};
|
||||
|
||||
// 실 스텝 파일이 존재하지 않는 버전 범위 (9.9.8 → 9.9.9)
|
||||
$result = $method->invoke($command, '9.9.8', '9.9.9', true, $log);
|
||||
|
||||
$this->assertTrue($result, '범위 내 스텝 파일이 없어 0건이면 정상 통과(true)여야 한다');
|
||||
$allLogs = implode("\n", $logs);
|
||||
$this->assertStringContainsString('실행할 스텝 없음', $allLogs, '스텝 부재 정상 통과 로그');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function spawn_자식_범위내_스텝이_있는데_0건_실행이면_abort_throw_한다(): void
|
||||
{
|
||||
// 범위 내에 스텝 파일이 실제로 존재(discovered>0)하는데 executed=0 인 경우 —
|
||||
// 이전 버전 자식이 신규 스텝을 놓치고 silent skip 한 이슈 #28 케이스 (케이스 A).
|
||||
// 이 경우에만 fail-fast 를 발동해야 한다.
|
||||
//
|
||||
// 재현: 스텝 파일은 존재하나 자식의 runUpgradeSteps 가 executed 를 0 으로 보고하도록,
|
||||
// discovered 는 세되 onStep 은 호출하지 않는 상황을 자식 프로세스 안에서 만들 수 없으므로,
|
||||
// 부모 가드 로직(handleSpawnExit)을 직접 호출해 discovered>0 && executed=0 분기를 검증한다.
|
||||
config(['app.update.spawn_failure_mode' => 'abort']);
|
||||
|
||||
$command = $this->makeCommandWithDummyIo();
|
||||
$method = new \ReflectionMethod(CoreUpdateCommand::class, 'handleSpawnExit');
|
||||
$method->setAccessible(true);
|
||||
|
||||
try {
|
||||
$method->invoke($command, '9.9.8', '9.9.9', true, fn () => null);
|
||||
$this->fail('step 0건 실행 시 mode=abort 에서 throw 되어야 한다');
|
||||
// exitCode=0, handoffPayload=null, stepsExecuted=0, stepsDiscovered=5
|
||||
$method->invoke($command, 0, null, 0, 5, '9.9.8', '9.9.9', fn () => null);
|
||||
$this->fail('discovered>0 && executed=0 이면 mode=abort 에서 throw 되어야 한다');
|
||||
} catch (UpgradeHandoffException $e) {
|
||||
$this->assertStringContainsString('step 0건 실행', $e->reason);
|
||||
$this->assertStringContainsString('발견 5건', $e->reason);
|
||||
$this->assertSame('9.9.8', $e->afterVersion);
|
||||
}
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function spawn_자식_silent_skip_시_fallback_모드는_false_반환한다(): void
|
||||
public function handleSpawnExit_executed_0_discovered_0_이면_from_lt_to_여도_정상_통과한다(): void
|
||||
{
|
||||
// 케이스 B — 범위 내 스텝 파일 부재. from<to 여도 실패 아님 (스텝 불필요 릴리즈).
|
||||
// proc_open 불필요한 순수 판정 로직 단위 검증.
|
||||
config(['app.update.spawn_failure_mode' => 'abort']);
|
||||
|
||||
$command = $this->makeCommandWithDummyIo();
|
||||
$method = new \ReflectionMethod(CoreUpdateCommand::class, 'handleSpawnExit');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$logs = [];
|
||||
$log = function (string $msg) use (&$logs): void {
|
||||
$logs[] = $msg;
|
||||
};
|
||||
|
||||
// exitCode=0, handoffPayload=null, stepsExecuted=0, stepsDiscovered=0
|
||||
$result = $method->invoke($command, 0, null, 0, 0, '7.0.0', '7.0.1', $log);
|
||||
|
||||
$this->assertTrue($result, 'discovered=0 이면 abort 모드에서도 정상 통과(true)');
|
||||
$this->assertStringContainsString('실행할 스텝 없음', implode("\n", $logs));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function handleSpawnExit_구버전_자식_discovered_null_은_레거시_fail_fast_판정을_유지한다(): void
|
||||
{
|
||||
// discovered 필드를 모르는 구버전 자식 — executed=0 + discovered=null + from<to.
|
||||
// 신버전 부모는 이 케이스를 기존(레거시) fail-fast 로 판정해야 한다 (안전 우선).
|
||||
config(['app.update.spawn_failure_mode' => 'abort']);
|
||||
|
||||
$command = $this->makeCommandWithDummyIo();
|
||||
$method = new \ReflectionMethod(CoreUpdateCommand::class, 'handleSpawnExit');
|
||||
$method->setAccessible(true);
|
||||
|
||||
try {
|
||||
// stepsExecuted=0, stepsDiscovered=null (구버전 자식)
|
||||
$method->invoke($command, 0, null, 0, null, '7.0.0', '7.0.1', fn () => null);
|
||||
$this->fail('discovered=null + executed=0 + from<to 는 레거시 fail-fast 여야 한다');
|
||||
} catch (UpgradeHandoffException $e) {
|
||||
$this->assertStringContainsString('step 0건 실행', $e->reason);
|
||||
$this->assertStringNotContainsString('발견', $e->reason, 'discovered 미상이므로 발견 건수 표기 없음');
|
||||
}
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function spawn_자식_범위내_스텝_파일이_없어_0건이면_fallback_모드도_정상_통과한다(): void
|
||||
{
|
||||
if (! function_exists('proc_open')) {
|
||||
$this->markTestSkipped('proc_open 미지원 환경');
|
||||
@@ -134,7 +210,7 @@ class CoreUpdateCommandSpawnFailureTest extends TestCase
|
||||
|
||||
$result = $method->invoke($command, '9.9.8', '9.9.9', true, fn () => null);
|
||||
|
||||
$this->assertFalse($result, 'mode=fallback 에서 step 0건 실행은 false 반환');
|
||||
$this->assertTrue($result, '스텝 파일 부재(discovered=0)는 fallback 모드에서도 정상 통과(true)');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
|
||||
@@ -134,4 +134,78 @@ class FilePermissionHelperSymlinkTest extends TestCase
|
||||
$this->assertSame('hi', File::get($dest.'/file.txt'));
|
||||
$this->assertSame('world', File::get($dest.'/sub/nested.txt'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows JUNCTION (`mklink /J`) 는 PHP 의 `SplFileInfo::isLink()` / `isDir()` 이
|
||||
* 모두 false 를 반환하는 reparse point 다. `php artisan storage:link` 가 Windows 에서
|
||||
* 생성하는 `public/storage` 가 이 형태이며, 이를 파일로 오판하면 `copyFile` 이
|
||||
* 디렉토리를 `copy()` 에 넘겨 `copy(): The first argument ... cannot be a directory` 로
|
||||
* 코어 업데이트가 실패한다 (회귀 가드).
|
||||
*
|
||||
* junction 은 Windows 전용이므로 비-Windows 환경에서는 skip.
|
||||
*/
|
||||
#[Test]
|
||||
public function copyDirectory_는_windows_junction_을_파일로_오판하지_않고_보존합니다(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$this->markTestSkipped('junction 은 Windows 전용 (mklink /J)');
|
||||
}
|
||||
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
$linkTarget = $this->tempRoot.'/link_target';
|
||||
|
||||
File::ensureDirectoryExists($source);
|
||||
File::ensureDirectoryExists($linkTarget);
|
||||
File::put($linkTarget.'/inside.txt', 'junction 대상 안 파일');
|
||||
|
||||
$junctionPath = $source.'/storage';
|
||||
// mklink /J 는 관리자 권한 없이 생성 가능 (심볼릭 링크와 달리 SeCreateSymbolicLink 불필요)
|
||||
exec('cmd /c mklink /J '.escapeshellarg($junctionPath).' '.escapeshellarg($linkTarget).' 2>&1', $out, $code);
|
||||
if ($code !== 0 || ! is_dir($junctionPath)) {
|
||||
$this->markTestSkipped('junction 생성 실패: '.implode("\n", $out));
|
||||
}
|
||||
|
||||
// 사전 조건: PHP 가 junction 을 link/dir 어느 쪽으로도 인식하지 못함을 확인
|
||||
$this->assertFalse(is_link($junctionPath), 'junction 은 is_link() 가 false (전제)');
|
||||
|
||||
// copyFile 이 디렉토리를 받아 던지던 예외 없이 완료되어야 한다
|
||||
FilePermissionHelper::copyDirectory($source, $dest);
|
||||
|
||||
// junction 은 dest 에도 junction 으로 보존되어 target 내용에 접근 가능해야 한다
|
||||
$this->assertTrue(is_dir($dest.'/storage'), 'dest 의 storage 는 디렉토리(junction)로 접근 가능해야 한다');
|
||||
$this->assertFileExists($dest.'/storage/inside.txt', 'junction 통과 시 target 파일 접근 가능');
|
||||
}
|
||||
|
||||
/**
|
||||
* removeOrphanItems 가 source 부재 junction 을 재귀 삭제(target 내용 삭제)하지 않고
|
||||
* 링크 자체만 제거하는지 검증 (junction 은 isDir() 이 false 라 별도 rmdir 경로 필요).
|
||||
*/
|
||||
#[Test]
|
||||
public function removeOrphanItems_는_source_부재_junction_을_target_추적_없이_링크만_제거합니다(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$this->markTestSkipped('junction 은 Windows 전용 (mklink /J)');
|
||||
}
|
||||
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
$linkTarget = $this->tempRoot.'/link_target';
|
||||
|
||||
File::ensureDirectoryExists($source);
|
||||
File::ensureDirectoryExists($dest);
|
||||
File::ensureDirectoryExists($linkTarget);
|
||||
File::put($linkTarget.'/precious.txt', '중요한 파일');
|
||||
|
||||
// dest 에만 존재하는 junction (source 에는 없음)
|
||||
exec('cmd /c mklink /J '.escapeshellarg($dest.'/orphan_link').' '.escapeshellarg($linkTarget).' 2>&1', $out, $code);
|
||||
if ($code !== 0 || ! is_dir($dest.'/orphan_link')) {
|
||||
$this->markTestSkipped('junction 생성 실패: '.implode("\n", $out));
|
||||
}
|
||||
|
||||
FilePermissionHelper::copyDirectory($source, $dest, null, [], '', true);
|
||||
|
||||
$this->assertDirectoryDoesNotExist($dest.'/orphan_link', 'orphan junction 은 제거되어야 한다');
|
||||
$this->assertFileExists($linkTarget.'/precious.txt', 'junction target 의 파일은 보존되어야 한다 (재귀 삭제 사고 차단)');
|
||||
}
|
||||
}
|
||||
@@ -15,19 +15,26 @@ description: |
|
||||
|
||||
구성 (정책 결정 2026-05-11):
|
||||
1. `spawn_failure_mode` 기본값 `abort` — 4분기 모두 UpgradeHandoffException throw.
|
||||
2. `[STEPS_EXECUTED]` stdout 라인 프로토콜 — 자식이 실행한 step 수 명시.
|
||||
부모가 신호 미수신 또는 step 0건 실행 (from<to) 감지 시 silent skip 으로 판정.
|
||||
2. `[STEPS_EXECUTED]` stdout 라인 프로토콜 — 자식이 실행한 step 수(count) + 범위 내
|
||||
발견된 스텝 파일 수(discovered) 명시. 부모는 신호 미수신 또는 executed=0 &&
|
||||
discovered>0 (스텝 파일이 있는데 실행 못함) 을 silent skip 으로 판정. executed=0 &&
|
||||
discovered=0 (스텝 파일 부재) 은 정상 통과 — from<to 여도 실패 아님 (스텝 불필요 릴리즈).
|
||||
3. `runUpgradeSteps` 진입 직후 stale 메모리 가드 — config('app.version') < toVersion
|
||||
이면 mode=abort 시 throw, mode=fallback 시 warning log.
|
||||
4. V-1 안전 작성 패턴 docs + audit rule `upgrade-step-vone-safety` (warning) —
|
||||
upgrade step 안의 `app(*Service|*Manager|*Repository::class)` 호출을 reviewer 에게 surface.
|
||||
|
||||
분기 개정 (2026-07-02 #432 후속): `child_silent_skip_zero_steps` 를 discovered 축으로
|
||||
세분화. 범위 내 스텝 파일이 애초에 없어 0건인 경우(discovered=0)를 정상 통과로 재분류하여,
|
||||
스텝이 필요 없는 패치 릴리즈(예: 7.0.0→7.0.1) 를 실패로 오판하던 결함을 차단.
|
||||
|
||||
axes:
|
||||
spawn_branch: [proc_open_disabled, proc_open_resource_fail, child_abnormal_exit, child_silent_skip_no_signal, child_silent_skip_zero_steps]
|
||||
spawn_branch: [proc_open_disabled, proc_open_resource_fail, child_abnormal_exit, child_silent_skip_no_signal, child_zero_steps_with_discovered, child_zero_steps_no_step_files]
|
||||
spawn_failure_mode: [abort, fallback]
|
||||
from_to_relation: [from_lt_to, from_eq_to_forced] # version_compare 분기
|
||||
parent_memory_version: [equal_to_to, less_than_to, greater_than_to] # stale 가드 트리거 조건
|
||||
steps_executed_signal: [present_positive, present_zero, absent] # 자식의 [STEPS_EXECUTED] 발행 상태
|
||||
steps_executed_signal: [present_positive, present_zero, absent] # 자식의 [STEPS_EXECUTED] count 발행 상태
|
||||
steps_discovered_signal: [discovered_positive, discovered_zero, absent] # 범위 내 발견된 스텝 파일 수 (신버전 자식만 발행, 구버전=absent)
|
||||
child_process_origin: [beta_5_plus, beta_4_or_earlier] # 이전 버전 자식 (silent skip 시뮬레이션)
|
||||
upgrade_step_v_one_pattern: [app_service_call, app_manager_call, app_repository_call, local_only]
|
||||
audit_allow_inline: [present, absent] # 면제 주석 적용 여부
|
||||
@@ -35,8 +42,12 @@ axes:
|
||||
|
||||
exclusions:
|
||||
- { spawn_branch: proc_open_disabled, parent_memory_version: equal_to_to, reason: "proc_open 비활성 시점에 부모는 항상 fromVersion 메모리 — equal 케이스 시뮬 불가" }
|
||||
- { from_to_relation: from_eq_to_forced, spawn_branch: child_silent_skip_zero_steps, reason: "from==to + force 케이스는 step 0건이 정상 동작이므로 silent skip 가드 미트리거" }
|
||||
- { from_to_relation: from_eq_to_forced, spawn_branch: child_zero_steps_with_discovered, reason: "from==to + force 케이스는 step 0건이 정상 동작이므로 silent skip 가드 미트리거" }
|
||||
- { child_process_origin: beta_4_or_earlier, steps_executed_signal: present_positive, reason: "beta.5 이전 자식은 [STEPS_EXECUTED] 신호 자체를 모름 — present_positive 시뮬 불가" }
|
||||
- { child_process_origin: beta_4_or_earlier, steps_discovered_signal: discovered_positive, reason: "discovered 필드는 #432 후속 신버전 자식만 발행 — 구버전 자식은 항상 absent" }
|
||||
- { child_process_origin: beta_4_or_earlier, steps_discovered_signal: discovered_zero, reason: "동일 — 구버전 자식은 discovered 필드 미발행(absent)" }
|
||||
- { spawn_branch: child_zero_steps_no_step_files, steps_discovered_signal: discovered_positive, reason: "스텝 파일 부재 브랜치는 정의상 discovered=0 — positive 모순" }
|
||||
- { spawn_branch: child_zero_steps_with_discovered, steps_discovered_signal: discovered_zero, reason: "스텝 파일 존재 브랜치는 정의상 discovered>0 — zero 모순" }
|
||||
|
||||
effects:
|
||||
# §2 spawn_failure_mode + failSpawnWithMode
|
||||
@@ -45,12 +56,17 @@ effects:
|
||||
- spawnUpgradeStepsProcess_proc_open_disabled_dispatches_to_failSpawnWithMode
|
||||
- spawnUpgradeStepsProcess_proc_open_resource_fail_dispatches_to_failSpawnWithMode
|
||||
- spawnUpgradeStepsProcess_child_abnormal_exit_dispatches_to_failSpawnWithMode
|
||||
# §2.1 [STEPS_EXECUTED] silent skip 가드
|
||||
- ExecuteUpgradeStepsCommand_emits_STEPS_EXECUTED_with_count_on_normal_completion
|
||||
# §2.1 [STEPS_EXECUTED] silent skip 가드 (count + discovered)
|
||||
- ExecuteUpgradeStepsCommand_emits_STEPS_EXECUTED_with_count_and_discovered_on_normal_completion
|
||||
- ExecuteUpgradeStepsCommand_does_not_emit_STEPS_EXECUTED_on_handoff_exit
|
||||
- spawnUpgradeStepsProcess_parses_STEPS_EXECUTED_with_positive_count_returns_true
|
||||
- spawnUpgradeStepsProcess_missing_STEPS_EXECUTED_dispatches_to_failSpawnWithMode
|
||||
- spawnUpgradeStepsProcess_zero_steps_with_from_lt_to_dispatches_to_failSpawnWithMode
|
||||
# discovered 기반 분기 (#432 후속) — executed=0 을 discovered 로 구분
|
||||
- handleSpawnExit_zero_executed_zero_discovered_returns_true # 케이스 B: 스텝 파일 부재 정상 통과
|
||||
- handleSpawnExit_zero_executed_positive_discovered_dispatches_to_failSpawnWithMode # 케이스 A: #28 silent skip
|
||||
- handleSpawnExit_zero_executed_null_discovered_from_lt_to_dispatches_to_failSpawnWithMode # 구버전 자식 레거시 판정
|
||||
- spawnUpgradeStepsProcess_no_step_files_returns_true_even_when_from_lt_to # 7.0.0→7.0.1 실증
|
||||
- runUpgradeSteps_notifies_discovered_zero_when_no_step_in_range
|
||||
- spawnUpgradeStepsProcess_zero_steps_with_from_eq_to_forced_returns_true
|
||||
# §6 stale 메모리 가드
|
||||
- runUpgradeSteps_throws_UpgradeHandoffException_when_memory_lt_to_with_abort_mode
|
||||
|
||||
Reference in new issue
Block a user