Skip to content

Fix: forward active alias to runcommand subprocess#6272

Merged
swissspidy merged 3 commits intomainfrom
copilot/fix-wpcli-runcommand-issue
Mar 16, 2026
Merged

Fix: forward active alias to runcommand subprocess#6272
swissspidy merged 3 commits intomainfrom
copilot/fix-wpcli-runcommand-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 14, 2026

  • Fix WP_CLI::runcommand() (launch=true path): prepend current alias before runtime_config in command string
  • Add Behat test verifying alias is forwarded when launching a subprocess: WP is in foo/, alias @foo sets the path, subprocess spawned by runcommand --launch uses the alias to find WP (without the fix, the subprocess has no alias and fails with "No WordPress installation found")
  • Fix CI failure: removed from 'bar' step that caused "Alias 'foo' not found" in CI — the test now runs from the test root where the project config with @foo is directly present, while still properly testing the fix (WP installation is only in foo/, so the subprocess must use the forwarded alias to locate it)
  • All lint, PHPCS, and PHPStan checks pass
Original prompt

This section details on the original issue you should resolve

<issue_title>WP_CLI::runcommand() and WP_CLI::launch_self() should use Runner::$alias in command string</issue_title>
<issue_description>Describe how other contributors can replicate this bug

Register commands

add_action(
	'cli_init',
	function () {
		WP_CLI::add_command(
			'first',
			function () {
				WP_CLI::runcommand( 'second' );
			}
		);

		WP_CLI::add_command(
			'second',
			function () {
				WP_CLI::log( 'second' );
			}
		);
	}
);

setup alias in ~/.wp-cli/config.yml

@wp:
  path: [PATH_TO_PROJECT]

and run wp @wp first not from current project directory.

Describe what you expect as the correct outcome

Expect second output but has warning No WordPress installation found

Provide a possible solution

wp-cli/php/class-wp-cli.php

Lines 1333 to 1335 in f94e77d

$runtime_config = Utils\assoc_args_to_str( $runtime_config );
$runcommand = "{$php_bin} {$script_path} {$runtime_config} {$command}";

Should add current alias to $runcommand string.
</issue_description>

<agent_instructions>See also https://gist.github.com/danielbachhuber/d11c00cf3229a9074b3b5bc0d1f23cd5</agent_instructions>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] [WP-CLI] Fix runner alias usage in WP_CLI commands Fix: forward active alias to runcommand subprocess Mar 14, 2026
Copilot AI requested a review from swissspidy March 14, 2026 22:37
@swissspidy

This comment was marked as resolved.

…nd in CI

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

This comment was marked as resolved.

@swissspidy swissspidy closed this Mar 15, 2026
@swissspidy swissspidy reopened this Mar 15, 2026
@swissspidy swissspidy marked this pull request as ready for review March 15, 2026 09:20
@swissspidy swissspidy requested a review from a team as a code owner March 15, 2026 09:20
Copilot AI review requested due to automatic review settings March 15, 2026 09:20
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

This PR fixes WP_CLI::runcommand() when launch=true so that spawned subprocesses retain the active alias context (e.g. @foo), ensuring the child process resolves the same WordPress installation as the parent.

Changes:

  • Prepend the active Runner alias (when present) to the spawned subprocess command in WP_CLI::runcommand()’s --launch path.
  • Add a Behat scenario ensuring an alias-defined path is honored by the launched subprocess.

Reviewed changes

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

File Description
php/class-wp-cli.php Prepends active alias to the subprocess command string for runcommand(..., ['launch' => true]).
features/runcommand.feature Adds coverage to verify alias context is preserved across a --launch subprocess.

💡 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.

Comment on lines +1595 to +1598
$alias_prefix = '@' . $alias . ' ';
}

$runcommand = "{$php_bin} {$script_path} {$alias_prefix}{$runtime_config} {$command}";
@swissspidy swissspidy merged commit e9ad35f into main Mar 16, 2026
73 checks passed
@swissspidy swissspidy deleted the copilot/fix-wpcli-runcommand-issue branch March 16, 2026 10:00
@swissspidy swissspidy added this to the 3.0.0 milestone Mar 16, 2026
swissspidy added a commit to apermo/wp-cli that referenced this pull request Mar 16, 2026
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.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.

WP_CLI::runcommand() and WP_CLI::launch_self() should use Runner::$alias in command string

3 participants