From 261516d5ce6f8b0d69cf9e3da7dd2f0ef1cdc36a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 4 Aug 2026 03:36:10 +0900 Subject: feat(plugin): generate the worker proxy stubs from the Composer sources Replace the hand-written proxy stubs under crates/shirabe-php-rpc/php/stubs with output of scripts/plugin-stub-generator, a deterministic emitter that derives every stub from the Composer checkout and the classifier report. Anything it cannot faithfully proxy (by-ref/variadic parameters, magic methods, public properties, diverging omitted overrides, stale stub files, a STUB_FILES entry missing in lib.rs) fails generation instead of degrading silently, so future Composer releases surface new members as explicit errors rather than silent gaps. Regenerating the stubs also normalizes the hand-written inconsistencies (uniform guarded constructors, import-based type spellings) and fixes real gaps the review of the generated diff uncovered: the BaseIO authentication methods now carry the real class's untyped signatures, and the previously missing ConsoleIO::sanitize is materialized together with its private static helper. A cargo test runs generate-stubs --check to keep the committed stubs, the generator and the embedded list from drifting apart. Co-Authored-By: Claude Fable 5 --- .../php/stubs/Composer/Composer.php | 11 ++--- .../php/stubs/Composer/EventDispatcher/Event.php | 14 ++++-- .../php/stubs/Composer/IO/BaseIO.php | 22 ++++----- .../php/stubs/Composer/IO/BufferIO.php | 4 +- .../php/stubs/Composer/IO/ConsoleIO.php | 53 ++++++++++++++++++++-- .../php/stubs/Composer/IO/NullIO.php | 4 +- .../php/stubs/Composer/PartialComposer.php | 13 ++---- .../php/stubs/Composer/Script/Event.php | 10 ++-- 8 files changed, 91 insertions(+), 40 deletions(-) (limited to 'crates/shirabe-php-rpc/php/stubs') diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Composer.php b/crates/shirabe-php-rpc/php/stubs/Composer/Composer.php index 1bb9f64c..de5a6d1b 100644 --- a/crates/shirabe-php-rpc/php/stubs/Composer/Composer.php +++ b/crates/shirabe-php-rpc/php/stubs/Composer/Composer.php @@ -1,17 +1,16 @@ __rhandle = $rhandle; $this->__epoch = $epoch; } diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/IO/BaseIO.php b/crates/shirabe-php-rpc/php/stubs/Composer/IO/BaseIO.php index 51cdbe08..55da6415 100644 --- a/crates/shirabe-php-rpc/php/stubs/Composer/IO/BaseIO.php +++ b/crates/shirabe-php-rpc/php/stubs/Composer/IO/BaseIO.php @@ -1,9 +1,7 @@ __rhandle, 'getAuthentications', []); } - public function resetAuthentications() - { - return \ShirabeRpcRuntime::callRust($this->__rhandle, 'resetAuthentications', []); - } - - public function hasAuthentication(string $repositoryName) + public function hasAuthentication($repositoryName) { return \ShirabeRpcRuntime::callRust($this->__rhandle, 'hasAuthentication', [$repositoryName]); } - public function getAuthentication(string $repositoryName) + public function getAuthentication($repositoryName) { return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getAuthentication', [$repositoryName]); } - public function setAuthentication(string $repositoryName, string $username, ?string $password = null) + public function setAuthentication($repositoryName, $username, $password = null) { return \ShirabeRpcRuntime::callRust($this->__rhandle, 'setAuthentication', [$repositoryName, $username, $password]); } @@ -198,4 +191,9 @@ abstract class BaseIO implements IOInterface, \ShirabeRustStub { \ShirabeRpcRuntime::callRust($this->__rhandle, 'log', [$level, $message, $context]); } + + public function resetAuthentications() + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'resetAuthentications', []); + } } diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/IO/BufferIO.php b/crates/shirabe-php-rpc/php/stubs/Composer/IO/BufferIO.php index e95fb2da..d5e59e90 100644 --- a/crates/shirabe-php-rpc/php/stubs/Composer/IO/BufferIO.php +++ b/crates/shirabe-php-rpc/php/stubs/Composer/IO/BufferIO.php @@ -1,7 +1,7 @@ $message) { + $message = self::ensureValidUtf8($message); + $sanitized[$key] = Preg::replace($pattern, '', $message); + } + + return $sanitized; + } + + private static function ensureValidUtf8(string $string): string + { + // Quick check: if string is already valid UTF-8, return as-is + if (function_exists('mb_check_encoding') && mb_check_encoding($string, 'UTF-8')) { + return $string; + } + + // Use mb_convert_encoding to replace invalid sequences with '?' + // This makes it visible when data quality issues occur + if (function_exists('mb_convert_encoding')) { + return (string) mb_convert_encoding($string, 'UTF-8', 'UTF-8'); + } + + // Fallback to iconv if mbstring unavailable + if (function_exists('iconv')) { + $cleaned = @iconv('UTF-8', 'UTF-8//TRANSLIT', $string); + if ($cleaned !== false) { + return $cleaned; + } + } + + // Last resort: return as-is (should never happen - Composer requires mbstring OR iconv) + return $string; + } + public function enableDebugging(float $startTime) { return \ShirabeRpcRuntime::callRust($this->__rhandle, 'enableDebugging', [$startTime]); diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/IO/NullIO.php b/crates/shirabe-php-rpc/php/stubs/Composer/IO/NullIO.php index 92e01700..1234ad4a 100644 --- a/crates/shirabe-php-rpc/php/stubs/Composer/IO/NullIO.php +++ b/crates/shirabe-php-rpc/php/stubs/Composer/IO/NullIO.php @@ -1,7 +1,7 @@ __rhandle, 'getComposer', []); } - public function getIO(): \Composer\IO\IOInterface + public function getIO(): IOInterface { return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getIO', []); } -- cgit v1.3.1