fix: keep MU-Migration WP-CLI shim out of autoloaders#1628
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe change excludes MU-Migration classes from Composer and Jetpack classmaps, updates the WP Ultimo autoloader plugin’s classmap handling, and adds a regression test confirming the WP-CLI polyfill is not autoloadable. ChangesMU-Migration autoload handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Composer
participant modifyJetpackAutoloader
participant Autoloader_Test
Composer->>modifyJetpackAutoloader: Provide generated classmap
modifyJetpackAutoloader->>modifyJetpackAutoloader: Filter MU-Migration entries
modifyJetpackAutoloader-->>Composer: Write modified classmap
Autoloader_Test->>Composer: Resolve WP_CLI
Composer-->>Autoloader_Test: WP_CLI is not autoloadable
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php (1)
124-140: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winRegex is fragile against Jetpack classmap format changes.
The regex on line 136 assumes specific formatting (tabs,
array()syntax, field orderingversionthenpath). If a future Jetpack Autoloader version changes its classmap format — e.g., switching to[]short array syntax, different indentation, or reordered fields — the regex will silently fail to match, leaving MU-Migration entries in the classmap. Theis_string($filtered)fallback on line 139 ensures safety (no crash), but the exclusion would be silently ineffective.Consider adding a log warning when the regex doesn't match any entries, so a format change is detectable rather than silent.
♻️ Suggested: log when no entries are removed
private function exclude_mu_migration_from_jetpack_classmap($content) { $pattern = "/\n\t'[^']+' => array\(\n\t\t'version' => '[^']+',\n\t\t'path'\s*=> [^\n]*\\/inc\\/site-exporter\\/mu-migration\\/[^\n]*\n\t\),/"; $filtered = preg_replace($pattern, '', $content); - return is_string($filtered) ? $filtered : $content; + if ( ! is_string($filtered) ) { + return $content; + } + + if ( $filtered === $content && strpos($content, 'mu-migration') !== false ) { + $this->io->write('<warning> MU-Migration entries found in Jetpack classmap but regex did not match — classmap format may have changed.</warning>'); + } + + return $filtered; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php` around lines 124 - 140, Update exclude_mu_migration_from_jetpack_classmap to detect when the MU-Migration exclusion pattern removes no entries and emit a warning through the plugin’s existing logging mechanism. Preserve the current content fallback when preg_replace fails, and ensure the warning only signals an unmatched or unsupported classmap format rather than normal successful removal.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/WP_Ultimo/Autoloader_Test.php`:
- Around line 66-74: Update the skip condition in
test_mu_migration_wp_cli_polyfill_is_not_autoloadable to use
class_exists('WP_CLI', false) instead of checking the WP_CLI constant, so the
test skips when the real WP-CLI class is already loaded. Preserve the existing
skip message and assertions.
---
Nitpick comments:
In
`@composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php`:
- Around line 124-140: Update exclude_mu_migration_from_jetpack_classmap to
detect when the MU-Migration exclusion pattern removes no entries and emit a
warning through the plugin’s existing logging mechanism. Preserve the current
content fallback when preg_replace fails, and ensure the warning only signals an
unmatched or unsupported classmap format rather than normal successful removal.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 44fe293a-629a-4c1d-a567-a807843e3947
⛔ Files ignored due to path filters (1)
composer.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
composer-plugins/wp-ultimo-autoloader-plugin/composer.jsoncomposer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.phpcomposer.jsontests/WP_Ultimo/Autoloader_Test.php
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
|
Performance Test Results Performance test results for 9c37294 are in 🛎️! |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
Summary
wp-ultimo/autoloader-pluginJetpack Autoloader workaround to strip MU-Migration entries until Autoloader: extract exclude-from-classmap patterns from root package Automattic/jetpack#46627 is available.class_exists( 'WP_CLI' )not autoloading the fake facade.Why
The 2.14.0/2.14.1 package could expose the bundled fake global
WP_CLIfacade through generated autoload maps. Third-party plugins that useclass_exists( 'WP_CLI' )as a CLI detector can then load CLI-only code during web/bootstrap requests.Verification
composer dump-autoload --optimizeWP_CLI,WP_CLI_Command, orinc/site-exporter/mu-migrationentries.class_exists( 'WP_CLI' )stays false, explicit polyfill require still works.class_exists( 'WP_CLI' )stays false.vendor/bin/phpcs composer-plugins/wp-ultimo-autoloader-plugin/src/class-wp-ultimo-autoloader-plugin.php tests/WP_Ultimo/Autoloader_Test.phpphp -lfor touched PHP files.composer validate --no-check-publish(warnings only for existing package metadata).wp php-errorsproduced no fatal output.Note
vendor/bin/phpunit --filter Autoloader_Testis blocked locally because the WordPress test library is not installed.aidevops.sh v3.32.32 plugin for OpenCode v1.17.18
Summary by CodeRabbit