Skip to content

Fix autoloader priority: locally installed packages now fully override phar-bundled versions#6218

Merged
swissspidy merged 10 commits intomainfrom
copilot/fix-export-command-override-issue
Mar 13, 2026
Merged

Fix autoloader priority: locally installed packages now fully override phar-bundled versions#6218
swissspidy merged 10 commits intomainfrom
copilot/fix-export-command-override-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 2, 2026

Plan: Fix locally installed packages not overriding phar-bundled versions

  • Understand the issue: autoloader priority problem
  • Identify root cause: bootstrap order loads framework before packages
  • Modify bootstrap order: swap IncludeFallbackAutoloader and IncludePackageAutoloader
  • Verify fix with test script showing correct order
  • Run linting (passed)
  • Run code style checks (passed)
  • Run static analysis (passed)
  • Run unit tests (passed, network failures unrelated)
  • Add comprehensive test for package override behavior
  • Fix test to use wp debug output instead of manual require
  • Run code review (addressed comments)
  • Run security scan (no issues)

Summary

Successfully fixed the issue where locally installed packages (via wp package install) only partially override phar-bundled versions. The solution was to swap the bootstrap order of IncludeFallbackAutoloader and IncludePackageAutoloader, ensuring that packages registered last get autoloader priority.

The test now uses wp cli version --debug to verify both autoloaders are loaded, instead of manually requiring bootstrap.php which doesn't work in the test environment.

Security Summary

No security vulnerabilities were introduced or discovered during this change.

Original prompt

This section details on the original issue you should resolve

<issue_title>Locally installed export-command should override phar-bundled version</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

Package is only very partially overridden by classes from a locally installed version of the package (classes from ~/.wp-cli/packages/vendor/wp-cli/export-command)

Describe how other contributors can replicate this bug

sudo curl -sLo wp https://github.com/wp-cli/wp-cli/.../wp-cli-1.5.0.phar && chmod +x ./wp
wp package install https://github.com/wp-cli/export-command.git ## <---- We override export-command
./wp eval "var_dump((new \ReflectionClass('\WP_Export_WXR_Formatter'))->getFileName(),
                    (new \ReflectionClass('\Export_Command'))->getFileName());"

Actual result

phar://./wp/vendor/wp-cli/export-command/src/WP_Export_WXR_Formatter.php
~/.wp-cli/packages/vendor/wp-cli/export-command/src/Export_Command.php

Desired result

~/.wp-cli/packages/vendor/wp-cli/export-command/src/WP_Export_WXR_Formatter.php
~/.wp-cli/packages/vendor/wp-cli/export-command/src/Export_Command.php

</issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera We've did fixes in that particular subsystem to make overriding behave more consistently. Can you confirm this also happens with the latest WP-CLI v2.2.0 ? @ernilambar I also can confirm this as I am able to reproduce the issue with given information.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 2, 2026 01:35
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix locally installed export-command override issue Fix autoloader priority: locally installed packages now fully override phar-bundled versions Feb 2, 2026
Copilot AI requested a review from swissspidy February 2, 2026 01:37
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/bootstrap.php 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review March 13, 2026 08:26
@swissspidy swissspidy requested a review from a team as a code owner March 13, 2026 08:27
Copilot AI review requested due to automatic review settings March 13, 2026 08:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes WP-CLI bootstrap autoloader precedence so locally installed packages (via wp package install) can fully override phar-bundled packages/classes.

Changes:

  • Swaps bootstrap step order so IncludeFallbackAutoloader runs before IncludePackageAutoloader.
  • Adds a Behat scenario intended to validate the bootstrap/autoloader behavior via --debug output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
php/bootstrap.php Reorders bootstrap steps to give locally installed package autoloaders higher precedence.
features/bootstrap.feature Adds coverage for the expected autoloader behavior using debug output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@swissspidy swissspidy added this to the 3.0.0 milestone Mar 13, 2026
@swissspidy swissspidy merged commit b4bad01 into main Mar 13, 2026
68 of 69 checks passed
@swissspidy swissspidy deleted the copilot/fix-export-command-override-issue branch March 13, 2026 10:48
swissspidy added a commit to apermo/wp-cli that referenced this pull request Mar 16, 2026
…e phar-bundled versions (wp-cli#6218)

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Pascal Birchler <pascalb@google.com>
swissspidy added a commit that referenced this pull request Mar 16, 2026
…6270)

* fix(context): resolve admin user dynamically

Replace hardcoded user ID 1 fallback in Admin
context with smart user resolution. On multisite,
queries get_super_admins() to find a valid super
admin. On single site, queries for the first user
with the administrator role. Emits a clear error
if no suitable user is found.

Fixes #6269

* fix(context): optimize query and add test cases

Use get_users() with login__in for single DB query
instead of looping get_user_by(). Add single-site
error case test. Replace wp super-admin commands
with direct option manipulation in tests.

* fix(context): fix linting issues

Use single quotes for strings per PHPCS rules.
Fix gherkin use-and lint violations by replacing
consecutive When steps with And.

* fix(context): address review feedback

Revert multisite super admin lookup from get_users()
back to foreach + get_user_by('login') loop because
get_users() only fetches users on the current site
but a super admin might not be a member of any site.

Add debug logging after resolving admin user ID.

* fix(context): use instanceof for type safety

* Fix autoloader priority: locally installed packages now fully override phar-bundled versions (#6218)

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Pascal Birchler <pascalb@google.com>

* Add environment variable configuration support to wp-cli.yml (#6169)

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Pascal Birchler <pascalb@google.com>

* Autocomplete `--url` (#5704)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Pascal Birchler <pascalb@google.com>
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>

* Add WP-CLI handbook link to `wp help` output (#6273)

* Initial plan

* Add WP-CLI handbook URL reference to wp help output

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

* Update file(s) from wp-cli/.github

* Update file(s) from wp-cli/.github

* Fix SSH alias path not forwarded to remote when defined as a separate config key (#6274)

* Initial plan

* Fix SSH alias path not forwarded to remote when path is a separate config key

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

* Fix: forward active alias to runcommand subprocess (#6272)

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

* Fix vagrant SSH strict host key checking failure (#6275)

* Initial plan

* Fix vagrant SSH strict host key checking failure

When ssh: vagrant is configured and vagrant ssh-config is parsed,
add -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null to
the SSH command to match what vagrant itself sets. This prevents
failures when the vagrant VM has been recreated and has a different
host key than what is stored in ~/.ssh/known_hosts.

Adds a Behat test scenario to verify the fix.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Apply suggestion from @swissspidy

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: Pascal Birchler <pascalb@google.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Add optional `$newline` parameter to `WP_CLI::log()` and `WP_CLI::line()` (#6276)

* Initial plan

* Add optional $newline parameter to WP_CLI::log(), WP_CLI::line(), and logger info() methods

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

* Undo Base class change

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: Pascal Birchler <pascalb@google.com>

* Refactor: remove unused imports (#6277)

* Harden some tests on macOS

* Update tests

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Pascal Birchler <pascalb@google.com>
Co-authored-by: Ian Dunn <ian@iandunn.name>
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
Co-authored-by: swissspidy <swissspidy@users.noreply.github.com>
Co-authored-by: Sören Wünsch <soerenwrede@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Locally installed export-command should override phar-bundled version

3 participants