Skip to content

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

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-export-command-override-issue
Draft

Fix autoloader priority: locally installed packages now fully override phar-bundled versions#6218
Copilot wants to merge 5 commits intomainfrom
copilot/fix-export-command-override-issue

Conversation

Copy link
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

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
Copy link
Member

@copilot the "Package autoloader has priority over fallback autoloader" test is now failing

001 Scenario: Package autoloader has priority over fallback autoloader # features/bootstrap.feature:542
      When I run `php test-bootstrap-order.php`                        # features/bootstrap.feature:565
        $ php test-bootstrap-order.php
        
        Warning: require_once(/tmp/wp-cli-test-run--69801709317d70.62570074/../../php/bootstrap.php): failed to open stream: No such file or directory in /tmp/wp-cli-test-run--69801709317d70.62570074/test-bootstrap-order.php on line 4
        
        Fatal error: require_once(): Failed opening required '/tmp/wp-cli-test-run--69801709317d70.62570074/../../php/bootstrap.php' (include_path='.:/usr/share/php') in /tmp/wp-cli-test-run--69801709317d70.62570074/test-bootstrap-order.php on line 4
        
        PHP Warning:  require_once(/tmp/wp-cli-test-run--69801709317d70.62570074/../../php/bootstrap.php): failed to open stream: No such file or directory in /tmp/wp-cli-test-run--69801709317d70.62570074/test-bootstrap-order.php on line 4
        PHP Fatal error:  require_once(): Failed opening required '/tmp/wp-cli-test-run--69801709317d70.62570074/../../php/bootstrap.php' (include_path='.:/usr/share/php') in /tmp/wp-cli-test-run--69801709317d70.62570074/test-bootstrap-order.php on line 4
        cwd: /tmp/wp-cli-test-run--69801709317d70.62570074/
        run time: 0.040348052978516
        exit status: 255 (RuntimeException)

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

Copilot AI commented Feb 3, 2026

@copilot the "Package autoloader has priority over fallback autoloader" test is now failing

...

Fixed in c7ee1a2. The test now uses wp cli version --debug to verify both autoloaders are loaded, instead of manually requiring bootstrap.php with a relative path that doesn't work in the test environment.

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

2 participants