Fix phar path resolution when renamed from wp-cli.phar#872
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix wp-config.mustache file not found in phar
Fix phar path resolution when renamed from wp-cli.phar
Feb 15, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
schlessera
force-pushed
the
copilot/fix-wp-config-mustache-file
branch
from
July 21, 2026 09:48
f49c248 to
9708a3a
Compare
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Member
|
Closing as per latest update on wp-cli/wp-cli#6242 |
Member
|
Actually, still needed because of the test. |
A Phar renamed away from `wp-cli.phar` used to build malformed template paths when generating a wp-config.php for an install in another directory via --path, failing with "wp-config.mustache is not a file in phar". Add a Bootstrap scenario that copies the freshly built Phar to a name without an extension and runs `config create --path=subfolder` against a separate install, so the fixed behavior is locked in and regressions are caught. The fix itself lives in wp-cli/wp-cli's Path::phar_safe(), which the bundled Phar picks up through the framework. See wp-cli/config-command#141.
Updates the pinned dev-main reference to 63fb80e (wp-cli/wp-cli#6242), which makes `Path::phar_safe()` resolve templates and assets correctly for a Phar renamed off `wp-cli.phar`. This turns the Bootstrap Behat scenario added in this PR green.
schlessera
force-pushed
the
copilot/fix-wp-config-mustache-file
branch
from
July 21, 2026 14:09
871a549 to
6bc67e4
Compare
schlessera
marked this pull request as ready for review
July 21, 2026 14:23
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
EDIT (2026-07-21): Reworked and rebased onto the current
main. This PR now contains only the Bootstrap regression test: it copies the freshly built Phar to a name without an extension and runsconfig create --path=subfolderagainst a separate install, reproducing the reported failure.Dropped from the earlier approach:
php/boot-phar.phpchange (Phar::running( true )→false). The fix now lives entirely in Fix phar path resolution when WP_CLI_PHAR_PATH includes phar:// prefix wp-cli#6242'sPath::phar_safe(), which handlesWP_CLI_PHAR_PATHwhether it is a bare path or aphar://URL, so no bundle code change is needed. KeepingPhar::running( true )also avoids changing the valuewp cli inforeports.cweagans/composer-patchesplugin and patch file, and the temporarywp-cli/wp-clibranch pin plus the resultingcomposer.lockchurn. This PR carries no dependency changes.Merge sequencing: the fix ships in wp-cli/wp-cli#6242. Once that is merged and the framework is bumped in this repo (the usual
update-frameworkflow), this scenario goes green. It may be red until then, which is expected for a companion test.Original description (now outdated)Fix phar path resolution when phar file is not named "wp-cli.phar"
Problem
When running
wp config create --path=subfolder ...with a phar file named something other than "wp-cli.phar" (e.g., "wp"), the path resolution fails with a malformed path error. Additionally, template loading fails with "Couldn't find plugin-status.mustache" errors.Root Cause
Two issues were present:
WP_CLI_PHAR_PATHwas set usingPhar::running(true)which returns"phar:///path/to/file.phar", causingphar_safe_path()to search for the malformed string"phar://phar:///path/to/file.phar/"phar_safe_path()in wp-cli/wp-cli was replacing full paths with bare"phar://"instead of the alias"phar://wp-cli.phar/", causing template paths like"phar://vendor/..."which don't resolve without an archive nameSolution
WP_CLI_PHAR_PATHin boot-phar.php to usePhar::running(false)which returns the filesystem path withoutphar://protocol (e.g.,"/path/to/file.phar")cweagans/composer-patchesplugin to apply a patch to wp-cli/wp-cli'sphar_safe_path()functionpatches/wp-cli-phar-safe-path.patchthat fixes the replacement to use'phar://wp-cli.phar/'instead of bare'phar://'This ensures:
phar_safe_path()correctly converts"phar:///tmp/some.phar/vendor/..."to"phar://wp-cli.phar/vendor/..."Changes Made
Note
The patch will be removed once the fix in wp-cli/wp-cli#6242 is merged and the dependency is updated. The patch is automatically applied during
composer installand modifies the vendored wp-cli/wp-cli code at build time.Original prompt
This section details on the original issue you should resolve
<issue_title>wp-config.mustache is not a file in phar</issue_title>
<issue_description>## Bug Report
Describe the current, buggy behavior
When wp-cli.phar is renamed to wp and moved into a path location, --path option seems to have conflict with wp create command. This has been reported before (#31)
Describe how other contributors can replicate this bug
However, with just a cd to the subfolder, it works just fine:
Also, if I rename wp to wp-cli.phar, it works:
Describe what you would expect as the correct outcome
Let us know what environment you are running this on