From 0e89281dd7f057d3829508b8e6c5d85c3f111c45 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 6 Aug 2026 01:51:05 +0900 Subject: test(plugin): compare a plugin-provided installer against upstream Composer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fixture plugin registers an InstallerInterface implementation of its own and installs a package of a custom type with it, recording every contract call it receives. A fresh install produces a byte-identical project tree on both implementations, trace included. A second test pins the divergence a re-run and a `remove` expose: the two implementations consult getInstaller at different points, so the trace order — and its length once `remove` re-creates the Composer instance — differs. It is written in full and marked ignored rather than trimmed. Co-Authored-By: Claude Opus 5 (1M context) --- .../e2e-installer/packages/asset-a/composer.json | 6 ++ .../fixtures/e2e-installer/plugin/composer.json | 17 ++++ .../e2e-installer/plugin/src/AssetInstaller.php | 113 +++++++++++++++++++++ .../fixtures/e2e-installer/plugin/src/Plugin.php | 28 +++++ .../fixtures/e2e-installer/project/composer.json | 32 ++++++ 5 files changed, 196 insertions(+) create mode 100644 crates/shirabe/tests/plugin/fixtures/e2e-installer/packages/asset-a/composer.json create mode 100644 crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/composer.json create mode 100644 crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/AssetInstaller.php create mode 100644 crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/Plugin.php create mode 100644 crates/shirabe/tests/plugin/fixtures/e2e-installer/project/composer.json (limited to 'crates/shirabe/tests/plugin/fixtures') diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/packages/asset-a/composer.json b/crates/shirabe/tests/plugin/fixtures/e2e-installer/packages/asset-a/composer.json new file mode 100644 index 00000000..4fe63968 --- /dev/null +++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/packages/asset-a/composer.json @@ -0,0 +1,6 @@ +{ + "name": "shirabe-test/asset-a", + "version": "1.0.0", + "type": "shirabe-asset", + "description": "Fixture package installed by the plugin-provided installer." +} diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/composer.json b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/composer.json new file mode 100644 index 00000000..8275f2c0 --- /dev/null +++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/composer.json @@ -0,0 +1,17 @@ +{ + "name": "shirabe-test/asset-installer", + "version": "1.0.0", + "type": "composer-plugin", + "description": "Fixture plugin registering a custom installer through InstallationManager::addInstaller.", + "autoload": { + "psr-4": { + "ShirabeTest\\AssetInstaller\\": "src/" + } + }, + "require": { + "composer-plugin-api": "^2.0" + }, + "extra": { + "class": "ShirabeTest\\AssetInstaller\\Plugin" + } +} diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/AssetInstaller.php b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/AssetInstaller.php new file mode 100644 index 00000000..a80eb678 --- /dev/null +++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/AssetInstaller.php @@ -0,0 +1,113 @@ +io = $io; + $this->composer = $composer; + } + + public function supports(string $packageType): bool + { + $this->trace('supports ' . $packageType); + + return $packageType === 'shirabe-asset'; + } + + public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package): bool + { + $this->trace('isInstalled ' . $package->getPrettyName()); + + return is_file($this->getInstallPath($package) . '/asset.txt'); + } + + public function download(PackageInterface $package, ?PackageInterface $prevPackage = null): ?PromiseInterface + { + $this->trace('download ' . $package->getPrettyName() . ' prev=' . $this->name($prevPackage)); + + return null; + } + + public function prepare(string $type, PackageInterface $package, ?PackageInterface $prevPackage = null): ?PromiseInterface + { + $this->trace('prepare ' . $type . ' ' . $package->getPrettyName() . ' prev=' . $this->name($prevPackage)); + + return null; + } + + public function install(InstalledRepositoryInterface $repo, PackageInterface $package): ?PromiseInterface + { + $path = $this->getInstallPath($package); + $this->trace('install ' . $package->getPrettyName() . ' -> ' . $path); + @mkdir($path, 0777, true); + file_put_contents($path . '/asset.txt', implode("\n", [ + 'name=' . $package->getPrettyName(), + 'version=' . $package->getPrettyVersion(), + 'type=' . $package->getType(), + 'root=' . $this->composer->getPackage()->getName(), + ]) . "\n"); + $this->io->write('asset-installer: installed ' . $package->getPrettyName()); + + return null; + } + + public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target): ?PromiseInterface + { + $this->trace('update ' . $initial->getPrettyName() . ' -> ' . $target->getPrettyName()); + + return $this->install($repo, $target); + } + + public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package): ?PromiseInterface + { + $path = $this->getInstallPath($package); + $this->trace('uninstall ' . $package->getPrettyName()); + @unlink($path . '/asset.txt'); + @rmdir($path); + + return null; + } + + public function cleanup(string $type, PackageInterface $package, ?PackageInterface $prevPackage = null): ?PromiseInterface + { + $this->trace('cleanup ' . $type . ' ' . $package->getPrettyName()); + + return null; + } + + public function getInstallPath(PackageInterface $package): string + { + return 'assets/' . $package->getPrettyName(); + } + + private function name(?PackageInterface $package): string + { + return $package === null ? 'null' : $package->getPrettyName(); + } + + private function trace(string $line): void + { + file_put_contents('installer-trace.txt', $line . "\n", FILE_APPEND); + } +} diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/Plugin.php b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/Plugin.php new file mode 100644 index 00000000..24a1d295 --- /dev/null +++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/Plugin.php @@ -0,0 +1,28 @@ +installer = new AssetInstaller($io, $composer); + $composer->getInstallationManager()->addInstaller($this->installer); + } + + public function deactivate(Composer $composer, IOInterface $io): void + { + $composer->getInstallationManager()->removeInstaller($this->installer); + } + + public function uninstall(Composer $composer, IOInterface $io): void + { + } +} diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/project/composer.json b/crates/shirabe/tests/plugin/fixtures/e2e-installer/project/composer.json new file mode 100644 index 00000000..64c1bb32 --- /dev/null +++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/project/composer.json @@ -0,0 +1,32 @@ +{ + "name": "shirabe/e2e-installer", + "description": "E2E fixture project: install a custom package type through a plugin-provided installer.", + "repositories": [ + { + "type": "path", + "url": "../plugin", + "options": { + "symlink": false + } + }, + { + "type": "path", + "url": "../packages/*", + "options": { + "symlink": false + } + }, + { + "packagist.org": false + } + ], + "require": { + "shirabe-test/asset-installer": "1.0.0", + "shirabe-test/asset-a": "1.0.0" + }, + "config": { + "allow-plugins": { + "shirabe-test/asset-installer": true + } + } +} -- cgit v1.3.1