Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions features/shell.feature
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ Feature: WordPress REPL
"""
And STDERR should be empty

Scenario: Use SHELL environment variable as fallback
Given a WP install

And a session file:
"""
return true;
"""

When I try `SHELL=/bin/bash wp shell --basic < session`
Then STDOUT should contain:
"""
bool(true)
"""
And STDERR should be empty
Comment on lines +64 to +77
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

This scenario doesn't clearly validate the new behavior of preferring $SHELL, because setting SHELL=/bin/bash matches the existing hardcoded fallback and would succeed even without the code change. Consider asserting a bash path that differs from /bin/bash (e.g. via a resolved bash path) or otherwise structuring the test so it fails on the old behavior but passes on the new one.

Copilot uses AI. Check for mistakes.

When I try `SHELL=/nonsense/path wp shell --basic < session`
Then STDOUT should contain:
"""
bool(true)
"""
And STDERR should be empty

Scenario: Input starting with dash
Given a WP install
And a session file:
Expand Down
2 changes: 2 additions & 0 deletions src/WP_CLI/Shell/REPL.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ private static function create_prompt_cmd( $prompt, $history_path ) {
$history_path = escapeshellarg( $history_path );
if ( getenv( 'WP_CLI_CUSTOM_SHELL' ) ) {
$shell_binary = getenv( 'WP_CLI_CUSTOM_SHELL' );
} elseif ( getenv( 'SHELL' ) ) {
$shell_binary = getenv( 'SHELL' );
} else {
$shell_binary = '/bin/bash';
Comment on lines 123 to 128
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

Using the SHELL environment variable as the default shell can break wp shell for users whose login shell is not bash (e.g. zsh/fish). create_prompt_cmd() builds a bash-specific command (history -r/-s/-w, read -re), so selecting a non-bash SHELL will pass the is_file/is_readable check but then fail at runtime. Consider preferring a known bash binary first (e.g. /bin/bash when it exists), and only falling back to SHELL when /bin/bash is unavailable or when SHELL points to a bash binary (e.g. basename is bash), or probe for bash on PATH.

Copilot uses AI. Check for mistakes.
}
Expand Down
Loading