fix(vendor-bundle): 확장에 새 패키지 추가 시 번들 누락 수정

빌드가 composer install 의 입력(스테이징에 복사할 composer.json/lock)만 활성
디렉토리에서 가져오고 manifest 해시는 _bundled 기준으로 기록해, 두 판단이 서로
다른 파일을 보고 있었다.

개발자는 규정상 _bundled 에서만 작업하므로 새 패키지를 추가하면 _bundled 에만
반영되고 활성은 다음 update 전까지 구버전으로 남는다. 그 결과 구버전 lock 으로
설치한 zip 에 신버전 해시가 붙어, 무결성 검증은 통과하는데 새 패키지가 번들에서
누락되고 설치 후 런타임에 클래스 not found 로 터졌다.

설치 입력·해시 기준·의존성 판정·stale 판정 네 가지를 모두 resolveHashTarget
(출력 우선, 없으면 소스 폴백) 으로 통일. 코어는 source == output 이라 무영향.

실증: 이커머스에 psr/log 추가 → 빌드 2 packages(수정 전 1) → zip 에 vendor/psr/log
포함 → module:update → 활성 vendor 배포 + Psr\Log\LoggerInterface 런타임 로드 확인.
This commit is contained in:
HeuJung committed 2026-07-11 19:50:06 +09:00
1 parent 13e65131f4
commit 25c0ab46ec
4 files changed
+139 -26

No files matched your search

+96
View File
@@ -291,6 +291,102 @@ class VendorBundlerTest extends TestCase
);
}
/**
* 분리 구조에서 composer install 의 입력(staging 에 복사되는 composer.json/lock)도
* **출력(_bundled)** 기준이어야 합니다.
*
* 개발자는 규정상 `_bundled` 에서만 작업하므로, 새 패키지를 추가하면 `_bundled/composer.json`
* 과 `_bundled/composer.lock` 에만 반영되고 활성 디렉토리는 구버전으로 남는다. 이때 설치 소스를
* 활성에서 가져오면 **구버전 lock 으로 install 한 zip** 에 **신버전 해시**를 붙인 manifest 가
* 만들어져, 무결성 검증은 통과하는데 정작 새 패키지가 번들에 빠지는 상태가 된다
* (런타임에 클래스 not found). 설치 입력과 해시 기준이 같은 디렉토리를 보아야 한다.
*/
public function test_build_installs_from_output_composer_lock_not_source(): void
{
$sourceDir = $this->testDir.'/active';
$outputDir = $this->testDir.'/bundled';
File::ensureDirectoryExists($sourceDir);
File::ensureDirectoryExists($outputDir);
// 활성 — 구버전: 패키지 1개 (아직 update 미반영)
File::put($sourceDir.'/composer.json', json_encode([
'name' => 'test/project',
'require' => ['php' => '^8.2', 'test/lib' => '^1.0'],
]));
File::put($sourceDir.'/composer.lock', json_encode([
'packages' => [
['name' => 'test/lib', 'version' => '1.0.0', 'type' => 'library'],
],
]));
// _bundled — 신버전: 개발자가 새 패키지(test/newpkg)를 추가한 상태
File::put($outputDir.'/composer.json', json_encode([
'name' => 'test/project',
'require' => ['php' => '^8.2', 'test/lib' => '^1.0', 'test/newpkg' => '^2.0'],
]));
File::put($outputDir.'/composer.lock', json_encode([
'packages' => [
['name' => 'test/lib', 'version' => '1.0.0', 'type' => 'library'],
['name' => 'test/newpkg', 'version' => '2.0.0', 'type' => 'library'],
],
]));
$this->invokeBuild('test:new-package', sourcePath: $sourceDir, outputPath: $outputDir);
$manifest = json_decode(File::get($outputDir.'/vendor-bundle.json'), true);
$names = array_column($manifest['packages'], 'name');
// manifest 의 packages 는 staging 에 복사된 lock 에서 추출되므로,
// 이 단언이 곧 "어느 lock 으로 install 했는가" 를 판정한다.
$this->assertContains(
'test/newpkg',
$names,
'_bundled 에 추가한 새 패키지가 번들에 포함되어야 합니다 (설치 소스가 활성이면 누락됨).'
);
$this->assertSame(
2,
$manifest['package_count'],
'package_count 는 _bundled/composer.lock 기준(2)이어야 합니다.'
);
// 해시 기준과 설치 입력이 같은 디렉토리를 보므로 무결성도 정합해야 한다.
$this->assertTrue($this->checker->verify($outputDir)->valid);
}
/**
* 출력 디렉토리에 composer.lock 이 없으면 소스(활성) 의 lock 으로 폴백해야 합니다.
*
* 코어는 source == output 이므로 항상 같은 파일이고, 확장도 _bundled 에 lock 이 없는
* 과도기 상태에서 빌드가 깨지지 않아야 한다 (resolveHashTarget 과 동일한 폴백 규칙).
*/
public function test_build_falls_back_to_source_lock_when_output_lock_missing(): void
{
$sourceDir = $this->testDir.'/active';
$outputDir = $this->testDir.'/bundled';
File::ensureDirectoryExists($sourceDir);
File::ensureDirectoryExists($outputDir);
File::put($sourceDir.'/composer.json', json_encode([
'name' => 'test/project',
'require' => ['php' => '^8.2', 'test/lib' => '^1.0'],
]));
File::put($sourceDir.'/composer.lock', json_encode([
'packages' => [
['name' => 'test/lib', 'version' => '1.0.0', 'type' => 'library'],
],
]));
// _bundled 에 composer.json 만 있고 lock 은 없음
File::put($outputDir.'/composer.json', File::get($sourceDir.'/composer.json'));
$this->invokeBuild('test:lock-fallback', sourcePath: $sourceDir, outputPath: $outputDir);
$manifest = json_decode(File::get($outputDir.'/vendor-bundle.json'), true);
$names = array_column($manifest['packages'], 'name');
$this->assertContains('test/lib', $names, '출력에 lock 이 없으면 소스 lock 으로 폴백해야 합니다.');
}
/**
* 분리 구조에서 isStale 은 **출력(_bundled)** 의 composer.json 변경을 감지해야 합니다.
*