From 3edda0ed556b7130182448271cbed949983f04ff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 15:23:19 +0000 Subject: [PATCH 01/17] Initial plan From 415fb600106c1bd1642590de21fecac47d4cd8c1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 15:36:31 +0000 Subject: [PATCH 02/17] Add --no-interaction option to package commands Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/package-install.feature | 30 +++++++++++++++++++++ features/package-update.feature | 20 ++++++++++++++ features/package.feature | 19 +++++++++++++ src/Package_Command.php | 46 +++++++++++++++++++++++++++++--- 4 files changed, 112 insertions(+), 3 deletions(-) diff --git a/features/package-install.feature b/features/package-install.feature index fe76b4c5..1733dd25 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -1102,3 +1102,33 @@ Feature: Install WP-CLI packages Error: ZipArchive failed to unzip 'package-dir/zero.zip': Not a zip archive (19). """ And STDOUT should be empty + + Scenario: Install a package with --no-interaction flag + Given an empty directory + And a composer.json file: + """ + { + "repositories": { + "test" : { + "type": "path", + "url": "./dummy-package/" + }, + "wp-cli": { + "type": "composer", + "url": "https://wp-cli.org/package-index/" + } + } + } + """ + And a dummy-package/composer.json file: + """ + { + "name": "wp-cli/test-package", + "description": "Test package for no-interaction flag" + } + """ + When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/test-package --no-interaction` + Then STDOUT should contain: + """ + Success: Package installed + """ diff --git a/features/package-update.feature b/features/package-update.feature index c5981277..42d064ee 100644 --- a/features/package-update.feature +++ b/features/package-update.feature @@ -98,3 +98,23 @@ Feature: Update WP-CLI packages """ Success: Packages updated. """ + + Scenario: Update packages with --no-interaction flag + Given an empty directory + + When I run `wp package install danielbachhuber/wp-cli-reset-post-date-command` + Then STDOUT should contain: + """ + Success: Package installed. + """ + + When I run `wp package update --no-interaction` + Then STDOUT should contain: + """ + Using Composer to update packages... + """ + And STDOUT should contain: + """ + Packages updated. + """ + And STDERR should be empty diff --git a/features/package.feature b/features/package.feature index a45218b4..290997c0 100644 --- a/features/package.feature +++ b/features/package.feature @@ -208,3 +208,22 @@ Feature: Manage WP-CLI packages """ {NO_SUCH_PACKAGE_COMPOSER_JSON} """ + + Scenario: Uninstall a package with --no-interaction flag + Given an empty directory + + When I run `wp package install runcommand/hook` + Then STDERR should be empty + + When I run `wp package uninstall runcommand/hook --no-interaction` + Then STDERR should be empty + And STDOUT should contain: + """ + Success: Uninstalled package. + """ + + When I run `wp package list` + Then STDOUT should not contain: + """ + runcommand/hook + """ diff --git a/src/Package_Command.php b/src/Package_Command.php index 9e13c0d6..1081bbcc 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -199,6 +199,9 @@ public function browse( $_, $assoc_args ) { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * + * [--no-interaction] + * : Do not ask any interactive questions. Useful for scripting. + * * ## EXAMPLES * * # Install a package hosted at a git URL. @@ -216,7 +219,12 @@ public function browse( $_, $assoc_args ) { public function install( $args, $assoc_args ) { list( $package_name ) = $args; - $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); + $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); + $no_interaction = (bool) Utils\get_flag_value( $assoc_args, 'no-interaction', false ); + + if ( $no_interaction ) { + $this->set_non_interactive_mode(); + } $this->set_composer_auth_env_var(); $git_package = false; @@ -503,6 +511,11 @@ public function path( $args ) { /** * Updates all installed WP-CLI packages to their latest version. * + * ## OPTIONS + * + * [--no-interaction] + * : Do not ask any interactive questions. Useful for scripting. + * * ## EXAMPLES * * $ wp package update @@ -519,7 +532,13 @@ public function path( $args ) { * --- * Success: Packages updated. */ - public function update() { + public function update( $_, $assoc_args = [] ) { + $no_interaction = (bool) Utils\get_flag_value( $assoc_args, 'no-interaction', false ); + + if ( $no_interaction ) { + $this->set_non_interactive_mode(); + } + $this->set_composer_auth_env_var(); $composer = $this->get_composer(); @@ -562,6 +581,9 @@ public function update() { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * + * [--no-interaction] + * : Do not ask any interactive questions. Useful for scripting. + * * ## EXAMPLES * * # Uninstall package. @@ -574,7 +596,12 @@ public function update() { public function uninstall( $args, $assoc_args ) { list( $package_name ) = $args; - $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); + $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); + $no_interaction = (bool) Utils\get_flag_value( $assoc_args, 'no-interaction', false ); + + if ( $no_interaction ) { + $this->set_non_interactive_mode(); + } $this->set_composer_auth_env_var(); $package = $this->get_installed_package_by_name( $package_name ); @@ -1478,4 +1505,17 @@ private function get_github_default_branch( $package_name, $insecure = false ) { return $default_branch; } + + /** + * Sets environment variables to enable non-interactive mode. + * + * This prevents Git from prompting for credentials (e.g., SSH passwords), + * which is useful for scripting and automation. + */ + private function set_non_interactive_mode() { + // Prevent Git from prompting for credentials + putenv( 'GIT_TERMINAL_PROMPT=0' ); + // Prevent SSH from prompting for passwords + putenv( 'GIT_SSH_COMMAND=ssh -o BatchMode=yes' ); + } } From f8ca62d9ae4d5390f00af293d743f0fff88c6048 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 15:39:11 +0000 Subject: [PATCH 03/17] Add documentation for update() parameters and putenv() usage Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Package_Command.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Package_Command.php b/src/Package_Command.php index 1081bbcc..72d9dabc 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -531,6 +531,9 @@ public function path( $args ) { * Generating autoload files * --- * Success: Packages updated. + * + * @param array $_ Unused positional arguments (none expected). + * @param array $assoc_args Associative array of options. */ public function update( $_, $assoc_args = [] ) { $no_interaction = (bool) Utils\get_flag_value( $assoc_args, 'no-interaction', false ); @@ -1511,6 +1514,10 @@ private function get_github_default_branch( $package_name, $insecure = false ) { * * This prevents Git from prompting for credentials (e.g., SSH passwords), * which is useful for scripting and automation. + * + * Note: This uses putenv() which affects the entire PHP process, including + * any Git operations spawned by Composer. This is intentional to ensure + * non-interactive behavior propagates to all child processes. */ private function set_non_interactive_mode() { // Prevent Git from prompting for credentials From e68d8d6770fa8a43eefc4d76a9763e8d583e0721 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 16:14:58 +0000 Subject: [PATCH 04/17] Change flag to 'interaction' with default true, keep --no-interaction in tests Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Package_Command.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 72d9dabc..3e74231a 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -199,7 +199,7 @@ public function browse( $_, $assoc_args ) { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * - * [--no-interaction] + * [--] * : Do not ask any interactive questions. Useful for scripting. * * ## EXAMPLES @@ -219,10 +219,10 @@ public function browse( $_, $assoc_args ) { public function install( $args, $assoc_args ) { list( $package_name ) = $args; - $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); - $no_interaction = (bool) Utils\get_flag_value( $assoc_args, 'no-interaction', false ); + $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); + $interaction = Utils\get_flag_value( $assoc_args, 'interaction', true ); - if ( $no_interaction ) { + if ( ! $interaction ) { $this->set_non_interactive_mode(); } @@ -513,7 +513,7 @@ public function path( $args ) { * * ## OPTIONS * - * [--no-interaction] + * [--] * : Do not ask any interactive questions. Useful for scripting. * * ## EXAMPLES @@ -536,9 +536,9 @@ public function path( $args ) { * @param array $assoc_args Associative array of options. */ public function update( $_, $assoc_args = [] ) { - $no_interaction = (bool) Utils\get_flag_value( $assoc_args, 'no-interaction', false ); + $interaction = Utils\get_flag_value( $assoc_args, 'interaction', true ); - if ( $no_interaction ) { + if ( ! $interaction ) { $this->set_non_interactive_mode(); } @@ -584,7 +584,7 @@ public function update( $_, $assoc_args = [] ) { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * - * [--no-interaction] + * [--] * : Do not ask any interactive questions. Useful for scripting. * * ## EXAMPLES @@ -599,10 +599,10 @@ public function update( $_, $assoc_args = [] ) { public function uninstall( $args, $assoc_args ) { list( $package_name ) = $args; - $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); - $no_interaction = (bool) Utils\get_flag_value( $assoc_args, 'no-interaction', false ); + $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); + $interaction = Utils\get_flag_value( $assoc_args, 'interaction', true ); - if ( $no_interaction ) { + if ( ! $interaction ) { $this->set_non_interactive_mode(); } From 60df40bcc52993afffad695f8355448478c3bb47 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 2 Nov 2025 17:43:48 +0100 Subject: [PATCH 05/17] Fix synopsis --- src/Package_Command.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 3e74231a..294de121 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -199,7 +199,7 @@ public function browse( $_, $assoc_args ) { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * - * [--] + * [--interaction] * : Do not ask any interactive questions. Useful for scripting. * * ## EXAMPLES @@ -513,7 +513,7 @@ public function path( $args ) { * * ## OPTIONS * - * [--] + * [--interaction] * : Do not ask any interactive questions. Useful for scripting. * * ## EXAMPLES @@ -584,7 +584,7 @@ public function update( $_, $assoc_args = [] ) { * [--insecure] * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * - * [--] + * [--interaction] * : Do not ask any interactive questions. Useful for scripting. * * ## EXAMPLES From 249e76eb8a7624b90c381fccf18274dba4926d87 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 16:50:30 +0000 Subject: [PATCH 06/17] Fix test to use real package name from package index Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/package-install.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/package-install.feature b/features/package-install.feature index 1733dd25..2c1f10c1 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -1123,11 +1123,11 @@ Feature: Install WP-CLI packages And a dummy-package/composer.json file: """ { - "name": "wp-cli/test-package", + "name": "wp-cli/restful", "description": "Test package for no-interaction flag" } """ - When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/test-package --no-interaction` + When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/restful --no-interaction` Then STDOUT should contain: """ Success: Package installed From a6df039f5e87947a084ad477de990aff3b319dee Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 19 Dec 2025 13:26:00 +0100 Subject: [PATCH 07/17] Update src/Package_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 294de121..d7f7e64d 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -200,7 +200,7 @@ public function browse( $_, $assoc_args ) { * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * * [--interaction] - * : Do not ask any interactive questions. Useful for scripting. + * : Control interactive mode. Use `--no-interaction` to disable prompts (interactive by default). Useful for scripting. * * ## EXAMPLES * From 27ab93454a04bb5048c3779786156cc1831fdfdc Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 19 Dec 2025 13:26:08 +0100 Subject: [PATCH 08/17] Update src/Package_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index d7f7e64d..cd364631 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -514,7 +514,7 @@ public function path( $args ) { * ## OPTIONS * * [--interaction] - * : Do not ask any interactive questions. Useful for scripting. + * : Boolean flag that controls interactive mode (enabled by default). Use `--no-interaction` to disable prompts, which is useful for scripting. * * ## EXAMPLES * From 1b8440795968ba770a706df38f215d1015cadb73 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 19 Dec 2025 13:26:15 +0100 Subject: [PATCH 09/17] Update src/Package_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index cd364631..769f902a 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -585,7 +585,7 @@ public function update( $_, $assoc_args = [] ) { * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * * [--interaction] - * : Do not ask any interactive questions. Useful for scripting. + * : Control interactive prompts. Use `--no-interaction` to disable interactive questions (useful for scripting). * * ## EXAMPLES * From 3e26c9a9c775959170ed60d3fdf1435a5be90a8b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 20 Jan 2026 10:50:08 +0100 Subject: [PATCH 10/17] Update src/Package_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 769f902a..025827c8 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -220,7 +220,7 @@ public function install( $args, $assoc_args ) { list( $package_name ) = $args; $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); - $interaction = Utils\get_flag_value( $assoc_args, 'interaction', true ); + $interaction = (bool) Utils\get_flag_value( $assoc_args, 'interaction', true ); if ( ! $interaction ) { $this->set_non_interactive_mode(); From 891c476493468faf0005020d53117d5b0df9e381 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 20 Jan 2026 10:52:40 +0100 Subject: [PATCH 11/17] Update src/Package_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 10dc0c31..e650b3b7 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -547,7 +547,7 @@ public function path( $args ) { * @param array $assoc_args Associative array of options. */ public function update( $_, $assoc_args = [] ) { - $interaction = Utils\get_flag_value( $assoc_args, 'interaction', true ); + $interaction = (bool) Utils\get_flag_value( $assoc_args, 'interaction', true ); if ( ! $interaction ) { $this->set_non_interactive_mode(); From 68d474180f8889d03b7ccc3384c548b15aa96d01 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 19 Feb 2026 09:49:04 +0100 Subject: [PATCH 12/17] Update src/Package_Command.php --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 4c326e21..f5cb1d1a 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -528,7 +528,7 @@ public function path( $args ) { * : One or more package names to update. If not specified, all packages will be updated. * * [--interaction] - * : Boolean flag that controls interactive mode (enabled by default). Use `--no-interaction` to disable prompts, which is useful for scripting. + * : Control interactive mode. Use `--no-interaction` to disable prompts (interactive by default). Useful for scripting. * * ## EXAMPLES * From 559907d5c42cc8abbda8d8c59fc57a6b31e56d68 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 19 Feb 2026 09:49:29 +0100 Subject: [PATCH 13/17] Update src/Package_Command.php --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index f5cb1d1a..210a4270 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -680,7 +680,7 @@ public function uninstall( $args, $assoc_args ) { list( $package_name ) = $args; $insecure = (bool) Utils\get_flag_value( $assoc_args, 'insecure', false ); - $interaction = Utils\get_flag_value( $assoc_args, 'interaction', true ); + $interaction = (bool) Utils\get_flag_value( $assoc_args, 'interaction', true ); if ( ! $interaction ) { $this->set_non_interactive_mode(); From 2edb8893ad112ed847e954b3485f78317a967fb1 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 19 Feb 2026 09:52:20 +0100 Subject: [PATCH 14/17] Fix phpdoc --- src/Package_Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 8b9cba3e..6c39ed02 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -663,8 +663,8 @@ public function get( $args, $assoc_args ) { * --- * Success: Package updated successfully. * - * @param array $_ Unused positional arguments (none expected). - * @param array $assoc_args Associative array of options. + * @param array $args Positional arguments. One or more package names to update. + * @param array{interaction?: bool} $assoc_args Associative arguments. */ public function update( $args, $assoc_args = [] ) { $interaction = (bool) Utils\get_flag_value( $assoc_args, 'interaction', true ); From 386d5e5346989bac5242cfee2293903a23708c2e Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 19 Feb 2026 09:53:08 +0100 Subject: [PATCH 15/17] Add newline --- features/package-update.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/package-update.feature b/features/package-update.feature index 6a7531a6..8773d48b 100644 --- a/features/package-update.feature +++ b/features/package-update.feature @@ -213,4 +213,4 @@ Feature: Update WP-CLI packages """ Packages updated. """ - And STDERR should be empty \ No newline at end of file + And STDERR should be empty From 5ac3863e5c48f76f8fe0bf880fa69d416da43d97 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Feb 2026 09:13:16 +0000 Subject: [PATCH 16/17] Improve tests to actually verify environment variables are set Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/package-install.feature | 18 +++++++++-- features/package-update.feature | 51 ++++++++++++++++++++++++------- features/package.feature | 52 +++++++++++++++++++++++++------- 3 files changed, 97 insertions(+), 24 deletions(-) diff --git a/features/package-install.feature b/features/package-install.feature index e3e3783c..6ba536c9 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -1263,7 +1263,7 @@ Feature: Install WP-CLI packages """ And STDOUT should be empty - Scenario: Install a package with --no-interaction flag + Scenario: Install a package with --no-interaction flag sets environment variables Given an empty directory And a composer.json file: """ @@ -1284,11 +1284,25 @@ Feature: Install WP-CLI packages """ { "name": "wp-cli/restful", - "description": "Test package for no-interaction flag" + "description": "Test package for no-interaction flag", + "scripts": { + "post-install-cmd": [ + "@php -r \"echo 'GIT_TERMINAL_PROMPT=' . getenv('GIT_TERMINAL_PROMPT') . PHP_EOL;\"", + "@php -r \"echo 'GIT_SSH_COMMAND=' . getenv('GIT_SSH_COMMAND') . PHP_EOL;\"" + ] + } } """ When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/restful --no-interaction` Then STDOUT should contain: + """ + GIT_TERMINAL_PROMPT=0 + """ + And STDOUT should contain: + """ + GIT_SSH_COMMAND=ssh -o BatchMode=yes + """ + And STDOUT should contain: """ Success: Package installed """ diff --git a/features/package-update.feature b/features/package-update.feature index 8773d48b..207e5394 100644 --- a/features/package-update.feature +++ b/features/package-update.feature @@ -195,22 +195,51 @@ Feature: Update WP-CLI packages """ And the return code should be 1 - Scenario: Update packages with --no-interaction flag + Scenario: Update packages with --no-interaction flag sets environment variables Given an empty directory - - When I run `wp package install danielbachhuber/wp-cli-reset-post-date-command` - Then STDOUT should contain: - """ - Success: Package installed. + And a composer.json file: + """ + { + "repositories": { + "test" : { + "type": "path", + "url": "./dummy-package/" + }, + "wp-cli": { + "type": "composer", + "url": "https://wp-cli.org/package-index/" + } + }, + "require": { + "wp-cli/restful": "*" + } + } + """ + And a dummy-package/composer.json file: + """ + { + "name": "wp-cli/restful", + "version": "1.0.0", + "description": "Test package for no-interaction flag", + "scripts": { + "post-update-cmd": [ + "@php -r \"echo 'GIT_TERMINAL_PROMPT=' . getenv('GIT_TERMINAL_PROMPT') . PHP_EOL;\"", + "@php -r \"echo 'GIT_SSH_COMMAND=' . getenv('GIT_SSH_COMMAND') . PHP_EOL;\"" + ] + } + } + """ + + When I run `WP_CLI_PACKAGES_DIR=. wp package update --no-interaction` + Then STDOUT should contain: + """ + GIT_TERMINAL_PROMPT=0 """ - - When I run `wp package update --no-interaction` - Then STDOUT should contain: + And STDOUT should contain: """ - Using Composer to update packages... + GIT_SSH_COMMAND=ssh -o BatchMode=yes """ And STDOUT should contain: """ Packages updated. """ - And STDERR should be empty diff --git a/features/package.feature b/features/package.feature index a429b13a..a00d64ac 100644 --- a/features/package.feature +++ b/features/package.feature @@ -209,23 +209,53 @@ Feature: Manage WP-CLI packages {NO_SUCH_PACKAGE_COMPOSER_JSON} """ - Scenario: Uninstall a package with --no-interaction flag + Scenario: Uninstall a package with --no-interaction flag sets environment variables Given an empty directory + And a composer.json file: + """ + { + "repositories": { + "test" : { + "type": "path", + "url": "./dummy-package/" + }, + "wp-cli": { + "type": "composer", + "url": "https://wp-cli.org/package-index/" + } + }, + "require": { + "wp-cli/restful": "*" + } + } + """ + And a dummy-package/composer.json file: + """ + { + "name": "wp-cli/restful", + "version": "1.0.0", + "description": "Test package for no-interaction flag", + "scripts": { + "pre-uninstall-cmd": [ + "@php -r \"echo 'GIT_TERMINAL_PROMPT=' . getenv('GIT_TERMINAL_PROMPT') . PHP_EOL;\"", + "@php -r \"echo 'GIT_SSH_COMMAND=' . getenv('GIT_SSH_COMMAND') . PHP_EOL;\"" + ] + } + } + """ - When I run `wp package install runcommand/hook` - Then STDERR should be empty - - When I run `wp package uninstall runcommand/hook --no-interaction` - Then STDERR should be empty + When I run `WP_CLI_PACKAGES_DIR=. wp package uninstall wp-cli/restful --no-interaction` + Then STDOUT should contain: + """ + GIT_TERMINAL_PROMPT=0 + """ And STDOUT should contain: """ - Success: Uninstalled package. + GIT_SSH_COMMAND=ssh -o BatchMode=yes """ - - When I run `wp package list` - Then STDOUT should not contain: + And STDOUT should contain: """ - runcommand/hook + Success: Uninstalled package. """ Scenario: List packages with --skip-update-check flag From 0b70a31b71625c486ef1e4dbd0211d74b6b6905f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Feb 2026 09:29:31 +0000 Subject: [PATCH 17/17] Replace env var tests with actual Git/SSH interaction tests Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/package-install.feature | 53 ++++++++----------------------- features/package-update.feature | 54 +++++++------------------------- features/package.feature | 48 ++++++---------------------- 3 files changed, 34 insertions(+), 121 deletions(-) diff --git a/features/package-install.feature b/features/package-install.feature index 6ba536c9..5a5d5c81 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -1263,46 +1263,19 @@ Feature: Install WP-CLI packages """ And STDOUT should be empty - Scenario: Install a package with --no-interaction flag sets environment variables + @github-api + Scenario: Install package with --no-interaction fails fast on Git authentication errors Given an empty directory - And a composer.json file: - """ - { - "repositories": { - "test" : { - "type": "path", - "url": "./dummy-package/" - }, - "wp-cli": { - "type": "composer", - "url": "https://wp-cli.org/package-index/" - } - } - } - """ - And a dummy-package/composer.json file: - """ - { - "name": "wp-cli/restful", - "description": "Test package for no-interaction flag", - "scripts": { - "post-install-cmd": [ - "@php -r \"echo 'GIT_TERMINAL_PROMPT=' . getenv('GIT_TERMINAL_PROMPT') . PHP_EOL;\"", - "@php -r \"echo 'GIT_SSH_COMMAND=' . getenv('GIT_SSH_COMMAND') . PHP_EOL;\"" - ] - } - } - """ - When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/restful --no-interaction` - Then STDOUT should contain: - """ - GIT_TERMINAL_PROMPT=0 - """ - And STDOUT should contain: - """ - GIT_SSH_COMMAND=ssh -o BatchMode=yes - """ - And STDOUT should contain: + + # Try to install from a repository that requires authentication + # With --no-interaction and GIT_TERMINAL_PROMPT=0, Git will fail immediately + # instead of prompting for credentials + When I try `wp package install git@github.com:wp-cli-private-test/authentication-required.git --no-interaction` + Then the return code should be 1 + # The command should fail fast without hanging + And STDERR should contain: """ - Success: Package installed + Package installation failed """ + # Git should report it couldn't authenticate, not prompt + And STDERR should match /fatal:|Could not read from remote repository|Repository not found/ diff --git a/features/package-update.feature b/features/package-update.feature index 207e5394..6d36ea89 100644 --- a/features/package-update.feature +++ b/features/package-update.feature @@ -195,51 +195,21 @@ Feature: Update WP-CLI packages """ And the return code should be 1 - Scenario: Update packages with --no-interaction flag sets environment variables + @github-api + Scenario: Update packages with --no-interaction completes without prompting Given an empty directory - And a composer.json file: - """ - { - "repositories": { - "test" : { - "type": "path", - "url": "./dummy-package/" - }, - "wp-cli": { - "type": "composer", - "url": "https://wp-cli.org/package-index/" - } - }, - "require": { - "wp-cli/restful": "*" - } - } - """ - And a dummy-package/composer.json file: - """ - { - "name": "wp-cli/restful", - "version": "1.0.0", - "description": "Test package for no-interaction flag", - "scripts": { - "post-update-cmd": [ - "@php -r \"echo 'GIT_TERMINAL_PROMPT=' . getenv('GIT_TERMINAL_PROMPT') . PHP_EOL;\"", - "@php -r \"echo 'GIT_SSH_COMMAND=' . getenv('GIT_SSH_COMMAND') . PHP_EOL;\"" - ] - } - } - """ - - When I run `WP_CLI_PACKAGES_DIR=. wp package update --no-interaction` - Then STDOUT should contain: - """ - GIT_TERMINAL_PROMPT=0 - """ - And STDOUT should contain: + + # Install a real package + When I run `wp package install danielbachhuber/wp-cli-reset-post-date-command` + Then STDOUT should contain: """ - GIT_SSH_COMMAND=ssh -o BatchMode=yes + Success: Package installed. """ - And STDOUT should contain: + + # Update with --no-interaction should complete without hanging + When I run `wp package update --no-interaction` + Then STDOUT should contain: """ Packages updated. """ + And STDERR should be empty diff --git a/features/package.feature b/features/package.feature index a00d64ac..74861450 100644 --- a/features/package.feature +++ b/features/package.feature @@ -209,50 +209,20 @@ Feature: Manage WP-CLI packages {NO_SUCH_PACKAGE_COMPOSER_JSON} """ - Scenario: Uninstall a package with --no-interaction flag sets environment variables + @github-api + Scenario: Uninstall a package with --no-interaction prevents Git credential prompts Given an empty directory - And a composer.json file: - """ - { - "repositories": { - "test" : { - "type": "path", - "url": "./dummy-package/" - }, - "wp-cli": { - "type": "composer", - "url": "https://wp-cli.org/package-index/" - } - }, - "require": { - "wp-cli/restful": "*" - } - } - """ - And a dummy-package/composer.json file: - """ - { - "name": "wp-cli/restful", - "version": "1.0.0", - "description": "Test package for no-interaction flag", - "scripts": { - "pre-uninstall-cmd": [ - "@php -r \"echo 'GIT_TERMINAL_PROMPT=' . getenv('GIT_TERMINAL_PROMPT') . PHP_EOL;\"", - "@php -r \"echo 'GIT_SSH_COMMAND=' . getenv('GIT_SSH_COMMAND') . PHP_EOL;\"" - ] - } - } - """ - When I run `WP_CLI_PACKAGES_DIR=. wp package uninstall wp-cli/restful --no-interaction` + # Install a real package first + When I run `wp package install danielbachhuber/wp-cli-reset-post-date-command` Then STDOUT should contain: """ - GIT_TERMINAL_PROMPT=0 - """ - And STDOUT should contain: - """ - GIT_SSH_COMMAND=ssh -o BatchMode=yes + Success: Package installed. """ + + # Uninstall with --no-interaction should complete without hanging + When I run `wp package uninstall danielbachhuber/wp-cli-reset-post-date-command --no-interaction` + Then STDERR should be empty And STDOUT should contain: """ Success: Uninstalled package.