diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-06 01:51:05 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-06 01:51:05 +0900 |
| commit | 0e89281dd7f057d3829508b8e6c5d85c3f111c45 (patch) | |
| tree | e8bb7c9c30009683f68d03fb4b35c7aade11b91b /crates/shirabe/tests/plugin/fixtures | |
| parent | 4de018826e9dce90fd5cb78d468641478327ec99 (diff) | |
| download | php-shirabe-0e89281dd7f057d3829508b8e6c5d85c3f111c45.tar.gz php-shirabe-0e89281dd7f057d3829508b8e6c5d85c3f111c45.tar.zst php-shirabe-0e89281dd7f057d3829508b8e6c5d85c3f111c45.zip | |
test(plugin): compare a plugin-provided installer against upstream Composer
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/plugin/fixtures')
5 files changed, 196 insertions, 0 deletions
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 @@ +<?php + +namespace ShirabeTest\AssetInstaller; + +use Composer\Composer; +use Composer\Installer\InstallerInterface; +use Composer\IO\IOInterface; +use Composer\Package\PackageInterface; +use Composer\Repository\InstalledRepositoryInterface; +use React\Promise\PromiseInterface; + +/** + * Installs `shirabe-asset` packages by writing a manifest of what the installer observed, + * without going through the download manager. Every call also appends a trace line, so the + * order and arguments of the installer contract are comparable between implementations. + */ +class AssetInstaller implements InstallerInterface +{ + /** @var IOInterface */ + private $io; + + /** @var Composer */ + private $composer; + + public function __construct(IOInterface $io, Composer $composer) + { + $this->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 @@ +<?php + +namespace ShirabeTest\AssetInstaller; + +use Composer\Composer; +use Composer\IO\IOInterface; +use Composer\Plugin\PluginInterface; + +class Plugin implements PluginInterface +{ + /** @var AssetInstaller */ + private $installer; + + public function activate(Composer $composer, IOInterface $io): void + { + $this->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 + } + } +} |
