Skip to content

Fix ssh option with docker scheme ignored when set at root of wp-cli.yml#6249

Open
Copilot wants to merge 13 commits intomainfrom
copilot/fix-ssh-option-docker-scheme
Open

Fix ssh option with docker scheme ignored when set at root of wp-cli.yml#6249
Copilot wants to merge 13 commits intomainfrom
copilot/fix-ssh-option-docker-scheme

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 25, 2026

  • Fix Configurator.php: allow root-level ssh to apply as default for aliased commands
  • Fix Runner.php: add WP_CLI_SSH_RUN=1 to env vars in run_ssh_command for SSH/docker/docker-compose schemes
  • Fix Runner.php: propagate WP_CLI_SSH_RUN=1 via -e flag for docker-compose-run scheme in generate_ssh_command()
  • Fix Runner.php: check WP_CLI_SSH_RUN in start() to skip config-based ssh when already in an SSH/container session
  • Add Behat tests for root-level ssh with docker scheme (with and without alias)
  • Update existing Behat SSH command assertions for WP_CLI_SSH_RUN=1 in flags.feature
  • Update existing Behat SSH command assertions for WP_CLI_SSH_RUN=1 in aliases.feature (vagrant, double-escape, space-escape, runtime alias x2)
  • Fix Runner.php: sprintf placeholder count mismatch in docker-compose-run format string (8 placeholders, 9 values)
Original prompt

This section details on the original issue you should resolve

<issue_title>The ssh option doesn't accept a docker scheme when used in the root of a config file</issue_title>
<issue_description>- [x] Yes, I reviewed the contribution guidelines.

Describe the current, buggy behavior

Given a Docker container called myproject_php_1 that can run WP-CLI commands, the following works as expected:

✅ Including the --ssh flag on the CLI:

wp option get home --ssh=docker:www-data@myproject_php_1`

✅ Using the ssh option for an alias in wp-cli.yml:

---
@local:
  ssh: docker:www-data@myproject_php_1
wp @local option get home

However, the following does not work:

❌ Using the ssh option in the root of wp-cli/yml:

ssh: docker:www-data@myproject_php_1
wp @local option get home

This results in the following error:

sh: docker: not found

I don't have much more info at the moment but wanted to report it. I can revisit this when I'm less busy.</issue_description>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Runner.php 0.00% 10 Missing ⚠️
php/WP_CLI/Configurator.php 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

- Configurator.php: Allow root-level `ssh` key to apply as default for aliased
  commands by excluding it from the alias-spec skip in merge_yml()
- Runner.php: Add WP_CLI_SSH_RUN=1 env var to remote commands to prevent
  recursive SSH/docker calls when config file is mounted inside a container
- Runner.php: Check WP_CLI_SSH_RUN in start() to skip config-based SSH when
  already inside an SSH/container session (CLI --ssh= still works)
- flags.feature: Update existing SSH test assertions and add two new scenarios
  for root-level docker SSH config (with and without alias)

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ssh option not accepting docker scheme in config file Fix ssh option with docker scheme ignored when set at root of wp-cli.yml Feb 25, 2026
@swissspidy swissspidy requested a review from Copilot February 26, 2026 00:24
@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

This comment was marked as resolved.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
For the docker-compose-run scheme, $wp_command was overwritten with
implode(' ', $wp_args), dropping $env_vars. Since docker compose run
doesn't invoke a shell, env var assignment prefix syntax doesn't work.
Instead, pass WP_CLI_SSH_RUN=1 (and WP_CLI_STRICT_ARGS_MODE=1 if set)
via -e flags on the `docker compose run` command itself.

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

This comment was marked as resolved.

Since run_ssh_command() now prepends WP_CLI_SSH_RUN=1 to the remote
command, update five assertions in aliases.feature that check the
exact SSH debug output to include WP_CLI_SSH_RUN=1:
- Vagrant SSH test: 'wp --debug --version' → 'WP_CLI_SSH_RUN=1 wp ...'
- Double-escape test: '; wp plugin list' → '; WP_CLI_SSH_RUN=1 wp ...'
- Space-escape test: '; wp post create' → '; WP_CLI_SSH_RUN=1 wp ...'
- Runtime alias tests (x2): 'env WP_CLI_RUNTIME_ALIAS= →
  'WP_CLI_SSH_RUN=1 env WP_CLI_RUNTIME_ALIAS=

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

This comment was marked as resolved.

Copilot AI requested a review from swissspidy March 16, 2026 21:49
@swissspidy

This comment was marked as resolved.

The two SSH args test scenarios were checking for 'wp at the end of
the SSH command string, but now the command includes WP_CLI_SSH_RUN=1
before wp. Update the assertions to match.

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

This comment was marked as resolved.

The format string for docker-compose-run had 8 %s placeholders but
9 values were passed (added $env_flags without adding a corresponding
placeholder). Add the missing %s to the format string.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI requested a review from swissspidy March 17, 2026 14:36
@swissspidy swissspidy marked this pull request as ready for review March 17, 2026 15:35
@swissspidy swissspidy requested a review from a team as a code owner March 17, 2026 15:35
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

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


💡 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 +835 to +839
$command = '%s run %s%s%s%s%s%s%s %s';

$env_flags = '-e WP_CLI_SSH_RUN=1 ';
if ( getenv( 'WP_CLI_STRICT_ARGS_MODE' ) ) {
$env_flags .= '-e WP_CLI_STRICT_ARGS_MODE=1 ';
Comment on lines 1556 to +1560
if ( $this->config['ssh'] ) {
// @phpstan-ignore cast.string
$this->run_ssh_command( (string) $this->config['ssh'] );
return;
// Don't recurse if SSH came from config file and we're already in an SSH/container session.
// Still allow SSH if it was explicitly passed via --ssh= on the CLI (present in runtime_config).
$ssh_from_cli = isset( $this->runtime_config['ssh'] ) && '' !== $this->runtime_config['ssh'];
if ( getenv( 'WP_CLI_SSH_RUN' ) && ! $ssh_from_cli ) {
Comment on lines 834 to +840
if ( 'docker-compose-run' === $bits['scheme'] ) {
$command = '%s run %s%s%s%s%s%s %s';
$command = '%s run %s%s%s%s%s%s%s %s';

$env_flags = '-e WP_CLI_SSH_RUN=1 ';
if ( getenv( 'WP_CLI_STRICT_ARGS_MODE' ) ) {
$env_flags .= '-e WP_CLI_STRICT_ARGS_MODE=1 ';
}
swissspidy and others added 2 commits March 20, 2026 23:54
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.

The ssh option doesn't accept a docker scheme when used in the root of a config file

3 participants