From 427e059e4ffc6ce5ff130c803f9e533b7c125089 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 7 Aug 2026 20:51:59 +0900 Subject: feat(plugin): cross alias packages over RPC as proxy stubs AliasPackage, CompleteAliasPackage and RootAliasPackage now have generated proxy stubs, so a package handed to a plugin no longer has to be a real package: it crosses as the stub matching its concrete variant, answers getAliasOf / setRootPackageAlias / isRootPackageAlias / hasSelfVersionRequires, and can be constructed from plugin code. The setters RootPackageInterface declares are routed through that interface for every root package instead of through the base Package state. Only the alias variant needs it -- RootAliasPackage overrides all nine to write through to the package it aliases -- but a real RootPackage delegates to the same base state either way, so both take one path. An alias of an alias has no representation here, so narrowing the constructor argument to a real package is an explicit error rather than a silent demotion. Co-Authored-By: Claude Opus 5 (1M context) --- .../plugin/fixtures/alias-v1/Alias/Plugin.php | 63 ++++++++++++++++++++++ .../tests/plugin/fixtures/alias-v1/composer.json | 12 +++++ 2 files changed, 75 insertions(+) create mode 100644 crates/shirabe/tests/plugin/fixtures/alias-v1/Alias/Plugin.php create mode 100644 crates/shirabe/tests/plugin/fixtures/alias-v1/composer.json (limited to 'crates/shirabe/tests/plugin/fixtures') diff --git a/crates/shirabe/tests/plugin/fixtures/alias-v1/Alias/Plugin.php b/crates/shirabe/tests/plugin/fixtures/alias-v1/Alias/Plugin.php new file mode 100644 index 00000000..373348e8 --- /dev/null +++ b/crates/shirabe/tests/plugin/fixtures/alias-v1/Alias/Plugin.php @@ -0,0 +1,63 @@ +getRepositoryManager()->getLocalRepository()->getPackages() as $package) { + if (!$package instanceof AliasPackage) { + continue; + } + $aliased = $package->getAliasOf(); + $io->write('alias: ' . self::describe($package)); + $io->write('alias description: ' . $package->getDescription()); + $io->write('alias self-version: ' . ($package->hasSelfVersionRequires() ? 'yes' : 'no')); + $io->write('alias root-flag: ' . ($package->isRootPackageAlias() ? 'yes' : 'no')); + $package->setRootPackageAlias(true); + $io->write('alias root-flag: ' . ($package->isRootPackageAlias() ? 'yes' : 'no')); + } + + $root = $composer->getPackage(); + if (!$root instanceof RootAliasPackage) { + throw new \RuntimeException('not a RootAliasPackage: ' . get_class($root)); + } + $io->write('root: ' . self::describe($root)); + $io->write('root aliasOf identity: ' . ($root->getAliasOf() === $root->getAliasOf() ? 'same' : 'distinct')); + $io->write('root minimum stability: ' . $root->getMinimumStability()); + $root->setMinimumStability('dev'); + $root->setExtra(['seen-by' => 'alias-v1']); + + $built = new CompleteAliasPackage($aliased, '9.9.9.9', '9.9.9'); + $io->write('built: ' . self::describe($built)); + } + + public function deactivate(Composer $composer, IOInterface $io) + { + } + + public function uninstall(Composer $composer, IOInterface $io) + { + } + + private static function describe(AliasPackage $package): string + { + return sprintf( + '%s %s %s of %s %s', + get_class($package), + $package->getName(), + $package->getPrettyVersion(), + get_class($package->getAliasOf()), + $package->getAliasOf()->getPrettyVersion() + ); + } +} diff --git a/crates/shirabe/tests/plugin/fixtures/alias-v1/composer.json b/crates/shirabe/tests/plugin/fixtures/alias-v1/composer.json new file mode 100644 index 00000000..ac831b6e --- /dev/null +++ b/crates/shirabe/tests/plugin/fixtures/alias-v1/composer.json @@ -0,0 +1,12 @@ +{ + "name": "alias-v1", + "version": "1.0.0", + "type": "composer-plugin", + "autoload": { "psr-0": { "Alias": "" } }, + "extra": { + "class": "Alias\\Plugin" + }, + "require": { + "composer-plugin-api": "^2.0" + } +} -- cgit v1.3.1