From 11cdaae87c37e479fea6c39447041c312410b101 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 4 Aug 2026 06:33:32 +0900 Subject: feat(plugin): instantiate plugin capabilities through the PHP RPC worker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getPluginCapability was a no-op returning None. Now it runs the real flow: class_exists in the worker, new $capabilityClass($ctorArgs) with the plugin's own phandle spliced in as $ctorArgs['plugin'], both instanceof checks answered by is_a in the child, and a per-interface Rust adapter over the resulting entity (CommandProvider and the plain Capability marker; anything else is an explicit error). getPluginCapabilities now propagates errors instead of swallowing them. Capable::get_capabilities widens from IndexMap to IndexMap: upstream casts the return with (array) and validates only the queried key, so the narrow type both rejected maps Composer accepts and made the invalidImplementationClassNames data provider unrepresentable. The old code also returned ' 0 ' (trimmed to the falsy '0') as a valid class name where upstream throws; the rewritten validation follows upstream's empty/is_string/trim sequence. CommandProvider::get_commands returns BaseCommand adapters whose name is read back over RPC after the PHP constructor ran configure(); executing one still needs the PHP-side Symfony Application and stays an explicit error. The is_array / instanceof BaseCommand checks that upstream's Application::getPluginCommands performs on the raw getCommands value live in the adapter, because Vec> asserts every element up front. Ports testCommandProviderCapability (plugin-v8 end to end against the real worker) and testQueryingWithInvalidCapabilityClassNameThrows (all eight provider cases); the two tests that pass a PHPUnit mock plugin into PHP stay ignored — a Rust-native mock has no PHP-side entity to cross the boundary as $ctorArgs['plugin']. Co-Authored-By: Claude Fable 5 --- crates/shirabe/src/plugin/capability/capability.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'crates/shirabe/src/plugin/capability/capability.rs') diff --git a/crates/shirabe/src/plugin/capability/capability.rs b/crates/shirabe/src/plugin/capability/capability.rs index 1788d9a0..aa70ffa0 100644 --- a/crates/shirabe/src/plugin/capability/capability.rs +++ b/crates/shirabe/src/plugin/capability/capability.rs @@ -1,4 +1,14 @@ //! ref: composer/src/Composer/Plugin/Capability/Capability.php -// TODO(plugin): Marker interface for Plugin capabilities. Every new Capability which is added to the Plugin API must implement this interface. -pub trait Capability {} +use crate::plugin::capability::CommandProvider; + +/// Marker interface for Plugin capabilities. Every new Capability which is added to the +/// Plugin API must implement this interface. +/// +/// The accessor replaces PHP's `instanceof` downcast on a capability instance of unknown +/// concrete type (the way `PluginInterface::as_capable` does for plugins). +pub trait Capability { + fn as_command_provider(&self) -> Option<&dyn CommandProvider> { + None + } +} -- cgit v1.3.1