v7.0.0-beta.7 release

This commit is contained in:
HeuJung committed 2026-05-15 19:24:41 +09:00
1 parent c186d9a9c2
commit 0e7fa04b03
36 files changed
+2625 -83

No files matched your search

+24
View File
@@ -71,6 +71,9 @@ class UpgradeStepsTest extends TestCase
'2.0.0' => $step_2_0,
]);
$module->shouldReceive('getIdentifier')->andReturn('test-module');
// ExtensionUpgradeGuardHelper::resolveSinceVersion 가 본 두 메서드를 조회 (a9432939f #347)
$module->shouldReceive('getRequiredCoreVersion')->andReturn(null);
$module->shouldReceive('getVersion')->andReturn('1.0.0');
$manager = $this->createModuleManagerWithMocks();
$method = new \ReflectionMethod($manager, 'runUpgradeSteps');
@@ -111,6 +114,9 @@ class UpgradeStepsTest extends TestCase
'1.2.0' => $step_1_2,
]);
$module->shouldReceive('getIdentifier')->andReturn('test-module');
// ExtensionUpgradeGuardHelper::resolveSinceVersion 가 본 두 메서드를 조회 (a9432939f #347)
$module->shouldReceive('getRequiredCoreVersion')->andReturn(null);
$module->shouldReceive('getVersion')->andReturn('1.0.0');
$manager = $this->createModuleManagerWithMocks();
$method = new \ReflectionMethod($manager, 'runUpgradeSteps');
@@ -139,6 +145,9 @@ class UpgradeStepsTest extends TestCase
'1.1.0' => $callableStep,
]);
$module->shouldReceive('getIdentifier')->andReturn('test-module');
// ExtensionUpgradeGuardHelper::resolveSinceVersion 가 본 두 메서드를 조회 (a9432939f #347)
$module->shouldReceive('getRequiredCoreVersion')->andReturn(null);
$module->shouldReceive('getVersion')->andReturn('1.0.0');
$manager = $this->createModuleManagerWithMocks();
$method = new \ReflectionMethod($manager, 'runUpgradeSteps');
@@ -166,6 +175,9 @@ class UpgradeStepsTest extends TestCase
'1.1.0' => $failingStep,
]);
$module->shouldReceive('getIdentifier')->andReturn('test-module');
// ExtensionUpgradeGuardHelper::resolveSinceVersion 가 본 두 메서드를 조회 (a9432939f #347)
$module->shouldReceive('getRequiredCoreVersion')->andReturn(null);
$module->shouldReceive('getVersion')->andReturn('1.0.0');
$manager = $this->createModuleManagerWithMocks();
$method = new \ReflectionMethod($manager, 'runUpgradeSteps');
@@ -239,6 +251,9 @@ class UpgradeStepsTest extends TestCase
'1.1.0' => $otherStep,
]);
$module->shouldReceive('getIdentifier')->andReturn('test-module');
// ExtensionUpgradeGuardHelper::resolveSinceVersion 가 본 두 메서드를 조회 (a9432939f #347)
$module->shouldReceive('getRequiredCoreVersion')->andReturn(null);
$module->shouldReceive('getVersion')->andReturn('1.0.0');
$manager = $this->createModuleManagerWithMocks();
$method = new \ReflectionMethod($manager, 'runUpgradeSteps');
@@ -270,6 +285,9 @@ class UpgradeStepsTest extends TestCase
'1.0.0-beta.2' => $step_beta2,
]);
$module->shouldReceive('getIdentifier')->andReturn('test-module');
// ExtensionUpgradeGuardHelper::resolveSinceVersion 가 본 두 메서드를 조회 (a9432939f #347)
$module->shouldReceive('getRequiredCoreVersion')->andReturn(null);
$module->shouldReceive('getVersion')->andReturn('1.0.0');
$manager = $this->createModuleManagerWithMocks();
$method = new \ReflectionMethod($manager, 'runUpgradeSteps');
@@ -307,6 +325,9 @@ class UpgradeStepsTest extends TestCase
'1.2.0' => $step_1_2,
]);
$module->shouldReceive('getIdentifier')->andReturn('test-module');
// ExtensionUpgradeGuardHelper::resolveSinceVersion 가 본 두 메서드를 조회 (a9432939f #347)
$module->shouldReceive('getRequiredCoreVersion')->andReturn(null);
$module->shouldReceive('getVersion')->andReturn('1.0.0');
$manager = $this->createModuleManagerWithMocks();
$method = new \ReflectionMethod($manager, 'runUpgradeSteps');
@@ -411,6 +432,9 @@ class UpgradeStepsTest extends TestCase
'7.0.0-beta.2' => $step_beta2,
]);
$module->shouldReceive('getIdentifier')->andReturn('test-module');
// ExtensionUpgradeGuardHelper::resolveSinceVersion 가 본 두 메서드를 조회 (a9432939f #347)
$module->shouldReceive('getRequiredCoreVersion')->andReturn(null);
$module->shouldReceive('getVersion')->andReturn('1.0.0');
$manager = $this->createModuleManagerWithMocks();
$method = new \ReflectionMethod($manager, 'runUpgradeSteps');
+69 -2
View File
@@ -57,8 +57,14 @@ class InstallerGuardTest extends TestCase
private function cleanup(): void
{
@unlink(BASE_PATH . '/storage/app/g7_installed');
@unlink(BASE_PATH . '/.env');
$lock = BASE_PATH . '/storage/app/g7_installed';
if (is_file($lock)) {
@unlink($lock);
}
$env = BASE_PATH . '/.env';
if (is_file($env)) {
@unlink($env);
}
}
public function test_no_signals_means_not_completed(): void
@@ -115,4 +121,65 @@ class InstallerGuardTest extends TestCase
$this->assertTrue(installer_is_completed());
}
// ------------------------------------------------------------------------
// finalize 전용 가드 — installer_finalize_is_completed()
//
// 일반 가드와 달리 g7_installed 락 파일은 차단 사유에서 제외되어야 한다
// (complete_flag task 가 락 파일을 먼저 생성한 직후 finalize 가 호출되는
// 설계상의 호출 순서 때문 — 이슈 #371 자가 차단 회귀 가드).
// ------------------------------------------------------------------------
public function test_finalize_guard_passes_with_lock_only(): void
{
// 정상 1회차 finalize 시나리오: 락 파일은 존재하나 .env 머지 아직 안 됨
file_put_contents(BASE_PATH . '/storage/app/g7_installed', '');
$this->assertFalse(
installer_finalize_is_completed(),
'g7_installed 락 파일 단독 존재 시 finalize 차단되면 자가 차단 회귀 (이슈 #371)'
);
}
public function test_finalize_guard_passes_with_no_env_file(): void
{
// .env 자체가 없는 신규 설치 시나리오
$this->assertFalse(installer_finalize_is_completed());
}
public function test_finalize_guard_blocks_when_env_completed_true(): void
{
// 이미 finalize 된 상태 — 멱등 차단
file_put_contents(BASE_PATH . '/.env', "APP_ENV=local\nINSTALLER_COMPLETED=true\n");
$this->assertTrue(installer_finalize_is_completed());
}
public function test_finalize_guard_blocks_with_lock_and_env_completed(): void
{
// 락 + .env true 동시 존재 → 차단 (멱등)
file_put_contents(BASE_PATH . '/storage/app/g7_installed', '');
file_put_contents(BASE_PATH . '/.env', 'INSTALLER_COMPLETED=true' . "\n");
$this->assertTrue(installer_finalize_is_completed());
}
public function test_finalize_guard_passes_when_env_completed_false(): void
{
file_put_contents(BASE_PATH . '/.env', "INSTALLER_COMPLETED=false\n");
$this->assertFalse(installer_finalize_is_completed());
}
public function test_finalize_guard_accepts_quoted_and_alt_truthy_values(): void
{
file_put_contents(BASE_PATH . '/.env', 'INSTALLER_COMPLETED="true"' . "\n");
$this->assertTrue(installer_finalize_is_completed());
file_put_contents(BASE_PATH . '/.env', 'INSTALLER_COMPLETED=1' . "\n");
$this->assertTrue(installer_finalize_is_completed());
file_put_contents(BASE_PATH . '/.env', 'INSTALLER_COMPLETED=yes' . "\n");
$this->assertTrue(installer_finalize_is_completed());
}
}
@@ -73,9 +73,13 @@ class InstallerSecurityHardeningTest extends TestCase
*/
protected function tearDown(): void
{
@unlink(STATE_PATH);
if (is_file(STATE_PATH)) {
@unlink(STATE_PATH);
}
$projectStateFile = dirname(__DIR__, 3) . '/storage/installer-state.json';
@unlink($projectStateFile);
if (is_file($projectStateFile)) {
@unlink($projectStateFile);
}
parent::tearDown();
}
@@ -366,7 +370,7 @@ class InstallerSecurityHardeningTest extends TestCase
'/opt/php/bin/php',
'C:/php/php.exe',
'/nonexistent/path',
// Windows 절대경로 (백슬래시 포함) — 회귀 가드: PO 환경 (Windows 빌트인 서버)
// Windows 절대경로 (백슬래시 포함) — 회귀 가드: Windows 빌트인 서버 환경
'C:\\laragon\\bin\\php\\php-8.3.26-Win32-vs16-x64\\php.exe',
'C:\\php\\php.exe',
'D:\\xampp\\php\\php.exe',
@@ -20,16 +20,44 @@ class InstallerRuntimeServiceProviderTest extends TestCase
private ?string $originalEnv = null;
private string $envPath;
private ?string $originalEnvContent = null;
private bool $originalEnvExisted = false;
/** @var array<string, string|null> */
private array $originalEnvSnapshot = [];
private const ENV_KEYS_FOR_SNAPSHOT = [
'DB_WRITE_HOST', 'DB_WRITE_PORT', 'DB_WRITE_DATABASE', 'DB_WRITE_USERNAME', 'DB_WRITE_PASSWORD',
'DB_READ_HOST', 'DB_READ_PORT', 'DB_READ_DATABASE', 'DB_READ_USERNAME', 'DB_READ_PASSWORD',
'DB_PREFIX', 'APP_KEY',
];
protected function setUp(): void
{
parent::setUp();
$this->runtimePath = base_path('storage/installer/runtime.php');
$this->envPath = base_path('.env');
// 테스트 시작 시 runtime.php 정리 (이전 테스트의 잔재 제거)
if (is_file($this->runtimePath)) {
@unlink($this->runtimePath);
}
// .env 원본 보존
if (is_file($this->envPath)) {
$this->originalEnvExisted = true;
$this->originalEnvContent = file_get_contents($this->envPath);
}
// process ENV 스냅샷 (stale ENV 보정 테스트가 갱신하므로 다음 테스트 격리)
foreach (self::ENV_KEYS_FOR_SNAPSHOT as $key) {
$value = getenv($key);
$this->originalEnvSnapshot[$key] = $value === false ? null : $value;
}
}
protected function tearDown(): void
@@ -49,6 +77,25 @@ class InstallerRuntimeServiceProviderTest extends TestCase
$this->originalEnv = null;
}
// .env 복원
if ($this->originalEnvExisted && $this->originalEnvContent !== null) {
file_put_contents($this->envPath, $this->originalEnvContent);
} elseif (! $this->originalEnvExisted && is_file($this->envPath)) {
@unlink($this->envPath);
}
// process ENV 복원
foreach ($this->originalEnvSnapshot as $key => $value) {
if ($value === null) {
putenv($key);
unset($_ENV[$key], $_SERVER[$key]);
} else {
putenv($key.'='.$value);
$_ENV[$key] = $value;
$_SERVER[$key] = $value;
}
}
parent::tearDown();
}
@@ -221,6 +268,161 @@ class InstallerRuntimeServiceProviderTest extends TestCase
$this->assertSame($originalKey, Config::get('app.key'));
}
// -----------------------------------------------------------------------
// beta.7 한시 보정 — beta.4~6 finalize 결함 환경에서 .env 머지 후 spawn 자식의
// stale process ENV (DB_WRITE_USERNAME=root 등) 회귀 차단.
//
// 트리거 조건 (모두 만족 시에만 보정):
// 1. runtime.php 부재 (이미 finalize 완료된 상태)
// 2. .env 존재 + 정합 자격증명 보유 (DB_WRITE_USERNAME 이 root 가 아니고 비어있지 않음)
// 3. process ENV 의 DB_WRITE_USERNAME 이 'root' 또는 빈 값 (stale 시그니처)
// 4. .env 의 INSTALLER_COMPLETED 가 truthy (finalize 성공 신호)
//
// 위 4개를 모두 만족하면 .env 의 DB_* / APP_KEY 를 process ENV (getenv/$_ENV/$_SERVER)
// 에 적용. 정상 환경에서는 #3 (stale 시그니처) 가 false 라 트리거 안 됨.
// -----------------------------------------------------------------------
public function test_recovers_stale_process_env_when_disk_env_is_healthy(): void
{
$this->withProductionEnv();
// 디스크 .env 는 정합 자격증명 + INSTALLER_COMPLETED (finalize 완료 신호)
file_put_contents($this->envPath, implode("\n", [
'APP_ENV=production',
'DB_WRITE_USERNAME=g7_user',
'DB_WRITE_PASSWORD="real_pw"',
'DB_WRITE_DATABASE=g7',
'DB_READ_USERNAME=g7_user',
'DB_READ_PASSWORD="real_pw"',
'DB_READ_DATABASE=g7',
'INSTALLER_COMPLETED=true',
'',
]));
// process ENV 는 stale (Dotenv 가 부팅 시 .env.example fallback 을 적재한 상태)
putenv('DB_WRITE_USERNAME=root');
putenv('DB_WRITE_PASSWORD=');
putenv('DB_READ_USERNAME=root');
putenv('DB_READ_PASSWORD=');
$_ENV['DB_WRITE_USERNAME'] = 'root';
$_ENV['DB_WRITE_PASSWORD'] = '';
$_ENV['DB_READ_USERNAME'] = 'root';
$_ENV['DB_READ_PASSWORD'] = '';
// $_SERVER 도 stale — bootstrap/app.php 의 Env::disablePutenv() 환경에서는
// Dotenv 가 $_ENV/$_SERVER 만 채우므로 셋 다 stale 인 실서버 케이스 재현
$_SERVER['DB_WRITE_USERNAME'] = 'root';
$_SERVER['DB_WRITE_PASSWORD'] = '';
$_SERVER['DB_READ_USERNAME'] = 'root';
$_SERVER['DB_READ_PASSWORD'] = '';
$this->assertFileDoesNotExist($this->runtimePath, 'precondition: runtime.php 부재');
$provider = new InstallerRuntimeServiceProvider($this->app);
$provider->register();
$this->assertSame('g7_user', getenv('DB_WRITE_USERNAME'), 'stale root 가 .env 의 정합 값으로 갱신되어야 함');
$this->assertSame('real_pw', getenv('DB_WRITE_PASSWORD'));
$this->assertSame('g7_user', getenv('DB_READ_USERNAME'));
$this->assertSame('real_pw', getenv('DB_READ_PASSWORD'));
$this->assertSame('g7_user', $_ENV['DB_WRITE_USERNAME'] ?? null);
$this->assertSame('g7_user', $_SERVER['DB_WRITE_USERNAME'] ?? null);
}
public function test_no_recovery_when_process_env_already_healthy(): void
{
$this->withProductionEnv();
file_put_contents($this->envPath, implode("\n", [
'DB_WRITE_USERNAME=g7_user',
'DB_WRITE_PASSWORD="real_pw"',
'INSTALLER_COMPLETED=true',
'',
]));
// 정상 환경 시뮬레이션 — process ENV 가 이미 정합
putenv('DB_WRITE_USERNAME=already_correct');
putenv('DB_WRITE_PASSWORD=already_correct_pw');
$_ENV['DB_WRITE_USERNAME'] = 'already_correct';
$_ENV['DB_WRITE_PASSWORD'] = 'already_correct_pw';
$provider = new InstallerRuntimeServiceProvider($this->app);
$provider->register();
// 보정 트리거 안 됨 — 정합 ENV 보존 (beta.7 보정이 .env 의 g7_user 로 덮어쓰면 안 됨)
$this->assertSame('already_correct', getenv('DB_WRITE_USERNAME'), 'stale 시그니처 아니므로 보정 미발동');
$this->assertSame('already_correct_pw', getenv('DB_WRITE_PASSWORD'));
}
public function test_no_recovery_when_disk_env_also_stale(): void
{
$this->withProductionEnv();
// 디스크 .env 도 stale (finalize 실패 분기 시뮬레이션)
file_put_contents($this->envPath, implode("\n", [
'DB_WRITE_USERNAME=root',
'DB_WRITE_PASSWORD=',
'INSTALLER_COMPLETED=true',
'',
]));
putenv('DB_WRITE_USERNAME=root');
putenv('DB_WRITE_PASSWORD=');
$_ENV['DB_WRITE_USERNAME'] = 'root';
$_ENV['DB_WRITE_PASSWORD'] = '';
$provider = new InstallerRuntimeServiceProvider($this->app);
$provider->register();
// .env 도 stale 이므로 보정 의미 없음 — 빈 값으로 덮어쓰지 않음
$this->assertSame('root', getenv('DB_WRITE_USERNAME'), '.env 도 stale 이면 보정 미발동 (정상 ENV 손상 방지)');
}
public function test_no_recovery_when_installer_not_completed(): void
{
$this->withProductionEnv();
// INSTALLER_COMPLETED 부재 — finalize 미수행 (인스톨러 중간 상태) 시그니처
file_put_contents($this->envPath, implode("\n", [
'DB_WRITE_USERNAME=g7_user',
'DB_WRITE_PASSWORD="real_pw"',
'',
]));
putenv('DB_WRITE_USERNAME=root');
$_ENV['DB_WRITE_USERNAME'] = 'root';
$provider = new InstallerRuntimeServiceProvider($this->app);
$provider->register();
// INSTALLER_COMPLETED 부재 → 보정 미발동 (인스톨러 진행 중일 수 있음, 보수적 보호)
$this->assertSame('root', getenv('DB_WRITE_USERNAME'), 'INSTALLER_COMPLETED 부재 시 보정 미발동');
}
public function test_no_recovery_when_runtime_php_still_present(): void
{
$this->withProductionEnv();
// runtime.php 잔존 — 기존 register() 가 Config 주입을 처리하므로 보정 불필요
$this->writeRuntime([
'db' => ['write' => ['host' => '127.0.0.1', 'username' => 'rt_user', 'password' => 'rt_pw']],
]);
file_put_contents($this->envPath, implode("\n", [
'DB_WRITE_USERNAME=g7_user',
'INSTALLER_COMPLETED=true',
'',
]));
putenv('DB_WRITE_USERNAME=root');
$_ENV['DB_WRITE_USERNAME'] = 'root';
$provider = new InstallerRuntimeServiceProvider($this->app);
$provider->register();
// runtime.php 존재 → 기존 경로 (Config 주입) 가 동작. 본 보정은 트리거 안 됨.
$this->assertSame('root', getenv('DB_WRITE_USERNAME'), 'runtime.php 잔존 시 본 보정 미발동');
}
/**
* @param array<string, mixed> $data
*/